4
4
use crate :: errors;
5
5
use rustc_errors:: ErrorGuaranteed ;
6
6
use rustc_hir as hir;
7
- use rustc_middle:: ty:: { self , AliasKind , Ty , TyCtxt , TypeVisitableExt } ;
7
+ use rustc_middle:: ty:: { self , AliasKind , TyCtxt , TypeVisitableExt } ;
8
8
use rustc_span:: def_id:: LocalDefId ;
9
9
use rustc_span:: Span ;
10
10
use rustc_trait_selection:: traits:: { self , IsFirstInputType } ;
@@ -283,8 +283,14 @@ fn emit_orphan_check_error<'tcx>(
283
283
let self_ty = trait_ref. self_ty ( ) ;
284
284
Err ( match err {
285
285
traits:: OrphanCheckErr :: NonLocalInputType ( tys) => {
286
- let ( mut opaque, mut foreign, mut name, mut pointer, mut ty_diag) =
287
- ( Vec :: new ( ) , Vec :: new ( ) , Vec :: new ( ) , Vec :: new ( ) , Vec :: new ( ) ) ;
286
+ // FIXME: Someone needs to just turn these into `Subdiag`s and attach
287
+ // them to the `Diag` after creating the error.
288
+ let mut opaque = vec ! [ ] ;
289
+ let mut foreign = vec ! [ ] ;
290
+ let mut name = vec ! [ ] ;
291
+ let mut pointer = vec ! [ ] ;
292
+ let mut ty_diag = vec ! [ ] ;
293
+ let mut adt = vec ! [ ] ;
288
294
let mut sugg = None ;
289
295
for & ( mut ty, is_target_ty) in & tys {
290
296
let span = if matches ! ( is_target_ty, IsFirstInputType :: Yes ) {
@@ -296,15 +302,6 @@ fn emit_orphan_check_error<'tcx>(
296
302
} ;
297
303
298
304
ty = tcx. erase_regions ( ty) ;
299
- ty = match ty. kind ( ) {
300
- // Remove the type arguments from the output, as they are not relevant.
301
- // You can think of this as the reverse of `resolve_vars_if_possible`.
302
- // That way if we had `Vec<MyType>`, we will properly attribute the
303
- // problem to `Vec<T>` and avoid confusing the user if they were to see
304
- // `MyType` in the error.
305
- ty:: Adt ( def, _) => Ty :: new_adt ( tcx, * def, ty:: List :: empty ( ) ) ,
306
- _ => ty,
307
- } ;
308
305
309
306
fn push_to_foreign_or_name < ' tcx > (
310
307
is_foreign : bool ,
@@ -366,6 +363,10 @@ fn emit_orphan_check_error<'tcx>(
366
363
}
367
364
pointer. push ( errors:: OnlyCurrentTraitsPointer { span, pointer : ty } ) ;
368
365
}
366
+ ty:: Adt ( adt_def, _) => adt. push ( errors:: OnlyCurrentTraitsAdt {
367
+ span,
368
+ name : tcx. def_path_str ( adt_def. did ( ) ) ,
369
+ } ) ,
369
370
_ => ty_diag. push ( errors:: OnlyCurrentTraitsTy { span, ty } ) ,
370
371
}
371
372
}
@@ -379,6 +380,7 @@ fn emit_orphan_check_error<'tcx>(
379
380
name,
380
381
pointer,
381
382
ty : ty_diag,
383
+ adt,
382
384
sugg,
383
385
} ,
384
386
_ if self_ty. is_primitive ( ) => errors:: OnlyCurrentTraits :: Primitive {
@@ -389,6 +391,7 @@ fn emit_orphan_check_error<'tcx>(
389
391
name,
390
392
pointer,
391
393
ty : ty_diag,
394
+ adt,
392
395
sugg,
393
396
} ,
394
397
_ => errors:: OnlyCurrentTraits :: Arbitrary {
@@ -399,6 +402,7 @@ fn emit_orphan_check_error<'tcx>(
399
402
name,
400
403
pointer,
401
404
ty : ty_diag,
405
+ adt,
402
406
sugg,
403
407
} ,
404
408
} ;
0 commit comments