Skip to content

Commit b0c97dc

Browse files
authored
Unrolled build for rust-lang#126328
Rollup merge of rust-lang#126328 - RalfJung:is_none_or, r=workingjubilee Add Option::is_none_or ACP: rust-lang/libs-team#212
2 parents f6b4b71 + 4c208ac commit b0c97dc

File tree

14 files changed

+41
-11
lines changed

14 files changed

+41
-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
@@ -6,6 +6,7 @@
66
#![feature(box_patterns)]
77
#![feature(decl_macro)]
88
#![feature(if_let_guard)]
9+
#![feature(is_none_or)]
910
#![feature(let_chains)]
1011
#![feature(never_type)]
1112
#![feature(rustdoc_internals)]

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
@@ -1557,7 +1557,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15571557

15581558
// If the length is 0, we don't create any elements, so we don't copy any. If the length is 1, we
15591559
// don't copy that one element, we move it. Only check for Copy if the length is larger.
1560-
if count.try_eval_target_usize(tcx, self.param_env).map_or(true, |len| len > 1) {
1560+
if count.try_eval_target_usize(tcx, self.param_env).is_none_or(|len| len > 1) {
15611561
let lang_item = self.tcx.require_lang_item(LangItem::Copy, None);
15621562
let code = traits::ObligationCauseCode::RepeatElementCopy {
15631563
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
@@ -4,6 +4,7 @@
44
#![feature(box_patterns)]
55
#![feature(control_flow_enum)]
66
#![feature(if_let_guard)]
7+
#![feature(is_none_or)]
78
#![feature(let_chains)]
89
#![feature(never_type)]
910
#![feature(try_blocks)]

library/core/src/option.rs

+26
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,32 @@ impl<T> Option<T> {
654654
!self.is_some()
655655
}
656656

657+
/// Returns `true` if the option is a [`None`] or the value inside of it matches a predicate.
658+
///
659+
/// # Examples
660+
///
661+
/// ```
662+
/// #![feature(is_none_or)]
663+
///
664+
/// let x: Option<u32> = Some(2);
665+
/// assert_eq!(x.is_none_or(|x| x > 1), true);
666+
///
667+
/// let x: Option<u32> = Some(0);
668+
/// assert_eq!(x.is_none_or(|x| x > 1), false);
669+
///
670+
/// let x: Option<u32> = None;
671+
/// assert_eq!(x.is_none_or(|x| x > 1), true);
672+
/// ```
673+
#[must_use]
674+
#[inline]
675+
#[unstable(feature = "is_none_or", issue = "none")]
676+
pub fn is_none_or(self, f: impl FnOnce(T) -> bool) -> bool {
677+
match self {
678+
None => true,
679+
Some(x) => f(x),
680+
}
681+
}
682+
657683
/////////////////////////////////////////////////////////////////////////
658684
// Adapter for working with references
659685
/////////////////////////////////////////////////////////////////////////

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
}

src/tools/rust-analyzer/crates/hir-ty/src/display.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1387,6 +1387,7 @@ fn generic_args_sans_defaults<'ga>(
13871387
}
13881388
// otherwise, if the arg is equal to the param default, hide it (unless the
13891389
// default is an error which can happen for the trait Self type)
1390+
#[allow(unstable_name_collisions)]
13901391
default_parameters.get(i).is_none_or(|default_parameter| {
13911392
// !is_err(default_parameter.skip_binders())
13921393
// &&

0 commit comments

Comments
 (0)