44use crate :: errors;
55use rustc_errors:: ErrorGuaranteed ;
66use rustc_hir as hir;
7- use rustc_middle:: ty:: { self , AliasKind , Ty , TyCtxt , TypeVisitableExt } ;
7+ use rustc_middle:: ty:: { self , AliasKind , TyCtxt , TypeVisitableExt } ;
88use rustc_span:: def_id:: LocalDefId ;
99use rustc_span:: Span ;
1010use rustc_trait_selection:: traits:: { self , IsFirstInputType } ;
@@ -283,8 +283,14 @@ fn emit_orphan_check_error<'tcx>(
283283 let self_ty = trait_ref. self_ty ( ) ;
284284 Err ( match err {
285285 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 ! [ ] ;
288294 let mut sugg = None ;
289295 for & ( mut ty, is_target_ty) in & tys {
290296 let span = if matches ! ( is_target_ty, IsFirstInputType :: Yes ) {
@@ -296,15 +302,6 @@ fn emit_orphan_check_error<'tcx>(
296302 } ;
297303
298304 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- } ;
308305
309306 fn push_to_foreign_or_name < ' tcx > (
310307 is_foreign : bool ,
@@ -366,6 +363,10 @@ fn emit_orphan_check_error<'tcx>(
366363 }
367364 pointer. push ( errors:: OnlyCurrentTraitsPointer { span, pointer : ty } ) ;
368365 }
366+ ty:: Adt ( adt_def, _) => adt. push ( errors:: OnlyCurrentTraitsAdt {
367+ span,
368+ name : tcx. def_path_str ( adt_def. did ( ) ) ,
369+ } ) ,
369370 _ => ty_diag. push ( errors:: OnlyCurrentTraitsTy { span, ty } ) ,
370371 }
371372 }
@@ -379,6 +380,7 @@ fn emit_orphan_check_error<'tcx>(
379380 name,
380381 pointer,
381382 ty : ty_diag,
383+ adt,
382384 sugg,
383385 } ,
384386 _ if self_ty. is_primitive ( ) => errors:: OnlyCurrentTraits :: Primitive {
@@ -389,6 +391,7 @@ fn emit_orphan_check_error<'tcx>(
389391 name,
390392 pointer,
391393 ty : ty_diag,
394+ adt,
392395 sugg,
393396 } ,
394397 _ => errors:: OnlyCurrentTraits :: Arbitrary {
@@ -399,6 +402,7 @@ fn emit_orphan_check_error<'tcx>(
399402 name,
400403 pointer,
401404 ty : ty_diag,
405+ adt,
402406 sugg,
403407 } ,
404408 } ;
0 commit comments