Skip to content

Commit 079a2e8

Browse files
is_{some,ok}_and
1 parent fe3038f commit 079a2e8

File tree

8 files changed

+21
-13
lines changed

8 files changed

+21
-13
lines changed

compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
9191

9292
// This opaque also needs to be from the impl method -- otherwise,
9393
// it's a refinement to a TAIT.
94-
if !tcx.hir().get_if_local(impl_opaque.def_id).map_or(false, |node| {
94+
if !tcx.hir().get_if_local(impl_opaque.def_id).is_some_and(|node| {
9595
matches!(
9696
node.expect_item().expect_opaque_ty().origin,
9797
hir::OpaqueTyOrigin::AsyncFn(def_id) | hir::OpaqueTyOrigin::FnReturn(def_id)

compiler/rustc_lint/src/levels.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
736736
if attr.has_name(sym::doc)
737737
&& attr
738738
.meta_item_list()
739-
.map_or(false, |l| ast::attr::list_contains_name(&l, sym::hidden))
739+
.is_some_and(|l| ast::attr::list_contains_name(&l, sym::hidden))
740740
{
741741
self.insert(LintId::of(MISSING_DOCS), (Level::Allow, LintLevelSource::Default));
742742
continue;

compiler/rustc_middle/src/ty/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ impl<'tcx> TyCtxt<'tcx> {
792792
// If `extern_crate` is `None`, then the crate was injected (e.g., by the allocator).
793793
// Treat that kind of crate as "indirect", since it's an implementation detail of
794794
// the language.
795-
|| self.extern_crate(key.as_def_id()).map_or(false, |e| e.is_direct())
795+
|| self.extern_crate(key.as_def_id()).is_some_and(|e| e.is_direct())
796796
}
797797
}
798798

compiler/rustc_mir_build/src/check_unsafety.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ impl UnsafeOpKind {
552552
) {
553553
let parent_id = tcx.hir().get_parent_item(hir_id);
554554
let parent_owner = tcx.hir().owner(parent_id);
555-
let should_suggest = parent_owner.fn_sig().map_or(false, |sig| sig.header.is_unsafe());
555+
let should_suggest = parent_owner.fn_sig().is_some_and(|sig| sig.header.is_unsafe());
556556
let unsafe_not_inherited_note = if should_suggest {
557557
suggest_unsafe_block.then(|| {
558558
let body_span = tcx.hir().body(parent_owner.body_id().unwrap()).value.span;

compiler/rustc_mir_dataflow/src/value_analysis.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ impl Map {
823823
) {
824824
// Allocate a value slot if it doesn't have one, and the user requested one.
825825
assert!(self.places[place].value_index.is_none());
826-
if tcx.layout_of(param_env.and(ty)).map_or(false, |layout| layout.abi.is_scalar()) {
826+
if tcx.layout_of(param_env.and(ty)).is_ok_and(|layout| layout.abi.is_scalar()) {
827827
self.places[place].value_index = Some(self.value_count.into());
828828
self.value_count += 1;
829829
}

compiler/rustc_resolve/src/late/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1869,7 +1869,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
18691869
),
18701870
};
18711871

1872-
fields.map_or(false, |fields| {
1872+
fields.is_some_and(|fields| {
18731873
fields
18741874
.iter()
18751875
.filter(|vis| !self.r.is_accessible_from(**vis, self.parent_scope.module))

compiler/rustc_trait_selection/src/traits/coherence.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -361,15 +361,23 @@ fn impl_intersection_has_impossible_obligation<'a, 'cx, 'tcx>(
361361
let infcx = selcx.infcx;
362362

363363
obligations.iter().find(|obligation| {
364-
if infcx.next_trait_solver() {
365-
infcx.evaluate_obligation(obligation).map_or(false, |result| !result.may_apply())
364+
let evaluation_result = if infcx.next_trait_solver() {
365+
infcx.evaluate_obligation(obligation)
366366
} else {
367367
// We use `evaluate_root_obligation` to correctly track intercrate
368368
// ambiguity clauses. We cannot use this in the new solver.
369-
selcx.evaluate_root_obligation(obligation).map_or(
370-
false, // Overflow has occurred, and treat the obligation as possibly holding.
371-
|result| !result.may_apply(),
372-
)
369+
selcx.evaluate_root_obligation(obligation)
370+
};
371+
372+
match evaluation_result {
373+
Ok(result) => !result.may_apply(),
374+
// If overflow occurs, we need to conservatively treat the goal as possibly holding,
375+
// since there can be instantiations of this goal that don't overflow and result in
376+
// success. This isn't much of a problem in the old solver, since we treat overflow
377+
// fatally (this still can be encountered: <https://github.com/rust-lang/rust/issues/105231>),
378+
// but in the new solver, this is very important for correctness, since overflow
379+
// *must* be treated as ambiguity for completeness.
380+
Err(_overflow) => false,
373381
}
374382
})
375383
}

compiler/stable_mir/src/mir/mono.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl Instance {
4040

4141
pub fn is_foreign_item(&self) -> bool {
4242
let item = CrateItem::try_from(*self);
43-
item.as_ref().map_or(false, CrateItem::is_foreign_item)
43+
item.as_ref().is_ok_and(CrateItem::is_foreign_item)
4444
}
4545

4646
/// Get the instance type with generic substitutions applied and lifetimes erased.

0 commit comments

Comments
 (0)