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 @@ impl<'a> AstValidator<'a> {
self.session.emit_err(InvalidVisibility { self.session.emit_err(InvalidVisibility {
span: vis.span, span: vis.span,
implied: vis.kind.is_pub().then(|| vis.span), implied: vis.kind.is_pub().then_some(vis.span),
note, note,
}); });
} }

View File

@ -1186,7 +1186,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
return None; return None;
}; };
debug!("checking call args for uses of inner_param: {:?}", args); 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 { }) else {
debug!("no uses of inner_param found as a by-move call arg"); debug!("no uses of inner_param found as a by-move call arg");
return; return;

View File

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

View File

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

View File

@ -2024,7 +2024,7 @@ fn linker_with_args<'a>(
.native_libraries .native_libraries
.iter() .iter()
.filter_map(|(cnum, libraries)| { .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(); .flatten();
for (raw_dylib_name, raw_dylib_imports) in for (raw_dylib_name, raw_dylib_imports) in

View File

@ -255,7 +255,7 @@ impl<'a> StripUnconfigured<'a> {
fn configure_krate_attrs(&self, mut attrs: ast::AttrVec) -> Option<ast::AttrVec> { fn configure_krate_attrs(&self, mut attrs: ast::AttrVec) -> Option<ast::AttrVec> {
attrs.flat_map_in_place(|attr| self.process_cfg_attr(attr)); 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`. /// Performs cfg-expansion on `stream`, producing a new `AttrTokenStream`.

View File

@ -204,7 +204,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local()); let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
match tcx.hir().find(hir_id) { match tcx.hir().find(hir_id) {
Some(Node::Item(hir::Item { kind: hir::ItemKind::Fn(_, generics, _), .. })) => { 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"); span_bug!(tcx.def_span(def_id), "main has a non-function type");

View File

@ -1046,7 +1046,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.param_env, self.param_env,
) )
.may_apply() .may_apply()
.then(|| deref_ty) .then_some(deref_ty)
}) })
} }

View File

@ -2308,7 +2308,8 @@ impl EarlyLintPass for IncompleteFeatures {
.for_each(|(&name, &span)| { .for_each(|(&name, &span)| {
let note = rustc_feature::find_feature_issue(name, GateIssue::Language) let note = rustc_feature::find_feature_issue(name, GateIssue::Language)
.map(|n| BuiltinIncompleteFeaturesNote { n }); .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( cx.emit_spanned_lint(
INCOMPLETE_FEATURES, INCOMPLETE_FEATURES,
span, span,

View File

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

View File

@ -414,7 +414,7 @@ impl<'tcx> Body<'tcx> {
(self.arg_count + 1..self.local_decls.len()).filter_map(move |index| { (self.arg_count + 1..self.local_decls.len()).filter_map(move |index| {
let local = Local::new(index); let local = Local::new(index);
let decl = &self.local_decls[local]; 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 @@ impl<'tcx> Instance<'tcx> {
/// this function returns `None`, then the MIR body does not require substitution during /// this function returns `None`, then the MIR body does not require substitution during
/// codegen. /// codegen.
fn substs_for_mir_body(&self) -> Option<SubstsRef<'tcx>> { 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 pub fn subst_mir<T>(&self, tcx: TyCtxt<'tcx>, v: &T) -> T

View File

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

View File

@ -254,7 +254,7 @@ impl<'a, 'tcx> Analysis<'tcx> for MaybeTransitiveLiveLocals<'a> {
) { ) {
// Compute the place that we are storing to, if any // Compute the place that we are storing to, if any
let destination = match &statement.kind { 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) => { StatementKind::SetDiscriminant { place, .. } | StatementKind::Deinit(place) => {
Some(**place) Some(**place)
} }

View File

@ -870,7 +870,7 @@ impl<'a> Parser<'a> {
None 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 }) Ok(BoundModifiers { maybe, maybe_const })
} }

View File

@ -835,7 +835,7 @@ impl<'a> Parser<'a> {
); );
} }
found.then(|| cur) found.then_some(cur)
} }
fn suggest_format(&mut self) { fn suggest_format(&mut self) {

View File

@ -281,7 +281,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
self.recurse_with_stability_attrs( self.recurse_with_stability_attrs(
depr.map(|(d, _)| DeprecationEntry::local(d, def_id)), depr.map(|(d, _)| DeprecationEntry::local(d, def_id)),
stab, stab,
inherit_const_stability.yes().then(|| const_stab).flatten(), inherit_const_stability.yes().then_some(const_stab).flatten(),
visit_children, 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. // 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| { let working_dir = std::env::current_dir().unwrap_or_else(|e| {

View File

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

View File

@ -809,7 +809,7 @@ mod parse {
if v.is_some() { if v.is_some() {
let mut bool_arg = None; let mut bool_arg = None;
if parse_opt_bool(&mut bool_arg, v) { 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; return true;
} }
} }
@ -850,7 +850,7 @@ mod parse {
if v.is_some() { if v.is_some() {
let mut bool_arg = None; let mut bool_arg = None;
if parse_opt_bool(&mut bool_arg, v) { 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; return true;
} }
} }

View File

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

View File

@ -771,7 +771,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
.iter() .iter()
.chain([&obligation]) .chain([&obligation])
.all(|obligation| self.predicate_may_hold(obligation)) .all(|obligation| self.predicate_may_hold(obligation))
.then(|| steps); .then_some(steps);
may_hold may_hold
}) })

View File

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

View File

@ -113,7 +113,7 @@ impl<'tcx> ChildrenExt<'tcx> for Children {
// Only report the `Self` type if it has at least // Only report the `Self` type if it has at least
// some outer concrete shell; otherwise, it's // some outer concrete shell; otherwise, it's
// not adding much information. // 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, intercrate_ambiguity_causes: overlap.intercrate_ambiguity_causes,
involves_placeholder: overlap.involves_placeholder, involves_placeholder: overlap.involves_placeholder,
} }