mirror of
https://github.com/rust-lang/rust-clippy
synced 2025-02-17 14:38:46 +00:00
Auto merge of #9099 - joshtriplett:unnecessary-lazy-eval-then-some, r=flip1995
Extend unnecessary_lazy_eval to cover `bool::then` -> `bool::then_some` fixes #9097 changelog: Extend `unnecessary_lazy_eval` to convert `bool::then` to `bool::then_some`
This commit is contained in:
commit
f93d418f17
22 changed files with 78 additions and 54 deletions
|
@ -553,7 +553,7 @@ fn replace_ident_like(contents: &str, replacements: &[(&str, &str)]) -> Option<S
|
|||
pos = m.end();
|
||||
}
|
||||
result.push_str(&contents[pos..]);
|
||||
edited.then(|| result)
|
||||
edited.then_some(result)
|
||||
}
|
||||
|
||||
fn round_to_fifty(count: usize) -> usize {
|
||||
|
|
|
@ -744,7 +744,9 @@ fn walk_parents<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> (Position, &
|
|||
},
|
||||
)
|
||||
},
|
||||
ExprKind::Call(func, _) if func.hir_id == child_id => (child_id == e.hir_id).then(|| Position::Callee),
|
||||
ExprKind::Call(func, _) if func.hir_id == child_id => {
|
||||
(child_id == e.hir_id).then_some(Position::Callee)
|
||||
},
|
||||
ExprKind::Call(func, args) => args
|
||||
.iter()
|
||||
.position(|arg| arg.hir_id == child_id)
|
||||
|
|
|
@ -650,7 +650,7 @@ fn find_insert_calls<'tcx>(
|
|||
let allow_insert_closure = s.allow_insert_closure;
|
||||
let is_single_insert = s.is_single_insert;
|
||||
let edits = s.edits;
|
||||
s.can_use_entry.then(|| InsertSearchResults {
|
||||
s.can_use_entry.then_some(InsertSearchResults {
|
||||
edits,
|
||||
allow_insert_closure,
|
||||
is_single_insert,
|
||||
|
|
|
@ -127,7 +127,7 @@ fn get_impl_span(cx: &LateContext<'_>, id: LocalDefId) -> Option<Span> {
|
|||
(!span.from_expansion()
|
||||
&& impl_item.generics.params.is_empty()
|
||||
&& !is_lint_allowed(cx, MULTIPLE_INHERENT_IMPL, id))
|
||||
.then(|| span)
|
||||
.then_some(span)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
|
@ -161,7 +161,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustiveEnum {
|
|||
(matches!(v.data, hir::VariantData::Unit(_))
|
||||
&& v.ident.as_str().starts_with('_')
|
||||
&& is_doc_hidden(cx.tcx.hir().attrs(v.id)))
|
||||
.then(|| (id, v.span))
|
||||
.then_some((id, v.span))
|
||||
});
|
||||
if let Some((id, span)) = iter.next()
|
||||
&& iter.next().is_none()
|
||||
|
|
|
@ -105,7 +105,7 @@ fn check<'tcx>(
|
|||
|
||||
// Determine which binding mode to use.
|
||||
let explicit_ref = some_pat.contains_explicit_ref_binding();
|
||||
let binding_ref = explicit_ref.or_else(|| (ty_ref_count != pat_ref_count).then(|| ty_mutability));
|
||||
let binding_ref = explicit_ref.or_else(|| (ty_ref_count != pat_ref_count).then_some(ty_mutability));
|
||||
|
||||
let as_ref_str = match binding_ref {
|
||||
Some(Mutability::Mut) => ".as_mut()",
|
||||
|
|
|
@ -38,7 +38,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>]) {
|
|||
normalized_pats[i + 1..]
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find_map(|(j, other)| pat.has_overlapping_values(other).then(|| i + 1 + j))
|
||||
.find_map(|(j, other)| pat.has_overlapping_values(other).then_some(i + 1 + j))
|
||||
.unwrap_or(normalized_pats.len())
|
||||
})
|
||||
.collect();
|
||||
|
@ -55,7 +55,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>]) {
|
|||
.zip(forwards_blocking_idxs[..i].iter().copied().rev())
|
||||
.skip_while(|&(_, forward_block)| forward_block > i)
|
||||
.find_map(|((j, other), forward_block)| {
|
||||
(forward_block == i || pat.has_overlapping_values(other)).then(|| j)
|
||||
(forward_block == i || pat.has_overlapping_values(other)).then_some(j)
|
||||
})
|
||||
.unwrap_or(0)
|
||||
})
|
||||
|
|
|
@ -1061,7 +1061,7 @@ fn contains_cfg_arm(cx: &LateContext<'_>, e: &Expr<'_>, scrutinee: &Expr<'_>, ar
|
|||
let start = scrutinee_span.hi();
|
||||
let mut arm_spans = arms.iter().map(|arm| {
|
||||
let data = arm.span.data();
|
||||
(data.ctxt == SyntaxContext::root()).then(|| (data.lo, data.hi))
|
||||
(data.ctxt == SyntaxContext::root()).then_some((data.lo, data.hi))
|
||||
});
|
||||
let end = e.span.hi();
|
||||
|
||||
|
@ -1095,7 +1095,7 @@ fn contains_cfg_arm(cx: &LateContext<'_>, e: &Expr<'_>, scrutinee: &Expr<'_>, ar
|
|||
parent: None,
|
||||
}
|
||||
.span();
|
||||
(!span_contains_cfg(cx, span)).then(|| next_start).ok_or(())
|
||||
(!span_contains_cfg(cx, span)).then_some(next_start).ok_or(())
|
||||
});
|
||||
match found {
|
||||
Ok(start) => {
|
||||
|
|
|
@ -43,7 +43,7 @@ fn parse_repeat_arg(cx: &LateContext<'_>, e: &Expr<'_>) -> Option<RepeatKind> {
|
|||
Some(RepeatKind::String)
|
||||
} else {
|
||||
let ty = ty.peel_refs();
|
||||
(ty.is_str() || is_type_diagnostic_item(cx, ty, sym::String)).then(|| RepeatKind::String)
|
||||
(ty.is_str() || is_type_diagnostic_item(cx, ty, sym::String)).then_some(RepeatKind::String)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2737,6 +2737,12 @@ impl Methods {
|
|||
}
|
||||
},
|
||||
("take", []) => needless_option_take::check(cx, expr, recv),
|
||||
("then", [arg]) => {
|
||||
if !meets_msrv(self.msrv, msrvs::BOOL_THEN_SOME) {
|
||||
return;
|
||||
}
|
||||
unnecessary_lazy_eval::check(cx, expr, recv, arg, "then_some");
|
||||
},
|
||||
("to_os_string" | "to_owned" | "to_path_buf" | "to_vec", []) => {
|
||||
implicit_clone::check(cx, name, expr, recv);
|
||||
},
|
||||
|
|
|
@ -20,8 +20,9 @@ pub(super) fn check<'tcx>(
|
|||
) {
|
||||
let is_option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Option);
|
||||
let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result);
|
||||
let is_bool = cx.typeck_results().expr_ty(recv).is_bool();
|
||||
|
||||
if is_option || is_result {
|
||||
if is_option || is_result || is_bool {
|
||||
if let hir::ExprKind::Closure { body, .. } = arg.kind {
|
||||
let body = cx.tcx.hir().body(body);
|
||||
let body_expr = &body.value;
|
||||
|
@ -33,8 +34,10 @@ pub(super) fn check<'tcx>(
|
|||
if eager_or_lazy::switch_to_eager_eval(cx, body_expr) {
|
||||
let msg = if is_option {
|
||||
"unnecessary closure used to substitute value for `Option::None`"
|
||||
} else {
|
||||
} else if is_result {
|
||||
"unnecessary closure used to substitute value for `Result::Err`"
|
||||
} else {
|
||||
"unnecessary closure used with `bool::then`"
|
||||
};
|
||||
let applicability = if body
|
||||
.params
|
||||
|
|
|
@ -146,7 +146,7 @@ fn detect_option_if_let_else<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>) ->
|
|||
});
|
||||
if let ExprKind::Path(QPath::Resolved(None, Path { res: Res::Local(local_id), .. })) = e.kind {
|
||||
match some_captures.get(local_id)
|
||||
.or_else(|| (method_sugg == "map_or_else").then(|| ()).and_then(|_| none_captures.get(local_id)))
|
||||
.or_else(|| (method_sugg == "map_or_else").then_some(()).and_then(|_| none_captures.get(local_id)))
|
||||
{
|
||||
Some(CaptureKind::Value | CaptureKind::Ref(Mutability::Mut)) => return None,
|
||||
Some(CaptureKind::Ref(Mutability::Not)) if as_mut => return None,
|
||||
|
|
|
@ -501,7 +501,7 @@ fn check_mut_from_ref<'tcx>(cx: &LateContext<'tcx>, sig: &FnSig<'_>, body: Optio
|
|||
.iter()
|
||||
.filter_map(get_rptr_lm)
|
||||
.filter(|&(lt, _, _)| lt.name == out.name)
|
||||
.map(|(_, mutability, span)| (mutability == Mutability::Not).then(|| span))
|
||||
.map(|(_, mutability, span)| (mutability == Mutability::Not).then_some(span))
|
||||
.collect();
|
||||
if let Some(args) = args
|
||||
&& !args.is_empty()
|
||||
|
|
|
@ -73,7 +73,7 @@ fn is_ptr_to_ref(cx: &LateContext<'_>, e: &Expr<'_>, ctxt: SyntaxContext) -> (bo
|
|||
&& let ExprKind::Unary(UnOp::Deref, derefed_expr) = borrowed_expr.kind
|
||||
&& cx.typeck_results().expr_ty(derefed_expr).is_unsafe_ptr()
|
||||
{
|
||||
(true, (borrowed_expr.span.ctxt() == ctxt || derefed_expr.span.ctxt() == ctxt).then(|| derefed_expr.span))
|
||||
(true, (borrowed_expr.span.ctxt() == ctxt || derefed_expr.span.ctxt() == ctxt).then_some(derefed_expr.span))
|
||||
} else {
|
||||
(false, None)
|
||||
}
|
||||
|
|
|
@ -843,7 +843,7 @@ fn get_lint_group(cx: &LateContext<'_>, lint_id: LintId) -> Option<String> {
|
|||
fn get_lint_level_from_group(lint_group: &str) -> Option<&'static str> {
|
||||
DEFAULT_LINT_LEVELS
|
||||
.iter()
|
||||
.find_map(|(group_name, group_level)| (*group_name == lint_group).then(|| *group_level))
|
||||
.find_map(|(group_name, group_level)| (*group_name == lint_group).then_some(*group_level))
|
||||
}
|
||||
|
||||
pub(super) fn is_deprecated_lint(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> bool {
|
||||
|
|
|
@ -515,7 +515,7 @@ impl Write {
|
|||
args.push(arg, span);
|
||||
}
|
||||
|
||||
parser.errors.is_empty().then(move || args)
|
||||
parser.errors.is_empty().then_some(args)
|
||||
}
|
||||
|
||||
/// Checks the arguments of `print[ln]!` and `write[ln]!` calls. It will return a tuple of two
|
||||
|
|
|
@ -1016,7 +1016,7 @@ pub fn can_move_expr_to_closure<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'
|
|||
captures: HirIdMap::default(),
|
||||
};
|
||||
v.visit_expr(expr);
|
||||
v.allow_closure.then(|| v.captures)
|
||||
v.allow_closure.then_some(v.captures)
|
||||
}
|
||||
|
||||
/// Returns the method names and argument list of nested method call expressions that make up
|
||||
|
|
|
@ -12,6 +12,7 @@ macro_rules! msrv_aliases {
|
|||
|
||||
// names may refer to stabilized feature flags or library items
|
||||
msrv_aliases! {
|
||||
1,62,0 { BOOL_THEN_SOME }
|
||||
1,53,0 { OR_PATTERNS, MANUAL_BITS, BTREE_MAP_RETAIN, BTREE_SET_RETAIN }
|
||||
1,52,0 { STR_SPLIT_ONCE, REM_EUCLID_CONST }
|
||||
1,51,0 { BORROW_AS_PTR, UNSIGNED_ABS }
|
||||
|
|
|
@ -353,7 +353,7 @@ pub fn snippet_with_context<'a>(
|
|||
/// span containing `m!(0)`.
|
||||
pub fn walk_span_to_context(span: Span, outer: SyntaxContext) -> Option<Span> {
|
||||
let outer_span = hygiene::walk_chain(span, outer);
|
||||
(outer_span.ctxt() == outer).then(|| outer_span)
|
||||
(outer_span.ctxt() == outer).then_some(outer_span)
|
||||
}
|
||||
|
||||
/// Removes block comments from the given `Vec` of lines.
|
||||
|
|
|
@ -30,6 +30,7 @@ fn main() {
|
|||
let ext_opt = Some(42);
|
||||
let nested_opt = Some(Some(42));
|
||||
let nested_tuple_opt = Some(Some((42, 43)));
|
||||
let cond = true;
|
||||
|
||||
// Should lint - Option
|
||||
let _ = opt.unwrap_or(2);
|
||||
|
@ -42,6 +43,7 @@ fn main() {
|
|||
let _ = opt.get_or_insert(2);
|
||||
let _ = opt.ok_or(2);
|
||||
let _ = nested_tuple_opt.unwrap_or(Some((1, 2)));
|
||||
let _ = cond.then_some(astronomers_pi);
|
||||
|
||||
// Cases when unwrap is not called on a simple variable
|
||||
let _ = Some(10).unwrap_or(2);
|
||||
|
|
|
@ -30,6 +30,7 @@ fn main() {
|
|||
let ext_opt = Some(42);
|
||||
let nested_opt = Some(Some(42));
|
||||
let nested_tuple_opt = Some(Some((42, 43)));
|
||||
let cond = true;
|
||||
|
||||
// Should lint - Option
|
||||
let _ = opt.unwrap_or_else(|| 2);
|
||||
|
@ -42,6 +43,7 @@ fn main() {
|
|||
let _ = opt.get_or_insert_with(|| 2);
|
||||
let _ = opt.ok_or_else(|| 2);
|
||||
let _ = nested_tuple_opt.unwrap_or_else(|| Some((1, 2)));
|
||||
let _ = cond.then(|| astronomers_pi);
|
||||
|
||||
// Cases when unwrap is not called on a simple variable
|
||||
let _ = Some(10).unwrap_or_else(|| 2);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:35:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:36:13
|
||||
|
|
||||
LL | let _ = opt.unwrap_or_else(|| 2);
|
||||
| ^^^^--------------------
|
||||
|
@ -9,7 +9,7 @@ LL | let _ = opt.unwrap_or_else(|| 2);
|
|||
= note: `-D clippy::unnecessary-lazy-evaluations` implied by `-D warnings`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:36:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:37:13
|
||||
|
|
||||
LL | let _ = opt.unwrap_or_else(|| astronomers_pi);
|
||||
| ^^^^---------------------------------
|
||||
|
@ -17,7 +17,7 @@ LL | let _ = opt.unwrap_or_else(|| astronomers_pi);
|
|||
| help: use `unwrap_or(..)` instead: `unwrap_or(astronomers_pi)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:37:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:38:13
|
||||
|
|
||||
LL | let _ = opt.unwrap_or_else(|| ext_str.some_field);
|
||||
| ^^^^-------------------------------------
|
||||
|
@ -25,7 +25,7 @@ LL | let _ = opt.unwrap_or_else(|| ext_str.some_field);
|
|||
| help: use `unwrap_or(..)` instead: `unwrap_or(ext_str.some_field)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:39:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:40:13
|
||||
|
|
||||
LL | let _ = opt.and_then(|_| ext_opt);
|
||||
| ^^^^---------------------
|
||||
|
@ -33,7 +33,7 @@ LL | let _ = opt.and_then(|_| ext_opt);
|
|||
| help: use `and(..)` instead: `and(ext_opt)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:40:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:41:13
|
||||
|
|
||||
LL | let _ = opt.or_else(|| ext_opt);
|
||||
| ^^^^-------------------
|
||||
|
@ -41,7 +41,7 @@ LL | let _ = opt.or_else(|| ext_opt);
|
|||
| help: use `or(..)` instead: `or(ext_opt)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:41:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:42:13
|
||||
|
|
||||
LL | let _ = opt.or_else(|| None);
|
||||
| ^^^^----------------
|
||||
|
@ -49,7 +49,7 @@ LL | let _ = opt.or_else(|| None);
|
|||
| help: use `or(..)` instead: `or(None)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:42:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:43:13
|
||||
|
|
||||
LL | let _ = opt.get_or_insert_with(|| 2);
|
||||
| ^^^^------------------------
|
||||
|
@ -57,7 +57,7 @@ LL | let _ = opt.get_or_insert_with(|| 2);
|
|||
| help: use `get_or_insert(..)` instead: `get_or_insert(2)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:43:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:44:13
|
||||
|
|
||||
LL | let _ = opt.ok_or_else(|| 2);
|
||||
| ^^^^----------------
|
||||
|
@ -65,15 +65,23 @@ LL | let _ = opt.ok_or_else(|| 2);
|
|||
| help: use `ok_or(..)` instead: `ok_or(2)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:44:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:45:13
|
||||
|
|
||||
LL | let _ = nested_tuple_opt.unwrap_or_else(|| Some((1, 2)));
|
||||
| ^^^^^^^^^^^^^^^^^-------------------------------
|
||||
| |
|
||||
| help: use `unwrap_or(..)` instead: `unwrap_or(Some((1, 2)))`
|
||||
|
||||
error: unnecessary closure used with `bool::then`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:46:13
|
||||
|
|
||||
LL | let _ = cond.then(|| astronomers_pi);
|
||||
| ^^^^^-----------------------
|
||||
| |
|
||||
| help: use `then_some(..)` instead: `then_some(astronomers_pi)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:47:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:49:13
|
||||
|
|
||||
LL | let _ = Some(10).unwrap_or_else(|| 2);
|
||||
| ^^^^^^^^^--------------------
|
||||
|
@ -81,7 +89,7 @@ LL | let _ = Some(10).unwrap_or_else(|| 2);
|
|||
| help: use `unwrap_or(..)` instead: `unwrap_or(2)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:48:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:50:13
|
||||
|
|
||||
LL | let _ = Some(10).and_then(|_| ext_opt);
|
||||
| ^^^^^^^^^---------------------
|
||||
|
@ -89,7 +97,7 @@ LL | let _ = Some(10).and_then(|_| ext_opt);
|
|||
| help: use `and(..)` instead: `and(ext_opt)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:49:28
|
||||
--> $DIR/unnecessary_lazy_eval.rs:51:28
|
||||
|
|
||||
LL | let _: Option<usize> = None.or_else(|| ext_opt);
|
||||
| ^^^^^-------------------
|
||||
|
@ -97,7 +105,7 @@ LL | let _: Option<usize> = None.or_else(|| ext_opt);
|
|||
| help: use `or(..)` instead: `or(ext_opt)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:50:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:52:13
|
||||
|
|
||||
LL | let _ = None.get_or_insert_with(|| 2);
|
||||
| ^^^^^------------------------
|
||||
|
@ -105,7 +113,7 @@ LL | let _ = None.get_or_insert_with(|| 2);
|
|||
| help: use `get_or_insert(..)` instead: `get_or_insert(2)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:51:35
|
||||
--> $DIR/unnecessary_lazy_eval.rs:53:35
|
||||
|
|
||||
LL | let _: Result<usize, usize> = None.ok_or_else(|| 2);
|
||||
| ^^^^^----------------
|
||||
|
@ -113,7 +121,7 @@ LL | let _: Result<usize, usize> = None.ok_or_else(|| 2);
|
|||
| help: use `ok_or(..)` instead: `ok_or(2)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:52:28
|
||||
--> $DIR/unnecessary_lazy_eval.rs:54:28
|
||||
|
|
||||
LL | let _: Option<usize> = None.or_else(|| None);
|
||||
| ^^^^^----------------
|
||||
|
@ -121,7 +129,7 @@ LL | let _: Option<usize> = None.or_else(|| None);
|
|||
| help: use `or(..)` instead: `or(None)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:55:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:57:13
|
||||
|
|
||||
LL | let _ = deep.0.unwrap_or_else(|| 2);
|
||||
| ^^^^^^^--------------------
|
||||
|
@ -129,7 +137,7 @@ LL | let _ = deep.0.unwrap_or_else(|| 2);
|
|||
| help: use `unwrap_or(..)` instead: `unwrap_or(2)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:56:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:58:13
|
||||
|
|
||||
LL | let _ = deep.0.and_then(|_| ext_opt);
|
||||
| ^^^^^^^---------------------
|
||||
|
@ -137,7 +145,7 @@ LL | let _ = deep.0.and_then(|_| ext_opt);
|
|||
| help: use `and(..)` instead: `and(ext_opt)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:57:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:59:13
|
||||
|
|
||||
LL | let _ = deep.0.or_else(|| None);
|
||||
| ^^^^^^^----------------
|
||||
|
@ -145,7 +153,7 @@ LL | let _ = deep.0.or_else(|| None);
|
|||
| help: use `or(..)` instead: `or(None)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:58:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:60:13
|
||||
|
|
||||
LL | let _ = deep.0.get_or_insert_with(|| 2);
|
||||
| ^^^^^^^------------------------
|
||||
|
@ -153,7 +161,7 @@ LL | let _ = deep.0.get_or_insert_with(|| 2);
|
|||
| help: use `get_or_insert(..)` instead: `get_or_insert(2)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:59:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:61:13
|
||||
|
|
||||
LL | let _ = deep.0.ok_or_else(|| 2);
|
||||
| ^^^^^^^----------------
|
||||
|
@ -161,7 +169,7 @@ LL | let _ = deep.0.ok_or_else(|| 2);
|
|||
| help: use `ok_or(..)` instead: `ok_or(2)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:79:28
|
||||
--> $DIR/unnecessary_lazy_eval.rs:81:28
|
||||
|
|
||||
LL | let _: Option<usize> = None.or_else(|| Some(3));
|
||||
| ^^^^^-------------------
|
||||
|
@ -169,7 +177,7 @@ LL | let _: Option<usize> = None.or_else(|| Some(3));
|
|||
| help: use `or(..)` instead: `or(Some(3))`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:80:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:82:13
|
||||
|
|
||||
LL | let _ = deep.0.or_else(|| Some(3));
|
||||
| ^^^^^^^-------------------
|
||||
|
@ -177,7 +185,7 @@ LL | let _ = deep.0.or_else(|| Some(3));
|
|||
| help: use `or(..)` instead: `or(Some(3))`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:81:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:83:13
|
||||
|
|
||||
LL | let _ = opt.or_else(|| Some(3));
|
||||
| ^^^^-------------------
|
||||
|
@ -185,7 +193,7 @@ LL | let _ = opt.or_else(|| Some(3));
|
|||
| help: use `or(..)` instead: `or(Some(3))`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Result::Err`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:87:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:89:13
|
||||
|
|
||||
LL | let _ = res2.unwrap_or_else(|_| 2);
|
||||
| ^^^^^---------------------
|
||||
|
@ -193,7 +201,7 @@ LL | let _ = res2.unwrap_or_else(|_| 2);
|
|||
| help: use `unwrap_or(..)` instead: `unwrap_or(2)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Result::Err`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:88:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:90:13
|
||||
|
|
||||
LL | let _ = res2.unwrap_or_else(|_| astronomers_pi);
|
||||
| ^^^^^----------------------------------
|
||||
|
@ -201,7 +209,7 @@ LL | let _ = res2.unwrap_or_else(|_| astronomers_pi);
|
|||
| help: use `unwrap_or(..)` instead: `unwrap_or(astronomers_pi)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Result::Err`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:89:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:91:13
|
||||
|
|
||||
LL | let _ = res2.unwrap_or_else(|_| ext_str.some_field);
|
||||
| ^^^^^--------------------------------------
|
||||
|
@ -209,7 +217,7 @@ LL | let _ = res2.unwrap_or_else(|_| ext_str.some_field);
|
|||
| help: use `unwrap_or(..)` instead: `unwrap_or(ext_str.some_field)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Result::Err`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:111:35
|
||||
--> $DIR/unnecessary_lazy_eval.rs:113:35
|
||||
|
|
||||
LL | let _: Result<usize, usize> = res.and_then(|_| Err(2));
|
||||
| ^^^^--------------------
|
||||
|
@ -217,7 +225,7 @@ LL | let _: Result<usize, usize> = res.and_then(|_| Err(2));
|
|||
| help: use `and(..)` instead: `and(Err(2))`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Result::Err`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:112:35
|
||||
--> $DIR/unnecessary_lazy_eval.rs:114:35
|
||||
|
|
||||
LL | let _: Result<usize, usize> = res.and_then(|_| Err(astronomers_pi));
|
||||
| ^^^^---------------------------------
|
||||
|
@ -225,7 +233,7 @@ LL | let _: Result<usize, usize> = res.and_then(|_| Err(astronomers_pi));
|
|||
| help: use `and(..)` instead: `and(Err(astronomers_pi))`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Result::Err`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:113:35
|
||||
--> $DIR/unnecessary_lazy_eval.rs:115:35
|
||||
|
|
||||
LL | let _: Result<usize, usize> = res.and_then(|_| Err(ext_str.some_field));
|
||||
| ^^^^-------------------------------------
|
||||
|
@ -233,7 +241,7 @@ LL | let _: Result<usize, usize> = res.and_then(|_| Err(ext_str.some_field))
|
|||
| help: use `and(..)` instead: `and(Err(ext_str.some_field))`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Result::Err`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:115:35
|
||||
--> $DIR/unnecessary_lazy_eval.rs:117:35
|
||||
|
|
||||
LL | let _: Result<usize, usize> = res.or_else(|_| Ok(2));
|
||||
| ^^^^------------------
|
||||
|
@ -241,7 +249,7 @@ LL | let _: Result<usize, usize> = res.or_else(|_| Ok(2));
|
|||
| help: use `or(..)` instead: `or(Ok(2))`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Result::Err`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:116:35
|
||||
--> $DIR/unnecessary_lazy_eval.rs:118:35
|
||||
|
|
||||
LL | let _: Result<usize, usize> = res.or_else(|_| Ok(astronomers_pi));
|
||||
| ^^^^-------------------------------
|
||||
|
@ -249,7 +257,7 @@ LL | let _: Result<usize, usize> = res.or_else(|_| Ok(astronomers_pi));
|
|||
| help: use `or(..)` instead: `or(Ok(astronomers_pi))`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Result::Err`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:117:35
|
||||
--> $DIR/unnecessary_lazy_eval.rs:119:35
|
||||
|
|
||||
LL | let _: Result<usize, usize> = res.or_else(|_| Ok(ext_str.some_field));
|
||||
| ^^^^-----------------------------------
|
||||
|
@ -257,7 +265,7 @@ LL | let _: Result<usize, usize> = res.or_else(|_| Ok(ext_str.some_field));
|
|||
| help: use `or(..)` instead: `or(Ok(ext_str.some_field))`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Result::Err`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:118:35
|
||||
--> $DIR/unnecessary_lazy_eval.rs:120:35
|
||||
|
|
||||
LL | let _: Result<usize, usize> = res.
|
||||
| ___________________________________^
|
||||
|
@ -271,5 +279,5 @@ LL | | or_else(|_| Ok(ext_str.some_field));
|
|||
| |
|
||||
| help: use `or(..)` instead: `or(Ok(ext_str.some_field))`
|
||||
|
||||
error: aborting due to 33 previous errors
|
||||
error: aborting due to 34 previous errors
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue