Skip to content

Commit d22bb5e

Browse files
committed
use is_none_or in some places in the compiler
1 parent 8e46c55 commit d22bb5e

File tree

12 files changed

+14
-11
lines changed

12 files changed

+14
-11
lines changed

compiler/rustc_const_eval/src/interpret/eval_context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
10571057

10581058
ty::Str | ty::Slice(_) | ty::Dynamic(_, _, ty::Dyn) | ty::Foreign(..) => false,
10591059

1060-
ty::Tuple(tys) => tys.last().iter().all(|ty| is_very_trivially_sized(**ty)),
1060+
ty::Tuple(tys) => tys.last().is_none_or(|ty| is_very_trivially_sized(*ty)),
10611061

10621062
ty::Pat(ty, ..) => is_very_trivially_sized(*ty),
10631063

compiler/rustc_const_eval/src/interpret/memory.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
446446
let (alloc_size, _alloc_align, ret_val) = alloc_size(alloc_id, offset, prov)?;
447447
// Test bounds.
448448
// It is sufficient to check this for the end pointer. Also check for overflow!
449-
if offset.checked_add(size, &self.tcx).map_or(true, |end| end > alloc_size) {
449+
if offset.checked_add(size, &self.tcx).is_none_or(|end| end > alloc_size) {
450450
throw_ub!(PointerOutOfBounds {
451451
alloc_id,
452452
alloc_size,

compiler/rustc_const_eval/src/interpret/projection.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ where
300300
) -> InterpResult<'tcx, P> {
301301
let len = base.len(self)?; // also asserts that we have a type where this makes sense
302302
let actual_to = if from_end {
303-
if from.checked_add(to).map_or(true, |to| to > len) {
303+
if from.checked_add(to).is_none_or(|to| to > len) {
304304
// This can only be reached in ConstProp and non-rustc-MIR.
305305
throw_ub!(BoundsCheckFailed { len: len, index: from.saturating_add(to) });
306306
}

compiler/rustc_const_eval/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#![feature(try_blocks)]
1414
#![feature(yeet_expr)]
1515
#![feature(if_let_guard)]
16+
#![feature(is_none_or)]
1617

1718
pub mod check_consts;
1819
pub mod const_eval;

compiler/rustc_hir_typeck/src/_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
234234
let ret_ty = ret_coercion.borrow().expected_ty();
235235
let ret_ty = self.infcx.shallow_resolve(ret_ty);
236236
self.can_coerce(arm_ty, ret_ty)
237-
&& prior_arm.map_or(true, |(_, ty, _)| self.can_coerce(ty, ret_ty))
237+
&& prior_arm.is_none_or(|(_, ty, _)| self.can_coerce(ty, ret_ty))
238238
// The match arms need to unify for the case of `impl Trait`.
239239
&& !matches!(ret_ty.kind(), ty::Alias(ty::Opaque, ..))
240240
}

compiler/rustc_hir_typeck/src/coercion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
913913
if self
914914
.tcx
915915
.upvars_mentioned(closure_def_id_a.expect_local())
916-
.map_or(true, |u| u.is_empty()) =>
916+
.is_none_or(|u| u.is_empty()) =>
917917
{
918918
// We coerce the closure, which has fn type
919919
// `extern "rust-call" fn((arg0,arg1,...)) -> _`

compiler/rustc_hir_typeck/src/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1560,7 +1560,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15601560

15611561
// If the length is 0, we don't create any elements, so we don't copy any. If the length is 1, we
15621562
// don't copy that one element, we move it. Only check for Copy if the length is larger.
1563-
if count.try_eval_target_usize(tcx, self.param_env).map_or(true, |len| len > 1) {
1563+
if count.try_eval_target_usize(tcx, self.param_env).is_none_or(|len| len > 1) {
15641564
let lang_item = self.tcx.require_lang_item(LangItem::Copy, None);
15651565
let code = traits::ObligationCauseCode::RepeatElementCopy {
15661566
is_constable,

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2240,7 +2240,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
22402240
for (idx, (generic_param, param)) in
22412241
params_with_generics.iter().enumerate().filter(|(idx, _)| {
22422242
check_for_matched_generics
2243-
|| expected_idx.map_or(true, |expected_idx| expected_idx == *idx)
2243+
|| expected_idx.is_none_or(|expected_idx| expected_idx == *idx)
22442244
})
22452245
{
22462246
let Some(generic_param) = generic_param else {

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
440440
};
441441
// Given `Result<_, E>`, check our expected ty is `Result<_, &E>` for
442442
// `as_ref` and `as_deref` compatibility.
443-
let error_tys_equate_as_ref = error_tys.map_or(true, |(found, expected)| {
443+
let error_tys_equate_as_ref = error_tys.is_none_or(|(found, expected)| {
444444
self.can_eq(
445445
self.param_env,
446446
Ty::new_imm_ref(self.tcx, self.tcx.lifetimes.re_erased, found),
@@ -492,7 +492,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
492492
&& Some(adt.did()) == self.tcx.lang_items().string()
493493
&& peeled.is_str()
494494
// `Result::map`, conversely, does not take ref of the error type.
495-
&& error_tys.map_or(true, |(found, expected)| {
495+
&& error_tys.is_none_or(|(found, expected)| {
496496
self.can_eq(self.param_env, found, expected)
497497
})
498498
{

compiler/rustc_hir_typeck/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#![feature(never_type)]
77
#![feature(box_patterns)]
88
#![feature(control_flow_enum)]
9+
#![feature(is_none_or)]
910

1011
#[macro_use]
1112
extern crate tracing;

src/tools/miri/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#![feature(lint_reasons)]
1414
#![feature(trait_upcasting)]
1515
#![feature(strict_overflow_ops)]
16+
#![feature(is_none_or)]
1617
// Configure clippy and other lints
1718
#![allow(
1819
clippy::collapsible_else_if,

src/tools/miri/src/shims/foreign_items.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -396,12 +396,12 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
396396
// If the newly promised alignment is bigger than the native alignment of this
397397
// allocation, and bigger than the previously promised alignment, then set it.
398398
if align > alloc_align
399-
&& !this
399+
&& this
400400
.machine
401401
.symbolic_alignment
402402
.get_mut()
403403
.get(&alloc_id)
404-
.is_some_and(|&(_, old_align)| align <= old_align)
404+
.is_none_or(|&(_, old_align)| align > old_align)
405405
{
406406
this.machine.symbolic_alignment.get_mut().insert(alloc_id, (offset, align));
407407
}

0 commit comments

Comments
 (0)