Skip to content

Commit b7230d4

Browse files
committed
Dogfood fixes to use bool::then_some
1 parent ebff720 commit b7230d4

16 files changed

+20
-18
lines changed

clippy_dev/src/update_lints.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ fn replace_ident_like(contents: &str, replacements: &[(&str, &str)]) -> Option<S
553553
pos = m.end();
554554
}
555555
result.push_str(&contents[pos..]);
556-
edited.then(|| result)
556+
edited.then_some(result)
557557
}
558558

559559
fn round_to_fifty(count: usize) -> usize {

clippy_lints/src/dereference.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,9 @@ fn walk_parents<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> (Position, &
730730
Position::DerefStable(precedence)
731731
})
732732
},
733-
ExprKind::Call(func, _) if func.hir_id == child_id => (child_id == e.hir_id).then(|| Position::Callee),
733+
ExprKind::Call(func, _) if func.hir_id == child_id => {
734+
(child_id == e.hir_id).then_some(Position::Callee)
735+
},
734736
ExprKind::Call(func, args) => args
735737
.iter()
736738
.position(|arg| arg.hir_id == child_id)

clippy_lints/src/entry.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ fn find_insert_calls<'tcx>(
650650
let allow_insert_closure = s.allow_insert_closure;
651651
let is_single_insert = s.is_single_insert;
652652
let edits = s.edits;
653-
s.can_use_entry.then(|| InsertSearchResults {
653+
s.can_use_entry.then_some(InsertSearchResults {
654654
edits,
655655
allow_insert_closure,
656656
is_single_insert,

clippy_lints/src/inherent_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ fn get_impl_span(cx: &LateContext<'_>, id: LocalDefId) -> Option<Span> {
127127
(!span.from_expansion()
128128
&& impl_item.generics.params.is_empty()
129129
&& !is_lint_allowed(cx, MULTIPLE_INHERENT_IMPL, id))
130-
.then(|| span)
130+
.then_some(span)
131131
} else {
132132
None
133133
}

clippy_lints/src/manual_non_exhaustive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustiveEnum {
161161
(matches!(v.data, hir::VariantData::Unit(_))
162162
&& v.ident.as_str().starts_with('_')
163163
&& is_doc_hidden(cx.tcx.hir().attrs(v.id)))
164-
.then(|| (id, v.span))
164+
.then_some((id, v.span))
165165
});
166166
if let Some((id, span)) = iter.next()
167167
&& iter.next().is_none()

clippy_lints/src/matches/manual_map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ fn check<'tcx>(
105105

106106
// Determine which binding mode to use.
107107
let explicit_ref = some_pat.contains_explicit_ref_binding();
108-
let binding_ref = explicit_ref.or_else(|| (ty_ref_count != pat_ref_count).then(|| ty_mutability));
108+
let binding_ref = explicit_ref.or_else(|| (ty_ref_count != pat_ref_count).then_some(ty_mutability));
109109

110110
let as_ref_str = match binding_ref {
111111
Some(Mutability::Mut) => ".as_mut()",

clippy_lints/src/matches/match_same_arms.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>]) {
3838
normalized_pats[i + 1..]
3939
.iter()
4040
.enumerate()
41-
.find_map(|(j, other)| pat.has_overlapping_values(other).then(|| i + 1 + j))
41+
.find_map(|(j, other)| pat.has_overlapping_values(other).then_some(i + 1 + j))
4242
.unwrap_or(normalized_pats.len())
4343
})
4444
.collect();
@@ -55,7 +55,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>]) {
5555
.zip(forwards_blocking_idxs[..i].iter().copied().rev())
5656
.skip_while(|&(_, forward_block)| forward_block > i)
5757
.find_map(|((j, other), forward_block)| {
58-
(forward_block == i || pat.has_overlapping_values(other)).then(|| j)
58+
(forward_block == i || pat.has_overlapping_values(other)).then_some(j)
5959
})
6060
.unwrap_or(0)
6161
})

clippy_lints/src/matches/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ fn contains_cfg_arm(cx: &LateContext<'_>, e: &Expr<'_>, scrutinee: &Expr<'_>, ar
10611061
let start = scrutinee_span.hi();
10621062
let mut arm_spans = arms.iter().map(|arm| {
10631063
let data = arm.span.data();
1064-
(data.ctxt == SyntaxContext::root()).then(|| (data.lo, data.hi))
1064+
(data.ctxt == SyntaxContext::root()).then_some((data.lo, data.hi))
10651065
});
10661066
let end = e.span.hi();
10671067

@@ -1095,7 +1095,7 @@ fn contains_cfg_arm(cx: &LateContext<'_>, e: &Expr<'_>, scrutinee: &Expr<'_>, ar
10951095
parent: None,
10961096
}
10971097
.span();
1098-
(!span_contains_cfg(cx, span)).then(|| next_start).ok_or(())
1098+
(!span_contains_cfg(cx, span)).then_some(next_start).ok_or(())
10991099
});
11001100
match found {
11011101
Ok(start) => {

clippy_lints/src/methods/manual_str_repeat.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fn parse_repeat_arg(cx: &LateContext<'_>, e: &Expr<'_>) -> Option<RepeatKind> {
4343
Some(RepeatKind::String)
4444
} else {
4545
let ty = ty.peel_refs();
46-
(ty.is_str() || is_type_diagnostic_item(cx, ty, sym::String)).then(|| RepeatKind::String)
46+
(ty.is_str() || is_type_diagnostic_item(cx, ty, sym::String)).then_some(RepeatKind::String)
4747
}
4848
}
4949
}

