Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 307799a

Browse files
committed
Use is_some_and/is_ok_and in less obvious spots
1 parent fb0f74a commit 307799a

File tree

19 files changed

+53
-88
lines changed

19 files changed

+53
-88
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ impl<'a> AstValidator<'a> {
348348
let source_map = self.session.source_map();
349349
let end = source_map.end_point(sp);
350350

351-
if source_map.span_to_snippet(end).map(|s| s == ";").unwrap_or(false) {
351+
if source_map.span_to_snippet(end).is_ok_and(|s| s == ";") {
352352
end
353353
} else {
354354
sp.shrink_to_hi()

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,9 @@ impl<'tcx> BorrowExplanation<'tcx> {
224224
if info.tail_result_is_ignored {
225225
// #85581: If the first mutable borrow's scope contains
226226
// the second borrow, this suggestion isn't helpful.
227-
if !multiple_borrow_span
228-
.map(|(old, new)| {
229-
old.to(info.span.shrink_to_hi()).contains(new)
230-
})
231-
.unwrap_or(false)
232-
{
227+
if !multiple_borrow_span.is_some_and(|(old, new)| {
228+
old.to(info.span.shrink_to_hi()).contains(new)
229+
}) {
233230
err.span_suggestion_verbose(
234231
info.span.shrink_to_hi(),
235232
"consider adding semicolon after the expression so its \

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
289289
.body
290290
.local_decls
291291
.get(local)
292-
.map(|l| mut_borrow_of_mutable_ref(l, self.local_names[local]))
293-
.unwrap_or(false) =>
292+
.is_some_and(|l| mut_borrow_of_mutable_ref(l, self.local_names[local])) =>
294293
{
295294
let decl = &self.body.local_decls[local];
296295
err.span_label(span, format!("cannot {act}"));

compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ impl OutlivesSuggestionBuilder {
125125
|(r, _)| {
126126
self.constraints_to_add
127127
.get(r)
128-
.map(|r_outlived| r_outlived.as_slice().contains(fr))
129-
.unwrap_or(false)
128+
.is_some_and(|r_outlived| r_outlived.as_slice().contains(fr))
130129
},
131130
);
132131

compiler/rustc_codegen_cranelift/src/abi/mod.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -432,11 +432,9 @@ pub(crate) fn codegen_terminator_call<'tcx>(
432432
let is_cold = if fn_sig.abi() == Abi::RustCold {
433433
true
434434
} else {
435-
instance
436-
.map(|inst| {
437-
fx.tcx.codegen_fn_attrs(inst.def_id()).flags.contains(CodegenFnAttrFlags::COLD)
438-
})
439-
.unwrap_or(false)
435+
instance.is_some_and(|inst| {
436+
fx.tcx.codegen_fn_attrs(inst.def_id()).flags.contains(CodegenFnAttrFlags::COLD)
437+
})
440438
};
441439
if is_cold {
442440
fx.bcx.set_cold_block(fx.bcx.current_block().unwrap());
@@ -470,7 +468,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
470468
};
471469

472470
// Pass the caller location for `#[track_caller]`.
473-
if instance.map(|inst| inst.def.requires_caller_location(fx.tcx)).unwrap_or(false) {
471+
if instance.is_some_and(|inst| inst.def.requires_caller_location(fx.tcx)) {
474472
let caller_location = fx.get_caller_location(source_info);
475473
args.push(CallArgument { value: caller_location, is_owned: false });
476474
}

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -630,11 +630,11 @@ fn codegen_stmt<'tcx>(
630630
let to_ty = fx.monomorphize(to_ty);
631631

632632
fn is_fat_ptr<'tcx>(fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool {
633-
ty.builtin_deref(true)
634-
.map(|ty::TypeAndMut { ty: pointee_ty, mutbl: _ }| {
633+
ty.builtin_deref(true).is_some_and(
634+
|ty::TypeAndMut { ty: pointee_ty, mutbl: _ }| {
635635
has_ptr_meta(fx.tcx, pointee_ty)
636-
})
637-
.unwrap_or(false)
636+
},
637+
)
638638
}
639639

640640
if is_fat_ptr(fx, from_ty) {

compiler/rustc_codegen_llvm/src/mono_item.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ impl CodegenCx<'_, '_> {
125125

126126
// Thread-local variables generally don't support copy relocations.
127127
let is_thread_local_var = llvm::LLVMIsAGlobalVariable(llval)
128-
.map(|v| llvm::LLVMIsThreadLocal(v) == llvm::True)
129-
.unwrap_or(false);
128+
.is_some_and(|v| llvm::LLVMIsThreadLocal(v) == llvm::True);
130129
if is_thread_local_var {
131130
return false;
132131
}

compiler/rustc_const_eval/src/transform/check_consts/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
944944
tcx.features().declared_lib_features.iter().any(|&(sym, _)| sym == gate)
945945
};
946946
let feature_gate_declared = gate_declared(gate);
947-
let implied_gate_declared = implied_by.map(gate_declared).unwrap_or(false);
947+
let implied_gate_declared = implied_by.is_some_and(gate_declared);
948948
if !feature_gate_declared && !implied_gate_declared {
949949
self.check_op(ops::FnCallUnstable(callee, Some(gate)));
950950
return;

compiler/rustc_errors/src/emitter.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,11 @@ pub trait Emitter: Translate {
285285
format!(
286286
"help: {}{}: `{}`",
287287
&msg,
288-
if self
289-
.source_map()
290-
.map(|sm| is_case_difference(
291-
sm,
292-
substitution,
293-
sugg.substitutions[0].parts[0].span,
294-
))
295-
.unwrap_or(false)
296-
{
288+
if self.source_map().is_some_and(|sm| is_case_difference(
289+
sm,
290+
substitution,
291+
sugg.substitutions[0].parts[0].span,
292+
)) {
297293
" (notice the capitalization)"
298294
} else {
299295
""

compiler/rustc_feature/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl UnstableFeatures {
8484
pub fn from_environment(krate: Option<&str>) -> Self {
8585
// `true` if this is a feature-staged build, i.e., on the beta or stable channel.
8686
let disable_unstable_features =
87-
option_env!("CFG_DISABLE_UNSTABLE_FEATURES").map(|s| s != "0").unwrap_or(false);
87+
option_env!("CFG_DISABLE_UNSTABLE_FEATURES").is_some_and(|s| s != "0");
8888
// Returns whether `krate` should be counted as unstable
8989
let is_unstable_crate =
9090
|var: &str| krate.is_some_and(|name| var.split(',').any(|new_krate| new_krate == name));

0 commit comments

Comments
 (0)