Replace some thens with some then_somes

This commit is contained in:
Maybe Waffle 2023-02-15 17:39:43 +00:00
parent 8751fa1a9a
commit 5bf6a46032
24 changed files with 27 additions and 26 deletions

View File

@ -271,7 +271,7 @@ fn invalid_visibility(&self, vis: &Visibility, note: Option<InvalidVisibilityNot
self.session.emit_err(InvalidVisibility {
span: vis.span,
implied: vis.kind.is_pub().then(|| vis.span),
implied: vis.kind.is_pub().then_some(vis.span),
note,
});
}

View File

@ -1186,7 +1186,7 @@ fn suggest_using_local_if_applicable(
return None;
};
debug!("checking call args for uses of inner_param: {:?}", args);
args.contains(&Operand::Move(inner_param)).then(|| (loc, term))
args.contains(&Operand::Move(inner_param)).then_some((loc, term))
}) else {
debug!("no uses of inner_param found as a by-move call arg");
return;

View File

@ -62,7 +62,7 @@ pub fn inject(
// the one with the prelude.
let name = names[0];
let root = (edition == Edition2015).then(|| kw::PathRoot);
let root = (edition == Edition2015).then_some(kw::PathRoot);
let import_path = root
.iter()

View File

@ -154,7 +154,7 @@ fn struct_llfields<'a, 'tcx>(
} else {
debug!("struct_llfields: offset: {:?} stride: {:?}", offset, layout.size);
}
let field_remapping = padding_used.then(|| field_remapping);
let field_remapping = padding_used.then_some(field_remapping);
(result, packed, field_remapping)
}

View File

@ -2024,7 +2024,7 @@ fn linker_with_args<'a>(
.native_libraries
.iter()
.filter_map(|(cnum, libraries)| {
(dependency_linkage[cnum.as_usize() - 1] != Linkage::Static).then(|| libraries)
(dependency_linkage[cnum.as_usize() - 1] != Linkage::Static).then_some(libraries)
})
.flatten();
for (raw_dylib_name, raw_dylib_imports) in

View File

@ -255,7 +255,7 @@ fn try_configure_tokens<T: HasTokens>(&self, node: &mut T) {
fn configure_krate_attrs(&self, mut attrs: ast::AttrVec) -> Option<ast::AttrVec> {
attrs.flat_map_in_place(|attr| self.process_cfg_attr(attr));
self.in_cfg(&attrs).then(|| attrs)
self.in_cfg(&attrs).then_some(attrs)
}
/// Performs cfg-expansion on `stream`, producing a new `AttrTokenStream`.

View File

@ -204,7 +204,7 @@ fn main_fn_generics_params_span(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Span>
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
match tcx.hir().find(hir_id) {
Some(Node::Item(hir::Item { kind: hir::ItemKind::Fn(_, generics, _), .. })) => {
generics.params.is_empty().not().then(|| generics.span)
generics.params.is_empty().not().then_some(generics.span)
}
_ => {
span_bug!(tcx.def_span(def_id), "main has a non-function type");

View File

@ -1046,7 +1046,7 @@ pub fn deref_once_mutably_for_diagnostic(&self, expr_ty: Ty<'tcx>) -> Option<Ty<
self.param_env,
)
.may_apply()
.then(|| deref_ty)
.then_some(deref_ty)
})
}

View File

@ -2308,7 +2308,8 @@ fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &ast::Crate) {
.for_each(|(&name, &span)| {
let note = rustc_feature::find_feature_issue(name, GateIssue::Language)
.map(|n| BuiltinIncompleteFeaturesNote { n });
let help = HAS_MIN_FEATURES.contains(&name).then(|| BuiltinIncompleteFeaturesHelp);
let help =
HAS_MIN_FEATURES.contains(&name).then_some(BuiltinIncompleteFeaturesHelp);
cx.emit_spanned_lint(
INCOMPLETE_FEATURES,
span,

View File

@ -487,7 +487,7 @@ fn no_lint_suggestion(&self, lint_name: &str) -> CheckLintNameResult<'_> {
let mut groups: Vec<_> = self
.lint_groups
.iter()
.filter_map(|(k, LintGroup { depr, .. })| depr.is_none().then(|| k))
.filter_map(|(k, LintGroup { depr, .. })| depr.is_none().then_some(k))
.collect();
groups.sort();
let groups = groups.iter().map(|k| Symbol::intern(k));

View File

@ -414,7 +414,7 @@ pub fn mut_vars_iter<'a>(&'a self) -> impl Iterator<Item = Local> + Captures<'tc
(self.arg_count + 1..self.local_decls.len()).filter_map(move |index| {
let local = Local::new(index);
let decl = &self.local_decls[local];
(decl.is_user_variable() && decl.mutability.is_mut()).then(|| local)
(decl.is_user_variable() && decl.mutability.is_mut()).then_some(local)
})
}

View File

@ -584,7 +584,7 @@ pub fn fn_once_adapter_instance(
/// this function returns `None`, then the MIR body does not require substitution during
/// codegen.
fn substs_for_mir_body(&self) -> Option<SubstsRef<'tcx>> {
self.def.has_polymorphic_mir_body().then(|| self.substs)
self.def.has_polymorphic_mir_body().then_some(self.substs)
}
pub fn subst_mir<T>(&self, tcx: TyCtxt<'tcx>, v: &T) -> T

View File

@ -203,7 +203,7 @@ fn lower_pattern_range(
if !lower_overflow && !higher_overflow {
self.tcx.sess.emit_err(LowerRangeBoundMustBeLessThanOrEqualToUpper {
span,
teach: self.tcx.sess.teach(&error_code!(E0030)).then(|| ()),
teach: self.tcx.sess.teach(&error_code!(E0030)).then_some(()),
});
}
PatKind::Wild

View File

@ -254,7 +254,7 @@ fn apply_statement_effect(
) {
// Compute the place that we are storing to, if any
let destination = match &statement.kind {
StatementKind::Assign(assign) => assign.1.is_safe_to_remove().then(|| assign.0),
StatementKind::Assign(assign) => assign.1.is_safe_to_remove().then_some(assign.0),
StatementKind::SetDiscriminant { place, .. } | StatementKind::Deinit(place) => {
Some(**place)
}

View File

@ -870,7 +870,7 @@ fn parse_ty_bound_modifiers(&mut self) -> PResult<'a, BoundModifiers> {
None
};
let maybe = self.eat(&token::Question).then(|| self.prev_token.span);
let maybe = self.eat(&token::Question).then_some(self.prev_token.span);
Ok(BoundModifiers { maybe, maybe_const })
}

View File

@ -835,7 +835,7 @@ fn integer(&mut self) -> Option<usize> {
);
}
found.then(|| cur)
found.then_some(cur)
}
fn suggest_format(&mut self) {

View File

@ -281,7 +281,7 @@ fn annotate<F>(
self.recurse_with_stability_attrs(
depr.map(|(d, _)| DeprecationEntry::local(d, def_id)),
stab,
inherit_const_stability.yes().then(|| const_stab).flatten(),
inherit_const_stability.yes().then_some(const_stab).flatten(),
visit_children,
);
}

View File

@ -2544,7 +2544,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
}
// Only use this directory if it has a file we can expect to always find.
candidate.join("library/std/src/lib.rs").is_file().then(|| candidate)
candidate.join("library/std/src/lib.rs").is_file().then_some(candidate)
};
let working_dir = std::env::current_dir().unwrap_or_else(|e| {

View File

@ -217,7 +217,7 @@ fn from_env_args_next() -> Option<PathBuf> {
// Look for the target rustlib directory in the suspected sysroot.
let mut rustlib_path = rustc_target::target_rustlib_path(&p, "dummy");
rustlib_path.pop(); // pop off the dummy target.
rustlib_path.exists().then(|| p)
rustlib_path.exists().then_some(p)
}
None => None,
}

View File

@ -809,7 +809,7 @@ pub(crate) fn parse_mir_spanview(slot: &mut Option<MirSpanview>, v: Option<&str>
if v.is_some() {
let mut bool_arg = None;
if parse_opt_bool(&mut bool_arg, v) {
*slot = bool_arg.unwrap().then(|| MirSpanview::Statement);
*slot = bool_arg.unwrap().then_some(MirSpanview::Statement);
return true;
}
}
@ -850,7 +850,7 @@ pub(crate) fn parse_instrument_coverage(
if v.is_some() {
let mut bool_arg = None;
if parse_opt_bool(&mut bool_arg, v) {
*slot = bool_arg.unwrap().then(|| InstrumentCoverage::All);
*slot = bool_arg.unwrap().then_some(InstrumentCoverage::All);
return true;
}
}

View File

@ -320,7 +320,7 @@ pub fn is_crate_root(self) -> bool {
#[inline]
pub fn as_crate_root(self) -> Option<CrateNum> {
self.is_crate_root().then(|| self.krate)
self.is_crate_root().then_some(self.krate)
}
#[inline]

View File

@ -771,7 +771,7 @@ fn suggest_dereferences(
.iter()
.chain([&obligation])
.all(|obligation| self.predicate_may_hold(obligation))
.then(|| steps);
.then_some(steps);
may_hold
})

View File

@ -307,7 +307,7 @@ fn predicate_references_self<'tcx>(
match predicate.kind().skip_binder() {
ty::PredicateKind::Clause(ty::Clause::Trait(ref data)) => {
// In the case of a trait predicate, we can skip the "self" type.
data.trait_ref.substs[1..].iter().any(has_self_ty).then(|| sp)
data.trait_ref.substs[1..].iter().any(has_self_ty).then_some(sp)
}
ty::PredicateKind::Clause(ty::Clause::Projection(ref data)) => {
// And similarly for projections. This should be redundant with
@ -325,7 +325,7 @@ fn predicate_references_self<'tcx>(
//
// This is ALT2 in issue #56288, see that for discussion of the
// possible alternatives.
data.projection_ty.substs[1..].iter().any(has_self_ty).then(|| sp)
data.projection_ty.substs[1..].iter().any(has_self_ty).then_some(sp)
}
ty::PredicateKind::AliasEq(..) => bug!("`AliasEq` not allowed as assumption"),

View File

@ -113,7 +113,7 @@ fn insert(
// Only report the `Self` type if it has at least
// some outer concrete shell; otherwise, it's
// not adding much information.
self_ty: self_ty.has_concrete_skeleton().then(|| self_ty),
self_ty: self_ty.has_concrete_skeleton().then_some(self_ty),
intercrate_ambiguity_causes: overlap.intercrate_ambiguity_causes,
involves_placeholder: overlap.involves_placeholder,
}