diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cfe89ad3787..834e06d8960c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5694,6 +5694,7 @@ Released 2018-09-13 [`collection_is_never_read`]: https://rust-lang.github.io/rust-clippy/master/index.html#collection_is_never_read [`comparison_chain`]: https://rust-lang.github.io/rust-clippy/master/index.html#comparison_chain [`comparison_to_empty`]: https://rust-lang.github.io/rust-clippy/master/index.html#comparison_to_empty +[`concealed_obvious_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#concealed_obvious_default [`confusing_method_to_numeric_cast`]: https://rust-lang.github.io/rust-clippy/master/index.html#confusing_method_to_numeric_cast [`const_is_empty`]: https://rust-lang.github.io/rust-clippy/master/index.html#const_is_empty [`const_static_lifetime`]: https://rust-lang.github.io/rust-clippy/master/index.html#const_static_lifetime diff --git a/clippy_config/src/conf.rs b/clippy_config/src/conf.rs index 87158cec42b2..060a6c407c01 100644 --- a/clippy_config/src/conf.rs +++ b/clippy_config/src/conf.rs @@ -1097,7 +1097,7 @@ impl serde::de::Error for FieldError { writeln!(msg).unwrap(); for (column, column_width) in column_widths.iter().copied().enumerate() { let index = column * rows + row; - let field = expected.get(index).copied().unwrap_or_default(); + let field = expected.get(index).copied().unwrap_or(""); write!(msg, "{:SEPARATOR_WIDTH$}{field:column_width$}", " ").unwrap(); } } @@ -1128,7 +1128,7 @@ fn calculate_dimensions(fields: &[&str]) -> (usize, Vec) { (0..rows) .map(|row| { let index = column * rows + row; - let field = fields.get(index).copied().unwrap_or_default(); + let field = fields.get(index).copied().unwrap_or(""); field.len() }) .max() diff --git a/clippy_lints/src/arbitrary_source_item_ordering.rs b/clippy_lints/src/arbitrary_source_item_ordering.rs index 06ff730f36f8..99e6d391f975 100644 --- a/clippy_lints/src/arbitrary_source_item_ordering.rs +++ b/clippy_lints/src/arbitrary_source_item_ordering.rs @@ -414,7 +414,7 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering { let module_level_order = self .module_item_order_groupings .module_level_order_of(&item_kind) - .unwrap_or_default(); + .unwrap_or(0); if let Some(cur_t) = cur_t.as_ref() { use std::cmp::Ordering; // Better legibility. diff --git a/clippy_lints/src/casts/cast_possible_truncation.rs b/clippy_lints/src/casts/cast_possible_truncation.rs index a2ecb5fb44ae..8d706ff3ece8 100644 --- a/clippy_lints/src/casts/cast_possible_truncation.rs +++ b/clippy_lints/src/casts/cast_possible_truncation.rs @@ -49,7 +49,7 @@ fn apply_reductions(cx: &LateContext<'_>, nbits: u64, expr: &Expr<'_>, signed: b .min(apply_reductions(cx, nbits, right, signed)) .min(apply_reductions(cx, nbits, left, signed)), BinOpKind::Shr => apply_reductions(cx, nbits, left, signed) - .saturating_sub(constant_int(cx, right).map_or(0, |s| u64::try_from(s).unwrap_or_default())), + .saturating_sub(constant_int(cx, right).map_or(0, |s| u64::try_from(s).unwrap_or(0))), _ => nbits, }, ExprKind::MethodCall(method, left, [right], _) => { diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index 1e3907d9ede0..b6163dda882a 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -359,6 +359,7 @@ pub static LINTS: &[&crate::LintInfo] = &[ crate::methods::CLONE_ON_COPY_INFO, crate::methods::CLONE_ON_REF_PTR_INFO, crate::methods::COLLAPSIBLE_STR_REPLACE_INFO, + crate::methods::CONCEALED_OBVIOUS_DEFAULT_INFO, crate::methods::CONST_IS_EMPTY_INFO, crate::methods::DOUBLE_ENDED_ITERATOR_LAST_INFO, crate::methods::DRAIN_COLLECT_INFO, diff --git a/clippy_lints/src/manual_strip.rs b/clippy_lints/src/manual_strip.rs index 9e911e61f196..6f16c182ce64 100644 --- a/clippy_lints/src/manual_strip.rs +++ b/clippy_lints/src/manual_strip.rs @@ -269,7 +269,7 @@ fn find_stripping<'tcx>( 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; + *self.bindings.entry(ident.name).or_insert(0) += 1; } walk_pat(self, pat); } diff --git a/clippy_lints/src/methods/concealed_obvious_default.rs b/clippy_lints/src/methods/concealed_obvious_default.rs new file mode 100644 index 000000000000..84b595ff773c --- /dev/null +++ b/clippy_lints/src/methods/concealed_obvious_default.rs @@ -0,0 +1,140 @@ +use rustc_span::Symbol; + +use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::sym; +use rustc_errors::Applicability; +use rustc_hir as hir; +use rustc_lint::LateContext; +use rustc_middle::ty::{self, Ty}; +use rustc_span::Span; + +use super::CONCEALED_OBVIOUS_DEFAULT; + +pub(super) fn check(cx: &LateContext<'_>, recv: &hir::Expr<'_>, method_name: Symbol, call_span: Span) { + // Type of the expression which invoked the method + let recv_ty = cx.typeck_results().expr_ty(recv); + + // Option::::unwrap_or_default() + // ^^^^^^^^^^^^^^^^^^^ + // if the call comes from expansion, bail + if call_span.from_expansion() { + return; + } + + // Only consider algebraic data types e.g. an `Option`. + // Their generics are represented by `generic_args` + if let ty::Adt(adt, generic_args) = recv_ty.kind() + // `name_of_generic`, is e.g. a `sym::Option` + && let Some(name_of_generic) = cx.tcx.get_diagnostic_name(adt.did()) + && let Some((message, suggestion)) = CONCEALING_METHODS.into_iter().find(|concealing| { + name_of_generic == concealing.ty && method_name == concealing.method + }).and_then(|concealing| { + let ty = generic_args.type_at(concealing.generic_index); + extract_obvious_default(cx, ty).map(|(default, ty)| { + let method = (concealing.fmt_msg)(ty); + ( + format!("method {method} conceals the underlying type"), + (concealing.fmt_sugg)(default), + ) + }) + }) + { + span_lint_and_sugg( + cx, + CONCEALED_OBVIOUS_DEFAULT, + call_span, + message, + "write the default type explicitly".to_string(), + suggestion, + Applicability::MachineApplicable, + ); + } +} + +/// Method which conceals an underlying type of a generic +struct ConcealingMethod { + /// Generic which contains the concealing method, e.g. `Option` + ty: Symbol, + /// Index of the concealed generic type, e.g. `0` for `Option` + generic_index: usize, + /// The concealing method, e.g. `unwrap_or_default` + method: Symbol, + /// Format the lint's message + /// + /// Receives the concealed type, e.g. for `Option` receives `bool` + fmt_msg: fn(&'static str) -> String, + /// Format the lint's suggestion + /// + /// Receives the default of the concealed type, e.g. for `Option` receives `false`, + /// as `bool::default()` is `false` + fmt_sugg: fn(&'static str) -> String, +} + +/// List of methods which use `Default` trait under the hood, +/// but they have an alternative non-`Default` method +/// +/// For example, there is `Option::unwrap_or_default` which is almost the same +/// as `Option::unwrap_or`, but the type does not have to be provided and the +/// `Default` implementation is used. +const CONCEALING_METHODS: [ConcealingMethod; 4] = [ + ConcealingMethod { + ty: sym::Result, + // Result + // ^ want + generic_index: 0, + method: sym::unwrap_or_default, + fmt_msg: |ty| format!("Result::<{ty}, _>::unwrap_or_default()"), + fmt_sugg: |val| format!("unwrap_or({val})"), + }, + ConcealingMethod { + ty: sym::Option, + // Option + // ^ want + generic_index: 0, + method: sym::unwrap_or_default, + fmt_msg: |ty| format!("Option::<{ty}>::unwrap_or_default()"), + fmt_sugg: |val| format!("unwrap_or({val})"), + }, + ConcealingMethod { + ty: sym::HashMapEntry, + // Entry<'a, K, V, A = Global> + // ^ want + generic_index: 2, + method: sym::or_default, + fmt_msg: |ty| format!("hash_map::Entry::<'_, _, {ty}>::or_default()"), + fmt_sugg: |val| format!("or_insert({val})"), + }, + ConcealingMethod { + ty: sym::BTreeEntry, + // Entry<'a, K, V, A = Global> + // ^ want + generic_index: 2, + method: sym::or_default, + fmt_msg: |ty| format!("btree_map::Entry::<'_, _, {ty}>::or_default()"), + fmt_sugg: |val| format!("or_insert({val})"), + }, +]; + +/// Get default value of a type with an obvious default. +/// +/// # Returns +/// +/// If the type has an obvious default: +/// +/// - Default for the type +/// - The type as it should be displayed in the lint message +/// +/// If the type is not considered to have an obvious default, return `None`. +fn extract_obvious_default(cx: &LateContext<'_>, ty: Ty<'_>) -> Option<(&'static str, &'static str)> { + match ty.peel_refs().kind() { + ty::Int(ty) => Some(("0", ty.name_str())), + ty::Uint(ty) => Some(("0", ty.name_str())), + ty::Float(ty) => Some(("0.0", ty.name_str())), + ty::Char => Some((r"'\0'", "char")), + ty::Str => Some((r#""""#, "&str")), + ty::Bool => Some(("false", "bool")), + ty::Tuple(tys) if tys.is_empty() => Some(("()", "()")), + ty::Adt(def, _) if cx.tcx.get_diagnostic_name(def.did()) == Some(sym::Option) => Some(("None", "Option<_>")), + _ => None, + } +} diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 347960e0003d..43a2f4ae0ace 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -14,6 +14,7 @@ mod clone_on_copy; mod clone_on_ref_ptr; mod cloned_instead_of_copied; mod collapsible_str_replace; +mod concealed_obvious_default; mod double_ended_iterator_last; mod drain_collect; mod err_expect; @@ -4565,6 +4566,46 @@ declare_clippy_lint! { "hardcoded localhost IP address" } +declare_clippy_lint! { + /// ### What it does + /// + /// Checks for usages of methods like `Option::unwrap_or_default`, + /// for types where the `Default` implementation is obvious and can be written literally + /// + /// ### Why is this bad? + /// + /// You have to know what the underlying type is, instead of it being obvious from a glance + /// + /// ### Example + /// ```no_run + /// fn f( + /// a: Option<&str>, + /// b: Option, + /// c: Option> + /// ) { + /// let a = a.unwrap_or_default(); + /// let b = b.unwrap_or_default(); + /// let c = c.unwrap_or_default(); + /// } + /// ``` + /// Use instead: + /// ```no_run + /// fn f( + /// a: Option<&str>, + /// b: Option, + /// c: Option> + /// ) { + /// let a = a.unwrap_or(""); + /// let b = b.unwrap_or(0); + /// let c = c.unwrap_or(None); + /// } + /// ``` + #[clippy::version = "1.89.0"] + pub CONCEALED_OBVIOUS_DEFAULT, + complexity, + ".*or_default() obscures the underlying type" +} + #[expect(clippy::struct_excessive_bools)] pub struct Methods { avoid_breaking_exported_api: bool, @@ -4744,6 +4785,7 @@ impl_lint_pass!(Methods => [ IO_OTHER_ERROR, SWAP_WITH_TEMPORARY, IP_CONSTANT, + CONCEALED_OBVIOUS_DEFAULT ]); /// Extracts a method call name, args, and `Span` of the method name. @@ -5544,7 +5586,7 @@ impl Methods { } } // Handle method calls whose receiver and arguments may come from expansion - if let ExprKind::MethodCall(path, recv, args, _call_span) = expr.kind { + if let ExprKind::MethodCall(path, recv, args, call_span) = expr.kind { match (path.ident.name, args) { (sym::expect, [_]) if !matches!(method_call(recv), Some((sym::ok | sym::err, _, [], _, _))) => { unwrap_expect_used::check( @@ -5579,6 +5621,9 @@ impl Methods { unwrap_expect_used::Variant::Unwrap, ); }, + (sym::or_default | sym::unwrap_or_default, []) => { + concealed_obvious_default::check(cx, recv, path.ident.name, call_span); + }, (sym::unwrap_err, []) => { unwrap_expect_used::check( cx, diff --git a/clippy_lints/src/operators/arithmetic_side_effects.rs b/clippy_lints/src/operators/arithmetic_side_effects.rs index a78a342d4fe3..6e6a8d80868c 100644 --- a/clippy_lints/src/operators/arithmetic_side_effects.rs +++ b/clippy_lints/src/operators/arithmetic_side_effects.rs @@ -64,9 +64,9 @@ impl ArithmeticSideEffects { /// "multiplication" are present in the inner set of allowed types. fn has_allowed_binary(&self, lhs_ty: Ty<'_>, rhs_ty: Ty<'_>) -> bool { let lhs_ty_string = lhs_ty.to_string(); - let lhs_ty_string_elem = lhs_ty_string.split('<').next().unwrap_or_default(); + let lhs_ty_string_elem = lhs_ty_string.split('<').next().unwrap_or(""); let rhs_ty_string = rhs_ty.to_string(); - let rhs_ty_string_elem = rhs_ty_string.split('<').next().unwrap_or_default(); + let rhs_ty_string_elem = rhs_ty_string.split('<').next().unwrap_or(""); if let Some(rhs_from_specific) = self.allowed_binary.get(lhs_ty_string_elem) && { let rhs_has_allowed_ty = rhs_from_specific.contains(rhs_ty_string_elem); @@ -85,7 +85,7 @@ impl ArithmeticSideEffects { /// allowed types. fn has_allowed_unary(&self, ty: Ty<'_>) -> bool { let ty_string = ty.to_string(); - let ty_string_elem = ty_string.split('<').next().unwrap_or_default(); + let ty_string_elem = ty_string.split('<').next().unwrap_or(""); self.allowed_unary.contains(ty_string_elem) } diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 3a08531cf1c9..fc2e9ec9581a 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -216,7 +216,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { fn next(&self, s: &'static str) -> String { let mut ids = self.ids.take(); - let out = match *ids.entry(s).and_modify(|n| *n += 1).or_default() { + let out = match *ids.entry(s).and_modify(|n| *n += 1).or_insert(0) { // first usage of the name, use it as is 0 => s.to_string(), // append a number starting with 1 diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 55469e8ebc90..dc5e61872eea 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -2770,7 +2770,7 @@ pub fn tokenize_with_text(s: &str) -> impl Iterator(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> u64 { match (cx.layout_of(ty).map(|layout| layout.size.bytes()), ty.kind()) { (Ok(size), _) => size, (Err(_), ty::Tuple(list)) => list.iter().map(|t| approx_ty_size(cx, t)).sum(), - (Err(_), ty::Array(t, n)) => n.try_to_target_usize(cx.tcx).unwrap_or_default() * approx_ty_size(cx, *t), + (Err(_), ty::Array(t, n)) => n.try_to_target_usize(cx.tcx).unwrap_or(0) * approx_ty_size(cx, *t), (Err(_), ty::Adt(def, subst)) if def.is_struct() => def .variants() .iter() @@ -955,7 +955,7 @@ pub fn approx_ty_size<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> u64 { .sum::() }) .max() - .unwrap_or_default(), + .unwrap_or(0), (Err(_), ty::Adt(def, subst)) if def.is_union() => def .variants() .iter() @@ -964,10 +964,10 @@ pub fn approx_ty_size<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> u64 { .iter() .map(|field| approx_ty_size(cx, field.ty(cx.tcx, subst))) .max() - .unwrap_or_default() + .unwrap_or(0) }) .max() - .unwrap_or_default(), + .unwrap_or(0), (Err(_), _) => 0, } } diff --git a/src/driver.rs b/src/driver.rs index 37adb14169a3..5ae0b2b50f82 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -267,7 +267,7 @@ pub fn main() { let clippy_args_var = env::var("CLIPPY_ARGS").ok(); let clippy_args = clippy_args_var .as_deref() - .unwrap_or_default() + .unwrap_or("") .split("__CLIPPY_HACKERY__") .filter_map(|s| match s { "" => None, diff --git a/tests/ui/concealed_obvious_default.fixed b/tests/ui/concealed_obvious_default.fixed new file mode 100644 index 000000000000..f9532c074c2f --- /dev/null +++ b/tests/ui/concealed_obvious_default.fixed @@ -0,0 +1,86 @@ +//@aux-build:proc_macros.rs +#![warn(clippy::concealed_obvious_default)] +#![allow(dead_code)] +#![allow(clippy::too_many_arguments)] + +extern crate proc_macros; + +use std::collections::{btree_map, hash_map}; + +fn test<'e, 'f, 'g, 'h>( + a: Option, + b: Option>, + c: Result<&str, ()>, + d: Result, + e: btree_map::Entry<'e, (), f32>, + e2: btree_map::Entry<'e, (), f32>, + f: btree_map::Entry<'f, (), char>, + f2: btree_map::Entry<'f, (), char>, + g: hash_map::Entry<'g, (), ()>, + g2: hash_map::Entry<'g, (), ()>, + h: hash_map::Entry<'h, (), u8>, + h2: hash_map::Entry<'h, (), u8>, +) { + _ = a.unwrap_or(false); + //~^ concealed_obvious_default + _ = a.unwrap_or(false); + + _ = b.unwrap_or(None); + //~^ concealed_obvious_default + _ = b.unwrap_or(None); + + _ = c.unwrap_or(""); + //~^ concealed_obvious_default + _ = c.unwrap_or(""); + + _ = d.unwrap_or(0); + //~^ concealed_obvious_default + _ = d.unwrap_or(0); + + _ = e.or_insert(0.0); + //~^ concealed_obvious_default + _ = e2.or_insert(0.0); + + _ = f.or_insert('\0'); + //~^ concealed_obvious_default + _ = f2.or_insert('\0'); + + _ = g.or_insert(()); + //~^ concealed_obvious_default + _ = g2.or_insert(()); + + _ = h.or_insert(0); + //~^ concealed_obvious_default + _ = h2.or_insert(0); + + // + // If the receiver comes from macro expansion, + // that's fine and we lint that. + // + + _ = proc_macros::external! { + Some(false) + } + .unwrap_or(false); + //~^ concealed_obvious_default + + _ = proc_macros::external! { + Some(false) + } + .unwrap_or(false); + + // + // However, if the method itself comes from + // macro expansion, it should not be linted. + // + + _ = proc_macros::external! { + Some(false).unwrap_or_default() + }; + + _ = proc_macros::external! { + Some(false).unwrap_or(false) + }; +} + +fn main() {} diff --git a/tests/ui/concealed_obvious_default.rs b/tests/ui/concealed_obvious_default.rs new file mode 100644 index 000000000000..1b15c940a8ba --- /dev/null +++ b/tests/ui/concealed_obvious_default.rs @@ -0,0 +1,86 @@ +//@aux-build:proc_macros.rs +#![warn(clippy::concealed_obvious_default)] +#![allow(dead_code)] +#![allow(clippy::too_many_arguments)] + +extern crate proc_macros; + +use std::collections::{btree_map, hash_map}; + +fn test<'e, 'f, 'g, 'h>( + a: Option, + b: Option>, + c: Result<&str, ()>, + d: Result, + e: btree_map::Entry<'e, (), f32>, + e2: btree_map::Entry<'e, (), f32>, + f: btree_map::Entry<'f, (), char>, + f2: btree_map::Entry<'f, (), char>, + g: hash_map::Entry<'g, (), ()>, + g2: hash_map::Entry<'g, (), ()>, + h: hash_map::Entry<'h, (), u8>, + h2: hash_map::Entry<'h, (), u8>, +) { + _ = a.unwrap_or_default(); + //~^ concealed_obvious_default + _ = a.unwrap_or(false); + + _ = b.unwrap_or_default(); + //~^ concealed_obvious_default + _ = b.unwrap_or(None); + + _ = c.unwrap_or_default(); + //~^ concealed_obvious_default + _ = c.unwrap_or(""); + + _ = d.unwrap_or_default(); + //~^ concealed_obvious_default + _ = d.unwrap_or(0); + + _ = e.or_default(); + //~^ concealed_obvious_default + _ = e2.or_insert(0.0); + + _ = f.or_default(); + //~^ concealed_obvious_default + _ = f2.or_insert('\0'); + + _ = g.or_default(); + //~^ concealed_obvious_default + _ = g2.or_insert(()); + + _ = h.or_default(); + //~^ concealed_obvious_default + _ = h2.or_insert(0); + + // + // If the receiver comes from macro expansion, + // that's fine and we lint that. + // + + _ = proc_macros::external! { + Some(false) + } + .unwrap_or_default(); + //~^ concealed_obvious_default + + _ = proc_macros::external! { + Some(false) + } + .unwrap_or(false); + + // + // However, if the method itself comes from + // macro expansion, it should not be linted. + // + + _ = proc_macros::external! { + Some(false).unwrap_or_default() + }; + + _ = proc_macros::external! { + Some(false).unwrap_or(false) + }; +} + +fn main() {} diff --git a/tests/ui/concealed_obvious_default.stderr b/tests/ui/concealed_obvious_default.stderr new file mode 100644 index 000000000000..f8f4fdde7d79 --- /dev/null +++ b/tests/ui/concealed_obvious_default.stderr @@ -0,0 +1,59 @@ +error: method Option::::unwrap_or_default() conceals the underlying type + --> tests/ui/concealed_obvious_default.rs:24:11 + | +LL | _ = a.unwrap_or_default(); + | ^^^^^^^^^^^^^^^^^^^ help: write the default type explicitly: `unwrap_or(false)` + | + = note: `-D clippy::concealed-obvious-default` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::concealed_obvious_default)]` + +error: method Option::>::unwrap_or_default() conceals the underlying type + --> tests/ui/concealed_obvious_default.rs:28:11 + | +LL | _ = b.unwrap_or_default(); + | ^^^^^^^^^^^^^^^^^^^ help: write the default type explicitly: `unwrap_or(None)` + +error: method Result::<&str, _>::unwrap_or_default() conceals the underlying type + --> tests/ui/concealed_obvious_default.rs:32:11 + | +LL | _ = c.unwrap_or_default(); + | ^^^^^^^^^^^^^^^^^^^ help: write the default type explicitly: `unwrap_or("")` + +error: method Result::::unwrap_or_default() conceals the underlying type + --> tests/ui/concealed_obvious_default.rs:36:11 + | +LL | _ = d.unwrap_or_default(); + | ^^^^^^^^^^^^^^^^^^^ help: write the default type explicitly: `unwrap_or(0)` + +error: method btree_map::Entry::<'_, _, f32>::or_default() conceals the underlying type + --> tests/ui/concealed_obvious_default.rs:40:11 + | +LL | _ = e.or_default(); + | ^^^^^^^^^^^^ help: write the default type explicitly: `or_insert(0.0)` + +error: method btree_map::Entry::<'_, _, char>::or_default() conceals the underlying type + --> tests/ui/concealed_obvious_default.rs:44:11 + | +LL | _ = f.or_default(); + | ^^^^^^^^^^^^ help: write the default type explicitly: `or_insert('\0')` + +error: method hash_map::Entry::<'_, _, ()>::or_default() conceals the underlying type + --> tests/ui/concealed_obvious_default.rs:48:11 + | +LL | _ = g.or_default(); + | ^^^^^^^^^^^^ help: write the default type explicitly: `or_insert(())` + +error: method hash_map::Entry::<'_, _, u8>::or_default() conceals the underlying type + --> tests/ui/concealed_obvious_default.rs:52:11 + | +LL | _ = h.or_default(); + | ^^^^^^^^^^^^ help: write the default type explicitly: `or_insert(0)` + +error: method Option::::unwrap_or_default() conceals the underlying type + --> tests/ui/concealed_obvious_default.rs:64:6 + | +LL | .unwrap_or_default(); + | ^^^^^^^^^^^^^^^^^^^ help: write the default type explicitly: `unwrap_or(false)` + +error: aborting due to 9 previous errors + diff --git a/tests/ui/manual_is_variant_and.fixed b/tests/ui/manual_is_variant_and.fixed index 18a72188ab59..be1a5e39c8d2 100644 --- a/tests/ui/manual_is_variant_and.fixed +++ b/tests/ui/manual_is_variant_and.fixed @@ -1,5 +1,6 @@ //@aux-build:option_helpers.rs #![warn(clippy::manual_is_variant_and)] +#![allow(clippy::concealed_obvious_default)] #[macro_use] extern crate option_helpers; diff --git a/tests/ui/manual_is_variant_and.rs b/tests/ui/manual_is_variant_and.rs index a92f7c043695..901b76255f59 100644 --- a/tests/ui/manual_is_variant_and.rs +++ b/tests/ui/manual_is_variant_and.rs @@ -1,5 +1,6 @@ //@aux-build:option_helpers.rs #![warn(clippy::manual_is_variant_and)] +#![allow(clippy::concealed_obvious_default)] #[macro_use] extern crate option_helpers; diff --git a/tests/ui/manual_is_variant_and.stderr b/tests/ui/manual_is_variant_and.stderr index 1fb437a8bc74..9a9f1c3ac187 100644 --- a/tests/ui/manual_is_variant_and.stderr +++ b/tests/ui/manual_is_variant_and.stderr @@ -1,5 +1,5 @@ error: called `map().unwrap_or_default()` on an `Option` value - --> tests/ui/manual_is_variant_and.rs:51:17 + --> tests/ui/manual_is_variant_and.rs:52:17 | LL | let _ = opt.map(|x| x > 1) | _________________^ @@ -11,7 +11,7 @@ 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:56:17 + --> tests/ui/manual_is_variant_and.rs:57:17 | LL | let _ = opt.map(|x| { | _________________^ @@ -30,13 +30,13 @@ LL ~ }); | error: called `map().unwrap_or_default()` on an `Option` value - --> tests/ui/manual_is_variant_and.rs:61:17 + --> tests/ui/manual_is_variant_and.rs:62: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:64:10 + --> tests/ui/manual_is_variant_and.rs:65:10 | LL | .map(|x| x > 1) | __________^ @@ -45,37 +45,37 @@ LL | | .unwrap_or_default(); | |____________________________^ help: use: `is_some_and(|x| x > 1)` error: called `.map() == Some()` - --> tests/ui/manual_is_variant_and.rs:68:13 + --> tests/ui/manual_is_variant_and.rs:69:13 | LL | let _ = Some(2).map(|x| x % 2 == 0) == Some(true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `Some(2).is_some_and(|x| x % 2 == 0)` error: called `.map() != Some()` - --> tests/ui/manual_is_variant_and.rs:70:13 + --> tests/ui/manual_is_variant_and.rs:71:13 | LL | let _ = Some(2).map(|x| x % 2 == 0) != Some(true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `Some(2).is_none_or(|x| x % 2 == 0)` error: called `.map() == Some()` - --> tests/ui/manual_is_variant_and.rs:72:13 + --> tests/ui/manual_is_variant_and.rs:73:13 | LL | let _ = Some(2).map(|x| x % 2 == 0) == some_true!(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `Some(2).is_some_and(|x| x % 2 == 0)` error: called `.map() != Some()` - --> tests/ui/manual_is_variant_and.rs:74:13 + --> tests/ui/manual_is_variant_and.rs:75:13 | LL | let _ = Some(2).map(|x| x % 2 == 0) != some_false!(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `Some(2).is_none_or(|x| x % 2 == 0)` error: called `map().unwrap_or_default()` on an `Option` value - --> tests/ui/manual_is_variant_and.rs:81:18 + --> tests/ui/manual_is_variant_and.rs:82: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:99:17 + --> tests/ui/manual_is_variant_and.rs:100:17 | LL | let _ = res.map(|x| { | _________________^ @@ -94,7 +94,7 @@ LL ~ }); | error: called `map().unwrap_or_default()` on a `Result` value - --> tests/ui/manual_is_variant_and.rs:104:17 + --> tests/ui/manual_is_variant_and.rs:105:17 | LL | let _ = res.map(|x| x > 1) | _________________^ @@ -103,25 +103,25 @@ LL | | .unwrap_or_default(); | |____________________________^ help: use: `is_ok_and(|x| x > 1)` error: called `.map() == Ok()` - --> tests/ui/manual_is_variant_and.rs:108:13 + --> tests/ui/manual_is_variant_and.rs:109:13 | LL | let _ = Ok::(2).map(|x| x % 2 == 0) == Ok(true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `Ok::(2).is_ok_and(|x| x % 2 == 0)` error: called `.map() != Ok()` - --> tests/ui/manual_is_variant_and.rs:110:13 + --> tests/ui/manual_is_variant_and.rs:111:13 | LL | let _ = Ok::(2).map(|x| x % 2 == 0) != Ok(true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `!Ok::(2).is_ok_and(|x| x % 2 == 0)` error: called `.map() != Ok()` - --> tests/ui/manual_is_variant_and.rs:112:13 + --> tests/ui/manual_is_variant_and.rs:113:13 | LL | let _ = Ok::(2).map(|x| x % 2 == 0) != Ok(true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `!Ok::(2).is_ok_and(|x| x % 2 == 0)` error: called `map().unwrap_or_default()` on a `Result` value - --> tests/ui/manual_is_variant_and.rs:119:18 + --> tests/ui/manual_is_variant_and.rs:120: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_unwrap_or_default.fixed b/tests/ui/manual_unwrap_or_default.fixed index 41ca44ceef4e..ca632655ffae 100644 --- a/tests/ui/manual_unwrap_or_default.fixed +++ b/tests/ui/manual_unwrap_or_default.fixed @@ -1,5 +1,5 @@ #![warn(clippy::manual_unwrap_or_default)] -#![allow(clippy::unnecessary_literal_unwrap)] +#![allow(clippy::unnecessary_literal_unwrap, clippy::concealed_obvious_default)] fn main() { let x: Option> = None; diff --git a/tests/ui/manual_unwrap_or_default.rs b/tests/ui/manual_unwrap_or_default.rs index 343fbc4879ce..6430e47879ba 100644 --- a/tests/ui/manual_unwrap_or_default.rs +++ b/tests/ui/manual_unwrap_or_default.rs @@ -1,5 +1,5 @@ #![warn(clippy::manual_unwrap_or_default)] -#![allow(clippy::unnecessary_literal_unwrap)] +#![allow(clippy::unnecessary_literal_unwrap, clippy::concealed_obvious_default)] fn main() { let x: Option> = None; diff --git a/tests/ui/obfuscated_if_else.fixed b/tests/ui/obfuscated_if_else.fixed index 70ae090626b9..1f272f8146fb 100644 --- a/tests/ui/obfuscated_if_else.fixed +++ b/tests/ui/obfuscated_if_else.fixed @@ -3,7 +3,8 @@ clippy::unnecessary_lazy_evaluations, clippy::unit_arg, clippy::unused_unit, - clippy::unwrap_or_default + clippy::unwrap_or_default, + clippy::concealed_obvious_default )] fn main() { diff --git a/tests/ui/obfuscated_if_else.rs b/tests/ui/obfuscated_if_else.rs index 8e1f57ca2c02..3cff0a9a72cc 100644 --- a/tests/ui/obfuscated_if_else.rs +++ b/tests/ui/obfuscated_if_else.rs @@ -3,7 +3,8 @@ clippy::unnecessary_lazy_evaluations, clippy::unit_arg, clippy::unused_unit, - clippy::unwrap_or_default + clippy::unwrap_or_default, + clippy::concealed_obvious_default )] fn main() { diff --git a/tests/ui/obfuscated_if_else.stderr b/tests/ui/obfuscated_if_else.stderr index 0de7259d8bb8..490b99d1669c 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:10:5 + --> tests/ui/obfuscated_if_else.rs:11:5 | LL | true.then_some("a").unwrap_or("b"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { "a" } else { "b" }` @@ -8,133 +8,133 @@ 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:13:5 + --> tests/ui/obfuscated_if_else.rs:14: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:17:5 + --> tests/ui/obfuscated_if_else.rs:18: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:20:5 + --> tests/ui/obfuscated_if_else.rs:21: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:27:5 + --> tests/ui/obfuscated_if_else.rs:28: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:30:5 + --> tests/ui/obfuscated_if_else.rs:31: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:5 + --> tests/ui/obfuscated_if_else.rs:35: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 + --> tests/ui/obfuscated_if_else.rs:37: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 + --> tests/ui/obfuscated_if_else.rs:39: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 + --> tests/ui/obfuscated_if_else.rs:42: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 + --> tests/ui/obfuscated_if_else.rs:45: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:50:5 + --> tests/ui/obfuscated_if_else.rs:51:5 | LL | true.then_some(()).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { () } else { Default::default() }` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:53:5 + --> tests/ui/obfuscated_if_else.rs:54:5 | LL | true.then(|| ()).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { () } else { Default::default() }` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:56:5 + --> tests/ui/obfuscated_if_else.rs:57:5 | LL | true.then_some(1).unwrap_or_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:59:5 + --> tests/ui/obfuscated_if_else.rs:60:5 | LL | true.then(|| 1).unwrap_or_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:65:13 + --> tests/ui/obfuscated_if_else.rs:66: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:69:13 + --> tests/ui/obfuscated_if_else.rs:70: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:69:48 + --> tests/ui/obfuscated_if_else.rs:70: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:69:81 + --> tests/ui/obfuscated_if_else.rs:70: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:75:17 + --> tests/ui/obfuscated_if_else.rs:76: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:79:13 + --> tests/ui/obfuscated_if_else.rs:80: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:83:14 + --> tests/ui/obfuscated_if_else.rs:84: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:87:14 + --> tests/ui/obfuscated_if_else.rs:88:14 | LL | let _ = *true.then_some(&42).unwrap_or(&17) as u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { &42 } else { &17 }` diff --git a/tests/ui/or_fun_call.fixed b/tests/ui/or_fun_call.fixed index a1119d75c231..08795535cabe 100644 --- a/tests/ui/or_fun_call.fixed +++ b/tests/ui/or_fun_call.fixed @@ -5,7 +5,8 @@ clippy::uninlined_format_args, clippy::unnecessary_wraps, clippy::unnecessary_literal_unwrap, - clippy::useless_vec + clippy::useless_vec, + clippy::concealed_obvious_default )] use std::collections::{BTreeMap, HashMap}; diff --git a/tests/ui/or_fun_call.rs b/tests/ui/or_fun_call.rs index a7cd632bf166..b03169158d33 100644 --- a/tests/ui/or_fun_call.rs +++ b/tests/ui/or_fun_call.rs @@ -5,7 +5,8 @@ clippy::uninlined_format_args, clippy::unnecessary_wraps, clippy::unnecessary_literal_unwrap, - clippy::useless_vec + clippy::useless_vec, + clippy::concealed_obvious_default )] use std::collections::{BTreeMap, HashMap}; diff --git a/tests/ui/or_fun_call.stderr b/tests/ui/or_fun_call.stderr index 35bda7e4d331..c5e6d6230d1d 100644 --- a/tests/ui/or_fun_call.stderr +++ b/tests/ui/or_fun_call.stderr @@ -1,5 +1,5 @@ error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:52:22 + --> tests/ui/or_fun_call.rs:53:22 | LL | with_constructor.unwrap_or(make()); | ^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(make)` @@ -8,7 +8,7 @@ LL | with_constructor.unwrap_or(make()); = help: to override `-D warnings` add `#[allow(clippy::or_fun_call)]` error: use of `unwrap_or` to construct default value - --> tests/ui/or_fun_call.rs:56:14 + --> tests/ui/or_fun_call.rs:57:14 | LL | with_new.unwrap_or(Vec::new()); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` @@ -17,199 +17,199 @@ 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:60:21 + --> tests/ui/or_fun_call.rs:61: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:64:14 + --> tests/ui/or_fun_call.rs:65: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:68:19 + --> tests/ui/or_fun_call.rs:69: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:72:24 + --> tests/ui/or_fun_call.rs:73: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:76:23 + --> tests/ui/or_fun_call.rs:77: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:80:18 + --> tests/ui/or_fun_call.rs:81: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:84:18 + --> tests/ui/or_fun_call.rs:85: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:88:14 + --> tests/ui/or_fun_call.rs:89: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:92:21 + --> tests/ui/or_fun_call.rs:93: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:96:19 + --> tests/ui/or_fun_call.rs:97: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:100:23 + --> tests/ui/or_fun_call.rs:101: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:104:21 + --> tests/ui/or_fun_call.rs:105: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:108:25 + --> tests/ui/or_fun_call.rs:109: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:112:21 + --> tests/ui/or_fun_call.rs:113: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:117:17 + --> tests/ui/or_fun_call.rs:118: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:122:21 + --> tests/ui/or_fun_call.rs:123: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:125:21 + --> tests/ui/or_fun_call.rs:126: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:150:35 + --> tests/ui/or_fun_call.rs:151: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:193:18 + --> tests/ui/or_fun_call.rs:194:18 | LL | None.unwrap_or(ptr_to_ref(s)); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| ptr_to_ref(s))` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:201:14 + --> tests/ui/or_fun_call.rs:202: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:204:14 + --> tests/ui/or_fun_call.rs:205: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:280:25 + --> tests/ui/or_fun_call.rs:281: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:282:25 + --> tests/ui/or_fun_call.rs:283: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:314:18 + --> tests/ui/or_fun_call.rs:315: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:318:28 + --> tests/ui/or_fun_call.rs:319: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:322:27 + --> tests/ui/or_fun_call.rs:323: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:326:22 + --> tests/ui/or_fun_call.rs:327: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:330:23 + --> tests/ui/or_fun_call.rs:331: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:334:25 + --> tests/ui/or_fun_call.rs:335: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:338:25 + --> tests/ui/or_fun_call.rs:339: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:380:17 + --> tests/ui/or_fun_call.rs:381: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:385:17 + --> tests/ui/or_fun_call.rs:386: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:390:17 + --> tests/ui/or_fun_call.rs:391:17 | LL | let _ = opt.unwrap_or({ | _________________^ @@ -229,19 +229,19 @@ LL ~ }); | error: function call inside of `map_or` - --> tests/ui/or_fun_call.rs:396:17 + --> tests/ui/or_fun_call.rs:397: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:401:17 + --> tests/ui/or_fun_call.rs:402: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:408:21 + --> tests/ui/or_fun_call.rs:409: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/significant_drop_tightening.fixed b/tests/ui/significant_drop_tightening.fixed index 3d416056226c..51d83c753a6a 100644 --- a/tests/ui/significant_drop_tightening.fixed +++ b/tests/ui/significant_drop_tightening.fixed @@ -1,4 +1,5 @@ #![warn(clippy::significant_drop_tightening)] +#![allow(clippy::concealed_obvious_default)] use std::sync::Mutex; diff --git a/tests/ui/significant_drop_tightening.rs b/tests/ui/significant_drop_tightening.rs index d9c4ad543593..9d01808da343 100644 --- a/tests/ui/significant_drop_tightening.rs +++ b/tests/ui/significant_drop_tightening.rs @@ -1,4 +1,5 @@ #![warn(clippy::significant_drop_tightening)] +#![allow(clippy::concealed_obvious_default)] use std::sync::Mutex; diff --git a/tests/ui/significant_drop_tightening.stderr b/tests/ui/significant_drop_tightening.stderr index 25cd9da73a10..28abbdb412c4 100644 --- a/tests/ui/significant_drop_tightening.stderr +++ b/tests/ui/significant_drop_tightening.stderr @@ -1,5 +1,5 @@ error: temporary with significant `Drop` can be early dropped - --> tests/ui/significant_drop_tightening.rs:10:9 + --> tests/ui/significant_drop_tightening.rs:11:9 | LL | pub fn complex_return_triggers_the_lint() -> i32 { | __________________________________________________- @@ -23,7 +23,7 @@ LL + drop(lock); | error: temporary with significant `Drop` can be early dropped - --> tests/ui/significant_drop_tightening.rs:105:13 + --> tests/ui/significant_drop_tightening.rs:106:13 | LL | / { LL | | let mutex = Mutex::new(1i32); @@ -42,7 +42,7 @@ LL + drop(lock); | error: temporary with significant `Drop` can be early dropped - --> tests/ui/significant_drop_tightening.rs:127:13 + --> tests/ui/significant_drop_tightening.rs:128:13 | LL | / { LL | | let mutex = Mutex::new(1i32); @@ -63,7 +63,7 @@ LL ~ | error: temporary with significant `Drop` can be early dropped - --> tests/ui/significant_drop_tightening.rs:134:17 + --> tests/ui/significant_drop_tightening.rs:135:17 | LL | / { LL | | let mutex = Mutex::new(vec![1i32]); diff --git a/tests/ui/unnecessary_literal_unwrap.fixed b/tests/ui/unnecessary_literal_unwrap.fixed index 877f4ad41c7e..7f32ba2b8c60 100644 --- a/tests/ui/unnecessary_literal_unwrap.fixed +++ b/tests/ui/unnecessary_literal_unwrap.fixed @@ -4,7 +4,8 @@ clippy::unnecessary_lazy_evaluations, clippy::diverging_sub_expression, clippy::let_unit_value, - clippy::no_effect + clippy::no_effect, + clippy::concealed_obvious_default )] fn unwrap_option_some() { diff --git a/tests/ui/unnecessary_literal_unwrap.rs b/tests/ui/unnecessary_literal_unwrap.rs index c0a35ae78a71..17b451387d3a 100644 --- a/tests/ui/unnecessary_literal_unwrap.rs +++ b/tests/ui/unnecessary_literal_unwrap.rs @@ -4,7 +4,8 @@ clippy::unnecessary_lazy_evaluations, clippy::diverging_sub_expression, clippy::let_unit_value, - clippy::no_effect + clippy::no_effect, + clippy::concealed_obvious_default )] fn unwrap_option_some() { diff --git a/tests/ui/unnecessary_literal_unwrap.stderr b/tests/ui/unnecessary_literal_unwrap.stderr index cd90763263e9..5385c513bbb7 100644 --- a/tests/ui/unnecessary_literal_unwrap.stderr +++ b/tests/ui/unnecessary_literal_unwrap.stderr @@ -1,5 +1,5 @@ error: used `unwrap()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:11:16 + --> tests/ui/unnecessary_literal_unwrap.rs:12:16 | LL | let _val = Some(1).unwrap(); | ^^^^^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL + let _val = 1; | error: used `expect()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:13:16 + --> tests/ui/unnecessary_literal_unwrap.rs:14:16 | LL | let _val = Some(1).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + let _val = 1; | error: used `unwrap()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:16:5 + --> tests/ui/unnecessary_literal_unwrap.rs:17:5 | LL | Some(1).unwrap(); | ^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + 1; | error: used `expect()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:18:5 + --> tests/ui/unnecessary_literal_unwrap.rs:19: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:24:16 + --> tests/ui/unnecessary_literal_unwrap.rs:25: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:26:16 + --> tests/ui/unnecessary_literal_unwrap.rs:27:16 | LL | let _val = None::<()>.expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -67,13 +67,13 @@ LL + let _val = panic!("this always happens"); | error: used `unwrap_or_default()` on `None` value - --> tests/ui/unnecessary_literal_unwrap.rs:28:24 + --> tests/ui/unnecessary_literal_unwrap.rs:29: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:30:21 + --> tests/ui/unnecessary_literal_unwrap.rs:31:21 | LL | let _val: u16 = None.unwrap_or(234); | ^^^^^^^^^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL + let _val: u16 = 234; | error: used `unwrap_or_else()` on `None` value - --> tests/ui/unnecessary_literal_unwrap.rs:32:21 + --> tests/ui/unnecessary_literal_unwrap.rs:33:21 | LL | let _val: u16 = None.unwrap_or_else(|| 234); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL + let _val: u16 = 234; | error: used `unwrap_or_else()` on `None` value - --> tests/ui/unnecessary_literal_unwrap.rs:34:21 + --> tests/ui/unnecessary_literal_unwrap.rs:35:21 | LL | let _val: u16 = None.unwrap_or_else(|| { 234 }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -109,7 +109,7 @@ LL + let _val: u16 = { 234 }; | error: used `unwrap_or_else()` on `None` value - --> tests/ui/unnecessary_literal_unwrap.rs:36:21 + --> tests/ui/unnecessary_literal_unwrap.rs:37:21 | LL | let _val: u16 = None.unwrap_or_else(|| -> u16 { 234 }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -121,13 +121,13 @@ LL + let _val: u16 = { 234 }; | error: used `unwrap()` on `None` value - --> tests/ui/unnecessary_literal_unwrap.rs:39:5 + --> tests/ui/unnecessary_literal_unwrap.rs:40:5 | LL | None::<()>.unwrap(); | ^^^^^^^^^^^^^^^^^^^ help: remove the `None` and `unwrap()`: `panic!()` error: used `expect()` on `None` value - --> tests/ui/unnecessary_literal_unwrap.rs:41:5 + --> tests/ui/unnecessary_literal_unwrap.rs:42:5 | LL | None::<()>.expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -139,13 +139,13 @@ LL + panic!("this always happens"); | error: used `unwrap_or_default()` on `None` value - --> tests/ui/unnecessary_literal_unwrap.rs:43:5 + --> tests/ui/unnecessary_literal_unwrap.rs:44: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:45:5 + --> tests/ui/unnecessary_literal_unwrap.rs:46:5 | LL | None::.unwrap_or(234); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -157,7 +157,7 @@ LL + 234; | error: used `unwrap_or_else()` on `None` value - --> tests/ui/unnecessary_literal_unwrap.rs:47:5 + --> tests/ui/unnecessary_literal_unwrap.rs:48:5 | LL | None::.unwrap_or_else(|| 234); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -169,7 +169,7 @@ LL + 234; | error: used `unwrap_or_else()` on `None` value - --> tests/ui/unnecessary_literal_unwrap.rs:49:5 + --> tests/ui/unnecessary_literal_unwrap.rs:50:5 | LL | None::.unwrap_or_else(|| { 234 }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -181,7 +181,7 @@ LL + { 234 }; | error: used `unwrap_or_else()` on `None` value - --> tests/ui/unnecessary_literal_unwrap.rs:51:5 + --> tests/ui/unnecessary_literal_unwrap.rs:52:5 | LL | None::.unwrap_or_else(|| -> u16 { 234 }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -193,7 +193,7 @@ LL + { 234 }; | error: used `unwrap()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:56:16 + --> tests/ui/unnecessary_literal_unwrap.rs:57:16 | LL | let _val = Ok::<_, ()>(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -205,7 +205,7 @@ LL + let _val = 1; | error: used `expect()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:58:16 + --> tests/ui/unnecessary_literal_unwrap.rs:59:16 | LL | let _val = Ok::<_, ()>(1).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -217,7 +217,7 @@ LL + let _val = 1; | error: used `unwrap_err()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:60:16 + --> tests/ui/unnecessary_literal_unwrap.rs:61:16 | LL | let _val = Ok::<_, ()>(1).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -229,7 +229,7 @@ LL + let _val = panic!("{:?}", 1); | error: used `expect_err()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:62:16 + --> tests/ui/unnecessary_literal_unwrap.rs:63:16 | LL | let _val = Ok::<_, ()>(1).expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -241,7 +241,7 @@ LL + let _val = panic!("{1}: {:?}", 1, "this always happens"); | error: used `unwrap()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:65:5 + --> tests/ui/unnecessary_literal_unwrap.rs:66:5 | LL | Ok::<_, ()>(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -253,7 +253,7 @@ LL + 1; | error: used `expect()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:67:5 + --> tests/ui/unnecessary_literal_unwrap.rs:68:5 | LL | Ok::<_, ()>(1).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -265,7 +265,7 @@ LL + 1; | error: used `unwrap_err()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:69:5 + --> tests/ui/unnecessary_literal_unwrap.rs:70:5 | LL | Ok::<_, ()>(1).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -277,7 +277,7 @@ LL + panic!("{:?}", 1); | error: used `expect_err()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:71:5 + --> tests/ui/unnecessary_literal_unwrap.rs:72:5 | LL | Ok::<_, ()>(1).expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -289,7 +289,7 @@ LL + panic!("{1}: {:?}", 1, "this always happens"); | error: used `unwrap_err()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap.rs:76:16 + --> tests/ui/unnecessary_literal_unwrap.rs:77:16 | LL | let _val = Err::<(), _>(1).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -301,7 +301,7 @@ LL + let _val = 1; | error: used `expect_err()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap.rs:78:16 + --> tests/ui/unnecessary_literal_unwrap.rs:79:16 | LL | let _val = Err::<(), _>(1).expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -313,7 +313,7 @@ LL + let _val = 1; | error: used `unwrap()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap.rs:80:16 + --> tests/ui/unnecessary_literal_unwrap.rs:81:16 | LL | let _val = Err::<(), _>(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -325,7 +325,7 @@ LL + let _val = panic!("{:?}", 1); | error: used `expect()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap.rs:82:16 + --> tests/ui/unnecessary_literal_unwrap.rs:83:16 | LL | let _val = Err::<(), _>(1).expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -337,7 +337,7 @@ LL + let _val = panic!("{1}: {:?}", 1, "this always happens"); | error: used `unwrap_err()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap.rs:85:5 + --> tests/ui/unnecessary_literal_unwrap.rs:86:5 | LL | Err::<(), _>(1).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -349,7 +349,7 @@ LL + 1; | error: used `expect_err()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap.rs:87:5 + --> tests/ui/unnecessary_literal_unwrap.rs:88:5 | LL | Err::<(), _>(1).expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -361,7 +361,7 @@ LL + 1; | error: used `unwrap()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap.rs:89:5 + --> tests/ui/unnecessary_literal_unwrap.rs:90:5 | LL | Err::<(), _>(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -373,7 +373,7 @@ LL + panic!("{:?}", 1); | error: used `expect()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap.rs:91:5 + --> tests/ui/unnecessary_literal_unwrap.rs:92:5 | LL | Err::<(), _>(1).expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -385,7 +385,7 @@ LL + panic!("{1}: {:?}", 1, "this always happens"); | error: used `unwrap_or()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:96:16 + --> tests/ui/unnecessary_literal_unwrap.rs:97:16 | LL | let _val = Some(1).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^ @@ -397,7 +397,7 @@ LL + let _val = 1; | error: used `unwrap_or_default()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:98:16 + --> tests/ui/unnecessary_literal_unwrap.rs:99:16 | LL | let _val = Some(1).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -409,7 +409,7 @@ LL + let _val = 1; | error: used `unwrap_or_else()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:100:16 + --> tests/ui/unnecessary_literal_unwrap.rs:101:16 | LL | let _val = Some(1).unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -421,7 +421,7 @@ LL + let _val = 1; | error: used `unwrap_or()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:103:5 + --> tests/ui/unnecessary_literal_unwrap.rs:104:5 | LL | Some(1).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^ @@ -433,7 +433,7 @@ LL + 1; | error: used `unwrap_or_default()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:105:5 + --> tests/ui/unnecessary_literal_unwrap.rs:106:5 | LL | Some(1).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -445,7 +445,7 @@ LL + 1; | error: used `unwrap_or_else()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:107:5 + --> tests/ui/unnecessary_literal_unwrap.rs:108:5 | LL | Some(1).unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -457,7 +457,7 @@ LL + 1; | error: used `unwrap_or()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:112:16 + --> tests/ui/unnecessary_literal_unwrap.rs:113:16 | LL | let _val = Ok::<_, ()>(1).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -469,7 +469,7 @@ LL + let _val = 1; | error: used `unwrap_or_default()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:114:16 + --> tests/ui/unnecessary_literal_unwrap.rs:115:16 | LL | let _val = Ok::<_, ()>(1).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -481,7 +481,7 @@ LL + let _val = 1; | error: used `unwrap_or_else()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:116:16 + --> tests/ui/unnecessary_literal_unwrap.rs:117:16 | LL | let _val = Ok::<_, ()>(1).unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -493,7 +493,7 @@ LL + let _val = 1; | error: used `unwrap_or()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:119:5 + --> tests/ui/unnecessary_literal_unwrap.rs:120:5 | LL | Ok::<_, ()>(1).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -505,7 +505,7 @@ LL + 1; | error: used `unwrap_or_default()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:121:5 + --> tests/ui/unnecessary_literal_unwrap.rs:122:5 | LL | Ok::<_, ()>(1).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -517,7 +517,7 @@ LL + 1; | error: used `unwrap_or_else()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:123:5 + --> tests/ui/unnecessary_literal_unwrap.rs:124:5 | LL | Ok::<_, ()>(1).unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -529,7 +529,7 @@ LL + 1; | error: used `unwrap_unchecked()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:138:22 + --> tests/ui/unnecessary_literal_unwrap.rs:139:22 | LL | let _ = unsafe { Some(1).unwrap_unchecked() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -541,7 +541,7 @@ LL + let _ = 1; | error: used `unwrap_unchecked()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:140:22 + --> tests/ui/unnecessary_literal_unwrap.rs:141:22 | LL | let _ = unsafe { Some(1).unwrap_unchecked() + *(&1 as *const i32) }; // needs to keep the unsafe block | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -553,7 +553,7 @@ LL + let _ = unsafe { 1 + *(&1 as *const i32) }; // needs to keep the unsafe | error: used `unwrap_unchecked()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:143:22 + --> tests/ui/unnecessary_literal_unwrap.rs:144:22 | LL | let _ = unsafe { Some(1).unwrap_unchecked() } + 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -565,7 +565,7 @@ LL + let _ = 1 + 1; | error: used `unwrap_unchecked()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:145:22 + --> tests/ui/unnecessary_literal_unwrap.rs:146:22 | LL | let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -577,7 +577,7 @@ LL + let _ = 1; | error: used `unwrap_unchecked()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:147:22 + --> tests/ui/unnecessary_literal_unwrap.rs:148:22 | LL | let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() + *(&1 as *const i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -589,7 +589,7 @@ LL + let _ = unsafe { 1 + *(&1 as *const i32) }; | error: used `unwrap_unchecked()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:149:22 + --> tests/ui/unnecessary_literal_unwrap.rs:150:22 | LL | let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() } + 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -601,7 +601,7 @@ LL + let _ = 1 + 1; | error: used `unwrap_err_unchecked()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap.rs:151:22 + --> tests/ui/unnecessary_literal_unwrap.rs:152: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 b6cba4e6a568..1024532029a2 100644 --- a/tests/ui/unnecessary_literal_unwrap_unfixable.rs +++ b/tests/ui/unnecessary_literal_unwrap_unfixable.rs @@ -1,6 +1,10 @@ #![warn(clippy::unnecessary_literal_unwrap)] #![allow(unreachable_code)] -#![allow(clippy::unnecessary_lazy_evaluations, clippy::let_unit_value)] +#![allow( + clippy::unnecessary_lazy_evaluations, + clippy::let_unit_value, + clippy::concealed_obvious_default +)] //@no-rustfix fn unwrap_option_some() { let val = Some(1); diff --git a/tests/ui/unnecessary_literal_unwrap_unfixable.stderr b/tests/ui/unnecessary_literal_unwrap_unfixable.stderr index 4994eeded776..015d362e9a31 100644 --- a/tests/ui/unnecessary_literal_unwrap_unfixable.stderr +++ b/tests/ui/unnecessary_literal_unwrap_unfixable.stderr @@ -1,11 +1,11 @@ error: used `unwrap()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:7:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:11:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `Some` and `unwrap()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:6:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:10:15 | LL | let val = Some(1); | ^^^^^^^ @@ -13,601 +13,601 @@ LL | let val = Some(1); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_literal_unwrap)]` error: used `expect()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:10:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:14:17 | LL | let _val2 = val.expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `expect()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:6:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:10:15 | LL | let val = Some(1); | ^^^^^^^ error: used `unwrap()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:15:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:19:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:15:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:19:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:18:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:22:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `expect()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:18:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:22:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:22:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:26:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `Some` and `unwrap()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:21:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:25:15 | LL | let val = Some::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:25:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:29:17 | LL | let _val2 = val.expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `expect()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:21:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:25:15 | LL | let val = Some::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap()` on `None` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:31:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:35:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `None` and `unwrap()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:30:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:34:15 | LL | let val = None::<()>; | ^^^^^^^^^^ error: used `expect()` on `None` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:34:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:38:17 | LL | let _val2 = val.expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `None` and `expect()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:30:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:34:15 | LL | let val = None::<()>; | ^^^^^^^^^^ error: used `unwrap_or_default()` on `None` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:37:21 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:41: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:40:5 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:44: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:46: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:45: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:49: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:45: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:52: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:45: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:55: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:45: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:60:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:64:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:60:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:64:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:63:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:67:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:63:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:67:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:66:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:70:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:66:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:70:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect_err()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:69:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:73:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:69:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:73:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:73:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:77:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:72:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:76:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:76:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:80:17 | LL | let _val2 = val.expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:72:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:76:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:79:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:83:17 | LL | let _val2 = val.unwrap_err(); | ^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:72:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:76:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect_err()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:82:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:86:17 | LL | let _val2 = val.expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:72:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:76:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:88:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:92:17 | LL | let _val2 = val.unwrap_err(); | ^^^^^^^^^^^^^^^^ | help: remove the `Err` and `unwrap_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:87:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:91:15 | LL | let val = Err::<(), _>(1); | ^^^^^^^^^^^^^^^ error: used `expect_err()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:91:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:95:17 | LL | let _val2 = val.expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:87:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:91:15 | LL | let val = Err::<(), _>(1); | ^^^^^^^^^^^^^^^ error: used `unwrap()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:94:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:98:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `Err` and `unwrap()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:87:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:91:15 | LL | let val = Err::<(), _>(1); | ^^^^^^^^^^^^^^^ error: used `expect()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:97:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:101:17 | LL | let _val2 = val.expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:87:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:91:15 | LL | let val = Err::<(), _>(1); | ^^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:102:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:106:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `unwrap_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:102:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:106:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect_err()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:105:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:109:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:105:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:109:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:108:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:112:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `unwrap()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:108:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:112:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:111:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:115:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:111:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:115:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:115:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:119:17 | LL | let _val2 = val.unwrap_err(); | ^^^^^^^^^^^^^^^^ | help: remove the `Err` and `unwrap_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:114:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:118:15 | LL | let val = Err::<(), usize>([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect_err()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:118:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:122:17 | LL | let _val2 = val.expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:114:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:118:15 | LL | let val = Err::<(), usize>([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:121:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:125:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `Err` and `unwrap()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:114:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:118:15 | LL | let val = Err::<(), usize>([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:124:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:128:17 | LL | let _val2 = val.expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:114:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:118:15 | LL | let val = Err::<(), usize>([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:130:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:134:17 | LL | let _val2 = val.unwrap_or(2); | ^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:129:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:133:15 | LL | let val = Some(1); | ^^^^^^^ error: used `unwrap_or_default()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:133:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:137:17 | LL | let _val2 = val.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_default()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:129:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:133:15 | LL | let val = Some(1); | ^^^^^^^ error: used `unwrap_or_else()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:136:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:140:17 | LL | let _val2 = val.unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_else()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:129:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:133:15 | LL | let val = Some(1); | ^^^^^^^ error: used `unwrap_or()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:141:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:145:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:141:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:145:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_default()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:144:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:148:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_default()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:144:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:148:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_else()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:147:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:151:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_else()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:147:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:151:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:151:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:155:17 | LL | let _val2 = val.unwrap_or(2); | ^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:150:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:154:15 | LL | let val = Some::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_default()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:154:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:158:17 | LL | let _val2 = val.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_default()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:150:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:154:15 | LL | let val = Some::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_else()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:157:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:161:17 | LL | let _val2 = val.unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_else()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:150:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:154:15 | LL | let val = Some::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:163:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:167:17 | LL | let _val2 = val.unwrap_or(2); | ^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:162:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:166:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `unwrap_or_default()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:166:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:170:17 | LL | let _val2 = val.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_default()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:162:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:166:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `unwrap_or_else()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:169:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:173:17 | LL | let _val2 = val.unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_else()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:162:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:166:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `unwrap_or()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:174:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:178:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:174:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:178:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_default()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:177:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:181:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_default()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:177:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:181:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_else()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:180:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:184:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_else()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:180:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:184:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:184:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:188:17 | LL | let _val2 = val.unwrap_or(2); | ^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:183:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:187:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_default()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:187:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:191:17 | LL | let _val2 = val.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_default()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:183:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:187:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_else()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:190:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:194:17 | LL | let _val2 = val.unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_else()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:183:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:187:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unwrap_or_else_default.fixed b/tests/ui/unwrap_or_else_default.fixed index 561cbce473de..d9e170bc72f4 100644 --- a/tests/ui/unwrap_or_else_default.fixed +++ b/tests/ui/unwrap_or_else_default.fixed @@ -1,6 +1,10 @@ #![warn(clippy::unwrap_or_default)] #![allow(dead_code)] -#![allow(clippy::unnecessary_wraps, clippy::unnecessary_literal_unwrap)] +#![allow( + clippy::unnecessary_wraps, + clippy::unnecessary_literal_unwrap, + clippy::concealed_obvious_default +)] /// Checks implementation of the `UNWRAP_OR_DEFAULT` lint. fn unwrap_or_else_default() { diff --git a/tests/ui/unwrap_or_else_default.rs b/tests/ui/unwrap_or_else_default.rs index 8389be964fe6..6455f2339c47 100644 --- a/tests/ui/unwrap_or_else_default.rs +++ b/tests/ui/unwrap_or_else_default.rs @@ -1,6 +1,10 @@ #![warn(clippy::unwrap_or_default)] #![allow(dead_code)] -#![allow(clippy::unnecessary_wraps, clippy::unnecessary_literal_unwrap)] +#![allow( + clippy::unnecessary_wraps, + clippy::unnecessary_literal_unwrap, + clippy::concealed_obvious_default +)] /// Checks implementation of the `UNWRAP_OR_DEFAULT` lint. fn unwrap_or_else_default() { diff --git a/tests/ui/unwrap_or_else_default.stderr b/tests/ui/unwrap_or_else_default.stderr index a001f7e46add..81490f8cae6a 100644 --- a/tests/ui/unwrap_or_else_default.stderr +++ b/tests/ui/unwrap_or_else_default.stderr @@ -1,5 +1,5 @@ error: use of `unwrap_or_else` to construct default value - --> tests/ui/unwrap_or_else_default.rs:46:14 + --> tests/ui/unwrap_or_else_default.rs:50:14 | LL | with_new.unwrap_or_else(Vec::new); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` @@ -8,41 +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:61:23 + --> tests/ui/unwrap_or_else_default.rs:65:23 | LL | with_real_default.unwrap_or_else(::default); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> tests/ui/unwrap_or_else_default.rs:65:24 + --> tests/ui/unwrap_or_else_default.rs:69:24 | LL | with_default_trait.unwrap_or_else(Default::default); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> tests/ui/unwrap_or_else_default.rs:69:23 + --> tests/ui/unwrap_or_else_default.rs:73:23 | LL | with_default_type.unwrap_or_else(u64::default); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> tests/ui/unwrap_or_else_default.rs:73:23 + --> tests/ui/unwrap_or_else_default.rs:77:23 | LL | with_default_type.unwrap_or_else(Vec::new); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> tests/ui/unwrap_or_else_default.rs:77:18 + --> tests/ui/unwrap_or_else_default.rs:81:18 | LL | empty_string.unwrap_or_else(|| "".to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` -error: use of `unwrap_or_else` to construct default value - --> tests/ui/unwrap_or_else_default.rs:82:12 - | -LL | option.unwrap_or_else(Vec::new).push(1); - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` - error: use of `unwrap_or_else` to construct default value --> tests/ui/unwrap_or_else_default.rs:86:12 | @@ -86,13 +80,19 @@ LL | option.unwrap_or_else(Vec::new).push(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> tests/ui/unwrap_or_else_default.rs:127:12 + --> tests/ui/unwrap_or_else_default.rs:114: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:131:12 | LL | option.unwrap_or_else(Vec::new).push(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `or_insert_with` to construct default value - --> tests/ui/unwrap_or_else_default.rs:145:32 + --> tests/ui/unwrap_or_else_default.rs:149:32 | LL | let _ = inner_map.entry(0).or_insert_with(Default::default); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()`