diff options
| author | Maybe Waffle <waffle.lapkin@gmail.com> | 2023-05-24 14:19:22 +0000 |
|---|---|---|
| committer | Maybe Waffle <waffle.lapkin@gmail.com> | 2023-05-24 14:20:41 +0000 |
| commit | fb0f74a8c9e8b8f488ec5894d5d314caebf4c662 (patch) | |
| tree | 4cab4cc84de840cc4cce01f3627a979fed59c54c /compiler/rustc_middle/src | |
| parent | 70db8369226c4d2386b25d66a49c8989247934bf (diff) | |
| download | rust-fb0f74a8c9e8b8f488ec5894d5d314caebf4c662.tar.gz rust-fb0f74a8c9e8b8f488ec5894d5d314caebf4c662.zip | |
Use `Option::is_some_and` and `Result::is_ok_and` in the compiler
Diffstat (limited to 'compiler/rustc_middle/src')
| -rw-r--r-- | compiler/rustc_middle/src/hir/map/mod.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/hir/mod.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/middle/privacy.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/middle/stability.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/context.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/generics.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/instance.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/mod.rs | 6 |
8 files changed, 11 insertions, 12 deletions
diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index 3b59df778dc..d1ddc8fc1fd 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -410,7 +410,7 @@ impl<'hir> Map<'hir> { /// item (possibly associated), a closure, or a `hir::AnonConst`. pub fn body_owner(self, BodyId { hir_id }: BodyId) -> HirId { let parent = self.parent_id(hir_id); - assert!(self.find(parent).map_or(false, |n| is_body_owner(n, hir_id)), "{hir_id:?}"); + assert!(self.find(parent).is_some_and(|n| is_body_owner(n, hir_id)), "{hir_id:?}"); parent } diff --git a/compiler/rustc_middle/src/hir/mod.rs b/compiler/rustc_middle/src/hir/mod.rs index ac0b2844177..45a07fdd293 100644 --- a/compiler/rustc_middle/src/hir/mod.rs +++ b/compiler/rustc_middle/src/hir/mod.rs @@ -115,7 +115,7 @@ impl<'tcx> TyCtxt<'tcx> { /// Returns `true` if this is a foreign item (i.e., linked via `extern { ... }`). pub fn is_foreign_item(self, def_id: impl Into<DefId>) -> bool { self.opt_parent(def_id.into()) - .map_or(false, |parent| matches!(self.def_kind(parent), DefKind::ForeignMod)) + .is_some_and(|parent| matches!(self.def_kind(parent), DefKind::ForeignMod)) } } diff --git a/compiler/rustc_middle/src/middle/privacy.rs b/compiler/rustc_middle/src/middle/privacy.rs index aeb6a1601fc..f45cf788dd9 100644 --- a/compiler/rustc_middle/src/middle/privacy.rs +++ b/compiler/rustc_middle/src/middle/privacy.rs @@ -94,8 +94,7 @@ pub struct EffectiveVisibilities<Id = LocalDefId> { impl EffectiveVisibilities { pub fn is_public_at_level(&self, id: LocalDefId, level: Level) -> bool { - self.effective_vis(id) - .map_or(false, |effective_vis| effective_vis.is_public_at_level(level)) + self.effective_vis(id).is_some_and(|effective_vis| effective_vis.is_public_at_level(level)) } /// See `Level::Reachable`. diff --git a/compiler/rustc_middle/src/middle/stability.rs b/compiler/rustc_middle/src/middle/stability.rs index 89fc864319d..6354c0aabde 100644 --- a/compiler/rustc_middle/src/middle/stability.rs +++ b/compiler/rustc_middle/src/middle/stability.rs @@ -375,7 +375,7 @@ impl<'tcx> TyCtxt<'tcx> { let parent_def_id = self.hir().get_parent_item(id); let skip = self .lookup_deprecation_entry(parent_def_id.to_def_id()) - .map_or(false, |parent_depr| parent_depr.same_origin(&depr_entry)); + .is_some_and(|parent_depr| parent_depr.same_origin(&depr_entry)); // #[deprecated] doesn't emit a notice if we're not on the // topmost deprecation. For example, if a struct is deprecated, diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 5393dba8c2e..6c931a24462 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -2341,7 +2341,7 @@ impl<'tcx> TyCtxt<'tcx> { } pub fn is_late_bound(self, id: HirId) -> bool { - self.is_late_bound_map(id.owner).map_or(false, |set| set.contains(&id.local_id)) + self.is_late_bound_map(id.owner).is_some_and(|set| set.contains(&id.local_id)) } pub fn late_bound_vars(self, id: HirId) -> &'tcx List<ty::BoundVariableKind> { @@ -2474,7 +2474,7 @@ pub fn provide(providers: &mut Providers) { |tcx, LocalCrate| attr::contains_name(tcx.hir().krate_attrs(), sym::compiler_builtins); providers.has_panic_handler = |tcx, LocalCrate| { // We want to check if the panic handler was defined in this crate - tcx.lang_items().panic_impl().map_or(false, |did| did.is_local()) + tcx.lang_items().panic_impl().is_some_and(|did| did.is_local()) }; providers.source_span = |tcx, def_id| tcx.untracked.source_span.get(def_id).unwrap_or(DUMMY_SP); } diff --git a/compiler/rustc_middle/src/ty/generics.rs b/compiler/rustc_middle/src/ty/generics.rs index 99174bae3f6..b0ffe78299d 100644 --- a/compiler/rustc_middle/src/ty/generics.rs +++ b/compiler/rustc_middle/src/ty/generics.rs @@ -298,7 +298,7 @@ impl<'tcx> Generics { .iter() .rev() .take_while(|param| { - param.default_value(tcx).map_or(false, |default| { + param.default_value(tcx).is_some_and(|default| { default.subst(tcx, substs) == substs[param.index as usize] }) }) diff --git a/compiler/rustc_middle/src/ty/instance.rs b/compiler/rustc_middle/src/ty/instance.rs index 8c69894f5ba..e641d1ef1be 100644 --- a/compiler/rustc_middle/src/ty/instance.rs +++ b/compiler/rustc_middle/src/ty/instance.rs @@ -659,7 +659,7 @@ fn polymorphize<'tcx>( } else { None }; - let has_upvars = upvars_ty.map_or(false, |ty| !ty.tuple_fields().is_empty()); + let has_upvars = upvars_ty.is_some_and(|ty| !ty.tuple_fields().is_empty()); debug!("polymorphize: upvars_ty={:?} has_upvars={:?}", upvars_ty, has_upvars); struct PolymorphizationFolder<'tcx> { diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index c9cd644fab0..c51548501ef 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -2220,8 +2220,8 @@ impl<'tcx> TyCtxt<'tcx> { let impl_trait_ref2 = self.impl_trait_ref(def_id2); // If either trait impl references an error, they're allowed to overlap, // as one of them essentially doesn't exist. - if impl_trait_ref1.map_or(false, |tr| tr.subst_identity().references_error()) - || impl_trait_ref2.map_or(false, |tr| tr.subst_identity().references_error()) + if impl_trait_ref1.is_some_and(|tr| tr.subst_identity().references_error()) + || impl_trait_ref2.is_some_and(|tr| tr.subst_identity().references_error()) { return Some(ImplOverlapKind::Permitted { marker: false }); } @@ -2242,7 +2242,7 @@ impl<'tcx> TyCtxt<'tcx> { let is_marker_overlap = { let is_marker_impl = |trait_ref: Option<EarlyBinder<TraitRef<'_>>>| -> bool { - trait_ref.map_or(false, |tr| self.trait_def(tr.skip_binder().def_id).is_marker) + trait_ref.is_some_and(|tr| self.trait_def(tr.skip_binder().def_id).is_marker) }; is_marker_impl(impl_trait_ref1) && is_marker_impl(impl_trait_ref2) }; |
