@@ -5,7 +5,6 @@ use rustc_data_structures::fx::FxHashSet;
5
5
use rustc_errors:: { struct_span_err, DelayDm } ;
6
6
use rustc_errors:: { Diagnostic , ErrorGuaranteed } ;
7
7
use rustc_hir as hir;
8
- use rustc_middle:: ty:: subst:: GenericArgKind ;
9
8
use rustc_middle:: ty:: subst:: InternalSubsts ;
10
9
use rustc_middle:: ty:: util:: IgnoreRegions ;
11
10
use rustc_middle:: ty:: {
@@ -47,58 +46,6 @@ fn do_orphan_check_impl<'tcx>(
47
46
let sp = tcx. def_span ( def_id) ;
48
47
let tr = impl_. of_trait . as_ref ( ) . unwrap ( ) ;
49
48
50
- // Ensure no opaque types are present in this impl header. See issues #76202 and #86411 for examples,
51
- // and #84660 where it would otherwise allow unsoundness.
52
- if trait_ref. has_opaque_types ( ) {
53
- trace ! ( "{:#?}" , item) ;
54
- // First we find the opaque type in question.
55
- for ty in trait_ref. substs {
56
- for ty in ty. walk ( ) {
57
- let ty:: subst:: GenericArgKind :: Type ( ty) = ty. unpack ( ) else { continue } ;
58
- let ty:: Opaque ( def_id, _) = * ty. kind ( ) else { continue } ;
59
- trace ! ( ?def_id) ;
60
-
61
- // Then we search for mentions of the opaque type's type alias in the HIR
62
- struct SpanFinder < ' tcx > {
63
- sp : Span ,
64
- def_id : DefId ,
65
- tcx : TyCtxt < ' tcx > ,
66
- }
67
- impl < ' v , ' tcx > hir:: intravisit:: Visitor < ' v > for SpanFinder < ' tcx > {
68
- #[ instrument( level = "trace" , skip( self , _id) ) ]
69
- fn visit_path ( & mut self , path : & ' v hir:: Path < ' v > , _id : hir:: HirId ) {
70
- // You can't mention an opaque type directly, so we look for type aliases
71
- if let hir:: def:: Res :: Def ( hir:: def:: DefKind :: TyAlias , def_id) = path. res {
72
- // And check if that type alias's type contains the opaque type we're looking for
73
- for arg in self . tcx . type_of ( def_id) . walk ( ) {
74
- if let GenericArgKind :: Type ( ty) = arg. unpack ( ) {
75
- if let ty:: Opaque ( def_id, _) = * ty. kind ( ) {
76
- if def_id == self . def_id {
77
- // Finally we update the span to the mention of the type alias
78
- self . sp = path. span ;
79
- return ;
80
- }
81
- }
82
- }
83
- }
84
- }
85
- hir:: intravisit:: walk_path ( self , path)
86
- }
87
- }
88
-
89
- let mut visitor = SpanFinder { sp, def_id, tcx } ;
90
- hir:: intravisit:: walk_item ( & mut visitor, item) ;
91
- let reported = tcx
92
- . sess
93
- . struct_span_err ( visitor. sp , "cannot implement trait on type alias impl trait" )
94
- . span_note ( tcx. def_span ( def_id) , "type alias impl trait defined here" )
95
- . emit ( ) ;
96
- return Err ( reported) ;
97
- }
98
- }
99
- span_bug ! ( sp, "opaque type not found, but `has_opaque_types` is set" )
100
- }
101
-
102
49
match traits:: orphan_check ( tcx, item. owner_id . to_def_id ( ) ) {
103
50
Ok ( ( ) ) => { }
104
51
Err ( err) => emit_orphan_check_error (
0 commit comments