Dogfood fixes to use bool::then_some

This commit is contained in:
Josh Triplett 2022-07-06 00:52:53 -07:00
parent ebff7206bc
commit b7230d4f44
16 changed files with 20 additions and 18 deletions

View file

@ -553,7 +553,7 @@ fn replace_ident_like(contents: &str, replacements: &[(&str, &str)]) -> Option<S
pos = m.end(); pos = m.end();
} }
result.push_str(&contents[pos..]); result.push_str(&contents[pos..]);
edited.then(|| result) edited.then_some(result)
} }
fn round_to_fifty(count: usize) -> usize { fn round_to_fifty(count: usize) -> usize {

View file

@ -730,7 +730,9 @@ fn walk_parents<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> (Position, &
Position::DerefStable(precedence) Position::DerefStable(precedence)
}) })
}, },
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 ExprKind::Call(func, args) => args
.iter() .iter()
.position(|arg| arg.hir_id == child_id) .position(|arg| arg.hir_id == child_id)

View file

@ -650,7 +650,7 @@ fn find_insert_calls<'tcx>(
let allow_insert_closure = s.allow_insert_closure; let allow_insert_closure = s.allow_insert_closure;
let is_single_insert = s.is_single_insert; let is_single_insert = s.is_single_insert;
let edits = s.edits; let edits = s.edits;
s.can_use_entry.then(|| InsertSearchResults { s.can_use_entry.then_some(InsertSearchResults {
edits, edits,
allow_insert_closure, allow_insert_closure,
is_single_insert, is_single_insert,

View file

@ -127,7 +127,7 @@ fn get_impl_span(cx: &LateContext<'_>, id: LocalDefId) -> Option<Span> {
(!span.from_expansion() (!span.from_expansion()
&& impl_item.generics.params.is_empty() && impl_item.generics.params.is_empty()
&& !is_lint_allowed(cx, MULTIPLE_INHERENT_IMPL, id)) && !is_lint_allowed(cx, MULTIPLE_INHERENT_IMPL, id))
.then(|| span) .then_some(span)
} else { } else {
None None
} }

View file

@ -161,7 +161,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustiveEnum {
(matches!(v.data, hir::VariantData::Unit(_)) (matches!(v.data, hir::VariantData::Unit(_))
&& v.ident.as_str().starts_with('_') && v.ident.as_str().starts_with('_')
&& is_doc_hidden(cx.tcx.hir().attrs(v.id))) && 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() if let Some((id, span)) = iter.next()
&& iter.next().is_none() && iter.next().is_none()

View file

@ -105,7 +105,7 @@ fn check<'tcx>(
// Determine which binding mode to use. // Determine which binding mode to use.
let explicit_ref = some_pat.contains_explicit_ref_binding(); 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 { let as_ref_str = match binding_ref {
Some(Mutability::Mut) => ".as_mut()", Some(Mutability::Mut) => ".as_mut()",

View file

@ -38,7 +38,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>]) {
normalized_pats[i + 1..] normalized_pats[i + 1..]
.iter() .iter()
.enumerate() .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()) .unwrap_or(normalized_pats.len())
}) })
.collect(); .collect();
@ -55,7 +55,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>]) {
.zip(forwards_blocking_idxs[..i].iter().copied().rev()) .zip(forwards_blocking_idxs[..i].iter().copied().rev())
.skip_while(|&(_, forward_block)| forward_block > i) .skip_while(|&(_, forward_block)| forward_block > i)
.find_map(|((j, other), forward_block)| { .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) .unwrap_or(0)
}) })

View file

@ -1061,7 +1061,7 @@ fn contains_cfg_arm(cx: &LateContext<'_>, e: &Expr<'_>, scrutinee: &Expr<'_>, ar
let start = scrutinee_span.hi(); let start = scrutinee_span.hi();
let mut arm_spans = arms.iter().map(|arm| { let mut arm_spans = arms.iter().map(|arm| {
let data = arm.span.data(); 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(); let end = e.span.hi();
@ -1095,7 +1095,7 @@ fn contains_cfg_arm(cx: &LateContext<'_>, e: &Expr<'_>, scrutinee: &Expr<'_>, ar
parent: None, parent: None,
} }
.span(); .span();
(!span_contains_cfg(cx, span)).then(|| next_start).ok_or(()) (!span_contains_cfg(cx, span)).then_some(next_start).ok_or(())
}); });
match found { match found {
Ok(start) => { Ok(start) => {

View file

@ -43,7 +43,7 @@ fn parse_repeat_arg(cx: &LateContext<'_>, e: &Expr<'_>) -> Option<RepeatKind> {
Some(RepeatKind::String) Some(RepeatKind::String)
} else { } else {
let ty = ty.peel_refs(); 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)
} }
} }
} }

View file

@ -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 { if let ExprKind::Path(QPath::Resolved(None, Path { res: Res::Local(local_id), .. })) = e.kind {
match some_captures.get(local_id) 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::Value | CaptureKind::Ref(Mutability::Mut)) => return None,
Some(CaptureKind::Ref(Mutability::Not)) if as_mut => return None, Some(CaptureKind::Ref(Mutability::Not)) if as_mut => return None,

View file

@ -501,7 +501,7 @@ fn check_mut_from_ref<'tcx>(cx: &LateContext<'tcx>, sig: &FnSig<'_>, body: Optio
.iter() .iter()
.filter_map(get_rptr_lm) .filter_map(get_rptr_lm)
.filter(|&(lt, _, _)| lt.name == out.name) .filter(|&(lt, _, _)| lt.name == out.name)
.map(|(_, mutability, span)| (mutability == Mutability::Not).then(|| span)) .map(|(_, mutability, span)| (mutability == Mutability::Not).then_some(span))
.collect(); .collect();
if let Some(args) = args if let Some(args) = args
&& !args.is_empty() && !args.is_empty()

View file

@ -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 && let ExprKind::Unary(UnOp::Deref, derefed_expr) = borrowed_expr.kind
&& cx.typeck_results().expr_ty(derefed_expr).is_unsafe_ptr() && cx.typeck_results().expr_ty(derefed_expr).is_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 { } else {
(false, None) (false, None)
} }

View file

@ -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> { fn get_lint_level_from_group(lint_group: &str) -> Option<&'static str> {
DEFAULT_LINT_LEVELS DEFAULT_LINT_LEVELS
.iter() .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 { pub(super) fn is_deprecated_lint(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> bool {

View file

@ -515,7 +515,7 @@ impl Write {
args.push(arg, span); 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 /// Checks the arguments of `print[ln]!` and `write[ln]!` calls. It will return a tuple of two

View file

@ -1016,7 +1016,7 @@ pub fn can_move_expr_to_closure<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'
captures: HirIdMap::default(), captures: HirIdMap::default(),
}; };
v.visit_expr(expr); 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 /// Returns the method names and argument list of nested method call expressions that make up

View file

@ -353,7 +353,7 @@ pub fn snippet_with_context<'a>(
/// span containing `m!(0)`. /// span containing `m!(0)`.
pub fn walk_span_to_context(span: Span, outer: SyntaxContext) -> Option<Span> { pub fn walk_span_to_context(span: Span, outer: SyntaxContext) -> Option<Span> {
let outer_span = hygiene::walk_chain(span, outer); 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. /// Removes block comments from the given `Vec` of lines.