@@ -283,15 +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
- // 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 ! [ ] ;
294
- let mut sugg = None ;
286
+ let mut diag = tcx. dcx ( ) . create_err ( match self_ty. kind ( ) {
287
+ ty:: Adt ( ..) => errors:: OnlyCurrentTraits :: Outside { span : sp, note : ( ) } ,
288
+ _ if self_ty. is_primitive ( ) => {
289
+ errors:: OnlyCurrentTraits :: Primitive { span : sp, note : ( ) }
290
+ }
291
+ _ => errors:: OnlyCurrentTraits :: Arbitrary { span : sp, note : ( ) } ,
292
+ } ) ;
293
+
295
294
for & ( mut ty, is_target_ty) in & tys {
296
295
let span = if matches ! ( is_target_ty, IsFirstInputType :: Yes ) {
297
296
// Point at `D<A>` in `impl<A, B> for C<B> in D<A>`
@@ -303,110 +302,85 @@ fn emit_orphan_check_error<'tcx>(
303
302
304
303
ty = tcx. erase_regions ( ty) ;
305
304
306
- fn push_to_foreign_or_name < ' tcx > (
307
- is_foreign : bool ,
308
- foreign : & mut Vec < errors:: OnlyCurrentTraitsForeign > ,
309
- name : & mut Vec < errors:: OnlyCurrentTraitsName < ' tcx > > ,
310
- span : Span ,
311
- sname : & ' tcx str ,
312
- ) {
313
- if is_foreign {
314
- foreign. push ( errors:: OnlyCurrentTraitsForeign { span } )
315
- } else {
316
- name. push ( errors:: OnlyCurrentTraitsName { span, name : sname } ) ;
317
- }
318
- }
319
-
320
305
let is_foreign =
321
306
!trait_ref. def_id . is_local ( ) && matches ! ( is_target_ty, IsFirstInputType :: No ) ;
322
307
323
308
match * ty. kind ( ) {
324
309
ty:: Slice ( _) => {
325
- push_to_foreign_or_name (
326
- is_foreign,
327
- & mut foreign,
328
- & mut name,
329
- span,
330
- "slices" ,
331
- ) ;
310
+ if is_foreign {
311
+ diag. subdiagnostic (
312
+ tcx. dcx ( ) ,
313
+ errors:: OnlyCurrentTraitsForeign { span } ,
314
+ ) ;
315
+ } else {
316
+ diag. subdiagnostic (
317
+ tcx. dcx ( ) ,
318
+ errors:: OnlyCurrentTraitsName { span, name : "slices" } ,
319
+ ) ;
320
+ }
332
321
}
333
322
ty:: Array ( ..) => {
334
- push_to_foreign_or_name (
335
- is_foreign,
336
- & mut foreign,
337
- & mut name,
338
- span,
339
- "arrays" ,
340
- ) ;
323
+ if is_foreign {
324
+ diag. subdiagnostic (
325
+ tcx. dcx ( ) ,
326
+ errors:: OnlyCurrentTraitsForeign { span } ,
327
+ ) ;
328
+ } else {
329
+ diag. subdiagnostic (
330
+ tcx. dcx ( ) ,
331
+ errors:: OnlyCurrentTraitsName { span, name : "arrays" } ,
332
+ ) ;
333
+ }
341
334
}
342
335
ty:: Tuple ( ..) => {
343
- push_to_foreign_or_name (
344
- is_foreign,
345
- & mut foreign,
346
- & mut name,
347
- span,
348
- "tuples" ,
349
- ) ;
336
+ if is_foreign {
337
+ diag. subdiagnostic (
338
+ tcx. dcx ( ) ,
339
+ errors:: OnlyCurrentTraitsForeign { span } ,
340
+ ) ;
341
+ } else {
342
+ diag. subdiagnostic (
343
+ tcx. dcx ( ) ,
344
+ errors:: OnlyCurrentTraitsName { span, name : "tuples" } ,
345
+ ) ;
346
+ }
350
347
}
351
348
ty:: Alias ( ty:: Opaque , ..) => {
352
- opaque . push ( errors:: OnlyCurrentTraitsOpaque { span } )
349
+ diag . subdiagnostic ( tcx . dcx ( ) , errors:: OnlyCurrentTraitsOpaque { span } ) ;
353
350
}
354
351
ty:: RawPtr ( ptr_ty, mutbl) => {
355
352
if !self_ty. has_param ( ) {
356
- let mut_key = mutbl. prefix_str ( ) ;
357
- sugg = Some ( errors:: OnlyCurrentTraitsPointerSugg {
358
- wrapper_span : self_ty_span,
359
- struct_span : full_impl_span. shrink_to_lo ( ) ,
360
- mut_key,
361
- ptr_ty,
362
- } ) ;
353
+ diag. subdiagnostic (
354
+ tcx. dcx ( ) ,
355
+ errors:: OnlyCurrentTraitsPointerSugg {
356
+ wrapper_span : self_ty_span,
357
+ struct_span : full_impl_span. shrink_to_lo ( ) ,
358
+ mut_key : mutbl. prefix_str ( ) ,
359
+ ptr_ty,
360
+ } ,
361
+ ) ;
363
362
}
364
- pointer. push ( errors:: OnlyCurrentTraitsPointer { span, pointer : ty } ) ;
363
+ diag. subdiagnostic (
364
+ tcx. dcx ( ) ,
365
+ errors:: OnlyCurrentTraitsPointer { span, pointer : ty } ,
366
+ ) ;
367
+ }
368
+ ty:: Adt ( adt_def, _) => {
369
+ diag. subdiagnostic (
370
+ tcx. dcx ( ) ,
371
+ errors:: OnlyCurrentTraitsAdt {
372
+ span,
373
+ name : tcx. def_path_str ( adt_def. did ( ) ) ,
374
+ } ,
375
+ ) ;
376
+ }
377
+ _ => {
378
+ diag. subdiagnostic ( tcx. dcx ( ) , errors:: OnlyCurrentTraitsTy { span, ty } ) ;
365
379
}
366
- ty:: Adt ( adt_def, _) => adt. push ( errors:: OnlyCurrentTraitsAdt {
367
- span,
368
- name : tcx. def_path_str ( adt_def. did ( ) ) ,
369
- } ) ,
370
- _ => ty_diag. push ( errors:: OnlyCurrentTraitsTy { span, ty } ) ,
371
380
}
372
381
}
373
382
374
- let err_struct = match self_ty. kind ( ) {
375
- ty:: Adt ( ..) => errors:: OnlyCurrentTraits :: Outside {
376
- span : sp,
377
- note : ( ) ,
378
- opaque,
379
- foreign,
380
- name,
381
- pointer,
382
- ty : ty_diag,
383
- adt,
384
- sugg,
385
- } ,
386
- _ if self_ty. is_primitive ( ) => errors:: OnlyCurrentTraits :: Primitive {
387
- span : sp,
388
- note : ( ) ,
389
- opaque,
390
- foreign,
391
- name,
392
- pointer,
393
- ty : ty_diag,
394
- adt,
395
- sugg,
396
- } ,
397
- _ => errors:: OnlyCurrentTraits :: Arbitrary {
398
- span : sp,
399
- note : ( ) ,
400
- opaque,
401
- foreign,
402
- name,
403
- pointer,
404
- ty : ty_diag,
405
- adt,
406
- sugg,
407
- } ,
408
- } ;
409
- tcx. dcx ( ) . emit_err ( err_struct)
383
+ diag. emit ( )
410
384
}
411
385
traits:: OrphanCheckErr :: UncoveredTy ( param_ty, local_type) => {
412
386
let mut sp = sp;
0 commit comments