Merge the orphan logic for all alias kinds

This commit is contained in:
Oli Scherer 2023-03-13 13:33:39 +00:00
parent 2304917aad
commit 4fdd07fe88

View file

@ -200,16 +200,17 @@ fn do_orphan_check_impl<'tcx>(
NonlocalImpl::DisallowOther, NonlocalImpl::DisallowOther,
), ),
ty::Alias(kind, _) => {
let problematic_kind = match kind {
// trait Id { type This: ?Sized; } // trait Id { type This: ?Sized; }
// impl<T: ?Sized> Id for T { // impl<T: ?Sized> Id for T {
// type This = T; // type This = T;
// } // }
// impl<T: ?Sized> AutoTrait for <T as Id>::This {} // impl<T: ?Sized> AutoTrait for <T as Id>::This {}
ty::Alias(AliasKind::Projection, _) => ( AliasKind::Projection => "associated type",
LocalImpl::Disallow { problematic_kind: "associated type" }, // type Opaque = impl Trait;
NonlocalImpl::DisallowOther, // impl AutoTrait for Opaque {}
), AliasKind::Opaque => "opaque type",
// ``` // ```
// struct S<T>(T); // struct S<T>(T);
// impl<T: ?Sized> S<T> { // impl<T: ?Sized> S<T> {
@ -218,17 +219,10 @@ fn do_orphan_check_impl<'tcx>(
// impl<T: ?Sized> AutoTrait for S<T>::This {} // impl<T: ?Sized> AutoTrait for S<T>::This {}
// ``` // ```
// FIXME(inherent_associated_types): The example code above currently leads to a cycle // FIXME(inherent_associated_types): The example code above currently leads to a cycle
ty::Alias(AliasKind::Inherent, _) => ( AliasKind::Inherent => "associated type",
LocalImpl::Disallow { problematic_kind: "associated type" }, };
NonlocalImpl::DisallowOther, (LocalImpl::Disallow { problematic_kind }, NonlocalImpl::DisallowOther)
), }
// type Opaque = impl Trait;
// impl AutoTrait for Opaque {}
ty::Alias(AliasKind::Opaque, _) => (
LocalImpl::Disallow { problematic_kind: "opaque type" },
NonlocalImpl::DisallowOther,
),
ty::Bool ty::Bool
| ty::Char | ty::Char