clippy_lints/src/option_if_let_else.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ fn detect_option_if_let_else<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>) ->
146146
});
147147
if let ExprKind::Path(QPath::Resolved(None, Path { res: Res::Local(local_id), .. })) = e.kind {
148148
match some_captures.get(local_id)
149-
.or_else(|| (method_sugg == "map_or_else").then(|| ()).and_then(|_| none_captures.get(local_id)))
149+
.or_else(|| (method_sugg == "map_or_else").then_some(()).and_then(|_| none_captures.get(local_id)))
150150
{
151151
Some(CaptureKind::Value | CaptureKind::Ref(Mutability::Mut)) => return None,
152152
Some(CaptureKind::Ref(Mutability::Not)) if as_mut => return None,

clippy_lints/src/ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ fn check_mut_from_ref<'tcx>(cx: &LateContext<'tcx>, sig: &FnSig<'_>, body: Optio
501501
.iter()
502502
.filter_map(get_rptr_lm)
503503
.filter(|&(lt, _, _)| lt.name == out.name)
504-
.map(|(_, mutability, span)| (mutability == Mutability::Not).then(|| span))
504+
.map(|(_, mutability, span)| (mutability == Mutability::Not).then_some(span))
505505
.collect();
506506
if let Some(args) = args
507507
&& !args.is_empty()

clippy_lints/src/swap_ptr_to_ref.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn is_ptr_to_ref(cx: &LateContext<'_>, e: &Expr<'_>, ctxt: SyntaxContext) -> (bo
7373
&& let ExprKind::Unary(UnOp::Deref, derefed_expr) = borrowed_expr.kind
7474
&& cx.typeck_results().expr_ty(derefed_expr).is_unsafe_ptr()
7575
{
76-
(true, (borrowed_expr.span.ctxt() == ctxt || derefed_expr.span.ctxt() == ctxt).then(|| derefed_expr.span))
76+
(true, (borrowed_expr.span.ctxt() == ctxt || derefed_expr.span.ctxt() == ctxt).then_some(derefed_expr.span))
7777
} else {
7878
(false, None)
7979
}

clippy_lints/src/utils/internal_lints/metadata_collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ fn get_lint_group(cx: &LateContext<'_>, lint_id: LintId) -> Option<String> {
843843
fn get_lint_level_from_group(lint_group: &str) -> Option<&'static str> {
844844
DEFAULT_LINT_LEVELS
845845
.iter()
846-
.find_map(|(group_name, group_level)| (*group_name == lint_group).then(|| *group_level))
846+
.find_map(|(group_name, group_level)| (*group_name == lint_group).then_some(*group_level))
847847
}
848848

849849
pub(super) fn is_deprecated_lint(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> bool {

clippy_lints/src/write.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ impl Write {
515515
args.push(arg, span);
516516
}
517517

518-
parser.errors.is_empty().then(move || args)
518+
parser.errors.is_empty().then_some(args)
519519
}
520520

521521
/// Checks the arguments of `print[ln]!` and `write[ln]!` calls. It will return a tuple of two

clippy_utils/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ pub fn can_move_expr_to_closure<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'
10161016
captures: HirIdMap::default(),
10171017
};
10181018
v.visit_expr(expr);
1019-
v.allow_closure.then(|| v.captures)
1019+
v.allow_closure.then_some(v.captures)
10201020
}
10211021

10221022
/// Returns the method names and argument list of nested method call expressions that make up

clippy_utils/src/source.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ pub fn snippet_with_context<'a>(
353353
/// span containing `m!(0)`.
354354
pub fn walk_span_to_context(span: Span, outer: SyntaxContext) -> Option<Span> {
355355
let outer_span = hygiene::walk_chain(span, outer);
356-
(outer_span.ctxt() == outer).then(|| outer_span)
356+
(outer_span.ctxt() == outer).then_some(outer_span)
357357
}
358358

359359
/// Removes block comments from the given `Vec` of lines.

0 commit comments

Comments
 (0)