mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 23:20:39 +00:00
Dogfood fixes to use bool::then_some
This commit is contained in:
parent
ebff7206bc
commit
b7230d4f44
16 changed files with 20 additions and 18 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 {
|
||||
|
|
|
@ -730,7 +730,9 @@ fn walk_parents<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> (Position, &
|
|||
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
|
||||
.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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue