@@ -7,6 +7,7 @@ use rustc_errors::ErrorGuaranteed;
7
7
use rustc_hir as hir;
8
8
use rustc_index:: bit_set:: GrowableBitSet ;
9
9
use rustc_infer:: infer:: TyCtxtInferExt ;
10
+ use rustc_middle:: ty:: subst:: GenericArgKind ;
10
11
use rustc_middle:: ty:: subst:: { GenericArg , InternalSubsts } ;
11
12
use rustc_middle:: ty:: { self , ImplPolarity , Ty , TyCtxt , TypeFoldable , TypeVisitor } ;
12
13
use rustc_session:: lint;
@@ -144,13 +145,41 @@ fn orphan_check_impl(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), ErrorGua
144
145
// Ensure no opaque types are present in this impl header. See issues #76202 and #86411 for examples,
145
146
// and #84660 where it would otherwise allow unsoundness.
146
147
if trait_ref. has_opaque_types ( ) {
148
+ trace ! ( "{:#?}" , item) ;
147
149
for ty in trait_ref. substs {
148
150
for ty in ty. walk ( ) {
149
151
let ty:: subst:: GenericArgKind :: Type ( ty) = ty. unpack ( ) else { continue } ;
150
- let ty:: Opaque ( def_id, _) = ty. kind ( ) else { continue } ;
152
+ let ty:: Opaque ( def_id, _) = * ty. kind ( ) else { continue } ;
153
+ trace ! ( ?def_id) ;
154
+ struct SpanFinder < ' tcx > {
155
+ sp : Span ,
156
+ def_id : DefId ,
157
+ tcx : TyCtxt < ' tcx > ,
158
+ }
159
+ impl < ' v , ' tcx > hir:: intravisit:: Visitor < ' v > for SpanFinder < ' tcx > {
160
+ #[ instrument( level = "trace" , skip( self , _id) ) ]
161
+ fn visit_path ( & mut self , path : & ' v hir:: Path < ' v > , _id : hir:: HirId ) {
162
+ if let hir:: def:: Res :: Def ( hir:: def:: DefKind :: TyAlias , def_id) = path. res {
163
+ for arg in self . tcx . type_of ( def_id) . walk ( ) {
164
+ if let GenericArgKind :: Type ( ty) = arg. unpack ( ) {
165
+ if let ty:: Opaque ( def_id, _) = * ty. kind ( ) {
166
+ if def_id == self . def_id {
167
+ self . sp = path. span ;
168
+ return ;
169
+ }
170
+ }
171
+ }
172
+ }
173
+ }
174
+ hir:: intravisit:: walk_path ( self , path)
175
+ }
176
+ }
177
+
178
+ let mut visitor = SpanFinder { sp, def_id, tcx } ;
179
+ hir:: intravisit:: walk_item ( & mut visitor, item) ;
151
180
let reported = tcx
152
181
. sess
153
- . struct_span_err ( sp, "cannot implement trait on type alias impl trait" )
182
+ . struct_span_err ( visitor . sp , "cannot implement trait on type alias impl trait" )
154
183
. span_note ( tcx. def_span ( def_id) , "type alias impl trait defined here" )
155
184
. emit ( ) ;
156
185
return Err ( reported) ;
0 commit comments