Skip to content

Commit 4fdd07f

Browse files
committed
Merge the orphan logic for all alias kinds
1 parent 2304917 commit 4fdd07f

File tree

1 file changed

+23
-29
lines changed
  • compiler/rustc_hir_analysis/src/coherence

1 file changed

+23
-29
lines changed

compiler/rustc_hir_analysis/src/coherence/orphan.rs

+23-29
Original file line numberDiff line numberDiff line change
@@ -200,35 +200,29 @@ fn do_orphan_check_impl<'tcx>(
200200
NonlocalImpl::DisallowOther,
201201
),
202202

203-
// trait Id { type This: ?Sized; }
204-
// impl<T: ?Sized> Id for T {
205-
// type This = T;
206-
// }
207-
// impl<T: ?Sized> AutoTrait for <T as Id>::This {}
208-
ty::Alias(AliasKind::Projection, _) => (
209-
LocalImpl::Disallow { problematic_kind: "associated type" },
210-
NonlocalImpl::DisallowOther,
211-
),
212-
213-
// ```
214-
// struct S<T>(T);
215-
// impl<T: ?Sized> S<T> {
216-
// type This = T;
217-
// }
218-
// impl<T: ?Sized> AutoTrait for S<T>::This {}
219-
// ```
220-
// FIXME(inherent_associated_types): The example code above currently leads to a cycle
221-
ty::Alias(AliasKind::Inherent, _) => (
222-
LocalImpl::Disallow { problematic_kind: "associated type" },
223-
NonlocalImpl::DisallowOther,
224-
),
225-
226-
// type Opaque = impl Trait;
227-
// impl AutoTrait for Opaque {}
228-
ty::Alias(AliasKind::Opaque, _) => (
229-
LocalImpl::Disallow { problematic_kind: "opaque type" },
230-
NonlocalImpl::DisallowOther,
231-
),
203+
ty::Alias(kind, _) => {
204+
let problematic_kind = match kind {
205+
// trait Id { type This: ?Sized; }
206+
// impl<T: ?Sized> Id for T {
207+
// type This = T;
208+
// }
209+
// impl<T: ?Sized> AutoTrait for <T as Id>::This {}
210+
AliasKind::Projection => "associated type",
211+
// type Opaque = impl Trait;
212+
// impl AutoTrait for Opaque {}
213+
AliasKind::Opaque => "opaque type",
214+
// ```
215+
// struct S<T>(T);
216+
// impl<T: ?Sized> S<T> {
217+
// type This = T;
218+
// }
219+
// impl<T: ?Sized> AutoTrait for S<T>::This {}
220+
// ```
221+
// FIXME(inherent_associated_types): The example code above currently leads to a cycle
222+
AliasKind::Inherent => "associated type",
223+
};
224+
(LocalImpl::Disallow { problematic_kind }, NonlocalImpl::DisallowOther)
225+
}
232226

233227
ty::Bool
234228
| ty::Char

0 commit comments

Comments
 (0)