Unwrap an Option that can only be Some, as inherent impls can't overlap

This commit is contained in:
Oli Scherer 2024-02-10 22:04:46 +00:00
parent 90a43f1406
commit a9e0e968be

View file

@ -1590,12 +1590,12 @@ pub fn impls_are_allowed_to_overlap(
def_id1: DefId, def_id1: DefId,
def_id2: DefId, def_id2: DefId,
) -> Option<ImplOverlapKind> { ) -> Option<ImplOverlapKind> {
let impl_trait_ref1 = self.impl_trait_ref(def_id1); let impl_trait_ref1 = self.impl_trait_ref(def_id1).unwrap();
let impl_trait_ref2 = self.impl_trait_ref(def_id2); let impl_trait_ref2 = self.impl_trait_ref(def_id2).unwrap();
// If either trait impl references an error, they're allowed to overlap, // If either trait impl references an error, they're allowed to overlap,
// as one of them essentially doesn't exist. // as one of them essentially doesn't exist.
if impl_trait_ref1.is_some_and(|tr| tr.instantiate_identity().references_error()) if impl_trait_ref1.instantiate_identity().references_error()
|| impl_trait_ref2.is_some_and(|tr| tr.instantiate_identity().references_error()) || impl_trait_ref2.instantiate_identity().references_error()
{ {
return Some(ImplOverlapKind::Permitted { marker: false }); return Some(ImplOverlapKind::Permitted { marker: false });
} }
@ -1615,8 +1615,8 @@ pub fn impls_are_allowed_to_overlap(
}; };
let is_marker_overlap = { let is_marker_overlap = {
let is_marker_impl = |trait_ref: Option<EarlyBinder<TraitRef<'_>>>| -> bool { let is_marker_impl = |trait_ref: EarlyBinder<TraitRef<'_>>| -> bool {
trait_ref.is_some_and(|tr| self.trait_def(tr.skip_binder().def_id).is_marker) self.trait_def(trait_ref.skip_binder().def_id).is_marker
}; };
is_marker_impl(impl_trait_ref1) && is_marker_impl(impl_trait_ref2) is_marker_impl(impl_trait_ref1) && is_marker_impl(impl_trait_ref2)
}; };