@@ -367,118 +367,52 @@ fn orphan_check_trait_ref<'tcx>(
367
367
trait_ref) ;
368
368
}
369
369
370
- if tcx. features ( ) . re_rebalance_coherence {
371
- // Given impl<P1..=Pn> Trait<T1..=Tn> for T0, an impl is valid only
372
- // if at least one of the following is true:
373
- //
374
- // - Trait is a local trait
375
- // (already checked in orphan_check prior to calling this function)
376
- // - All of
377
- // - At least one of the types T0..=Tn must be a local type.
378
- // Let Ti be the first such type.
379
- // - No uncovered type parameters P1..=Pn may appear in T0..Ti (excluding Ti)
380
- //
381
- fn uncover_fundamental_ty < ' tcx > (
382
- tcx : TyCtxt < ' tcx > ,
383
- ty : Ty < ' tcx > ,
384
- in_crate : InCrate ,
385
- ) -> Vec < Ty < ' tcx > > {
386
- if fundamental_ty ( ty) && ty_is_non_local ( tcx, ty, in_crate) . is_some ( ) {
387
- ty. walk_shallow ( ) . flat_map ( |ty| uncover_fundamental_ty ( tcx, ty, in_crate) ) . collect ( )
388
- } else {
389
- vec ! [ ty]
390
- }
370
+ // Given impl<P1..=Pn> Trait<T1..=Tn> for T0, an impl is valid only
371
+ // if at least one of the following is true:
372
+ //
373
+ // - Trait is a local trait
374
+ // (already checked in orphan_check prior to calling this function)
375
+ // - All of
376
+ // - At least one of the types T0..=Tn must be a local type.
377
+ // Let Ti be the first such type.
378
+ // - No uncovered type parameters P1..=Pn may appear in T0..Ti (excluding Ti)
379
+ //
380
+ fn uncover_fundamental_ty < ' tcx > (
381
+ tcx : TyCtxt < ' tcx > ,
382
+ ty : Ty < ' tcx > ,
383
+ in_crate : InCrate ,
384
+ ) -> Vec < Ty < ' tcx > > {
385
+ if fundamental_ty ( ty) && ty_is_non_local ( tcx, ty, in_crate) . is_some ( ) {
386
+ ty. walk_shallow ( ) . flat_map ( |ty| uncover_fundamental_ty ( tcx, ty, in_crate) ) . collect ( )
387
+ } else {
388
+ vec ! [ ty]
391
389
}
390
+ }
392
391
393
- let mut non_local_spans = vec ! [ ] ;
394
- for ( i, input_ty) in trait_ref
395
- . input_types ( )
396
- . flat_map ( |ty| uncover_fundamental_ty ( tcx, ty, in_crate) )
397
- . enumerate ( )
398
- {
399
- debug ! ( "orphan_check_trait_ref: check ty `{:?}`" , input_ty) ;
400
- let non_local_tys = ty_is_non_local ( tcx, input_ty, in_crate) ;
401
- if non_local_tys. is_none ( ) {
402
- debug ! ( "orphan_check_trait_ref: ty_is_local `{:?}`" , input_ty) ;
403
- return Ok ( ( ) ) ;
404
- } else if let ty:: Param ( _) = input_ty. kind {
405
- debug ! ( "orphan_check_trait_ref: uncovered ty: `{:?}`" , input_ty) ;
406
- return Err ( OrphanCheckErr :: UncoveredTy ( input_ty) )
407
- }
408
- if let Some ( non_local_tys) = non_local_tys {
409
- for input_ty in non_local_tys {
410
- non_local_spans. push ( ( input_ty, i == 0 ) ) ;
411
- }
412
- }
392
+ let mut non_local_spans = vec ! [ ] ;
393
+ for ( i, input_ty) in trait_ref
394
+ . input_types ( )
395
+ . flat_map ( |ty| uncover_fundamental_ty ( tcx, ty, in_crate) )
396
+ . enumerate ( )
397
+ {
398
+ debug ! ( "orphan_check_trait_ref: check ty `{:?}`" , input_ty) ;
399
+ let non_local_tys = ty_is_non_local ( tcx, input_ty, in_crate) ;
400
+ if non_local_tys. is_none ( ) {
401
+ debug ! ( "orphan_check_trait_ref: ty_is_local `{:?}`" , input_ty) ;
402
+ return Ok ( ( ) ) ;
403
+ } else if let ty:: Param ( _) = input_ty. kind {
404
+ debug ! ( "orphan_check_trait_ref: uncovered ty: `{:?}`" , input_ty) ;
405
+ return Err ( OrphanCheckErr :: UncoveredTy ( input_ty) )
413
406
}
414
- // If we exit above loop, never found a local type.
415
- debug ! ( "orphan_check_trait_ref: no local type" ) ;
416
- Err ( OrphanCheckErr :: NonLocalInputType ( non_local_spans) )
417
- } else {
418
- let mut non_local_spans = vec ! [ ] ;
419
- // First, create an ordered iterator over all the type
420
- // parameters to the trait, with the self type appearing
421
- // first. Find the first input type that either references a
422
- // type parameter OR some local type.
423
- for ( i, input_ty) in trait_ref. input_types ( ) . enumerate ( ) {
424
- let non_local_tys = ty_is_non_local ( tcx, input_ty, in_crate) ;
425
- if non_local_tys. is_none ( ) {
426
- debug ! ( "orphan_check_trait_ref: ty_is_local `{:?}`" , input_ty) ;
427
-
428
- // First local input type. Check that there are no
429
- // uncovered type parameters.
430
- let uncovered_tys = uncovered_tys ( tcx, input_ty, in_crate) ;
431
- for uncovered_ty in uncovered_tys {
432
- if let Some ( param) = uncovered_ty. walk ( )
433
- . find ( |t| is_possibly_remote_type ( t, in_crate) )
434
- {
435
- debug ! ( "orphan_check_trait_ref: uncovered type `{:?}`" , param) ;
436
- return Err ( OrphanCheckErr :: UncoveredTy ( param) ) ;
437
- }
438
- }
439
-
440
- // OK, found local type, all prior types upheld invariant.
441
- return Ok ( ( ) ) ;
442
- }
443
-
444
- // Otherwise, enforce invariant that there are no type
445
- // parameters reachable.
446
- if let Some ( param) = input_ty. walk ( )
447
- . find ( |t| is_possibly_remote_type ( t, in_crate) )
448
- {
449
- debug ! ( "orphan_check_trait_ref: uncovered type `{:?}`" , param) ;
450
- return Err ( OrphanCheckErr :: UncoveredTy ( param) ) ;
451
- }
452
-
453
- if let Some ( non_local_tys) = non_local_tys {
454
- for input_ty in non_local_tys {
455
- non_local_spans. push ( ( input_ty, i == 0 ) ) ;
456
- }
407
+ if let Some ( non_local_tys) = non_local_tys {
408
+ for input_ty in non_local_tys {
409
+ non_local_spans. push ( ( input_ty, i == 0 ) ) ;
457
410
}
458
411
}
459
- // If we exit above loop, never found a local type.
460
- debug ! ( "orphan_check_trait_ref: no local type" ) ;
461
- Err ( OrphanCheckErr :: NonLocalInputType ( non_local_spans) )
462
- }
463
- }
464
-
465
- fn uncovered_tys < ' tcx > ( tcx : TyCtxt < ' tcx > , ty : Ty < ' tcx > , in_crate : InCrate ) -> Vec < Ty < ' tcx > > {
466
- if ty_is_non_local_constructor ( tcx, ty, in_crate) . is_none ( ) {
467
- vec ! [ ]
468
- } else if fundamental_ty ( ty) {
469
- ty. walk_shallow ( )
470
- . flat_map ( |t| uncovered_tys ( tcx, t, in_crate) )
471
- . collect ( )
472
- } else {
473
- vec ! [ ty]
474
- }
475
- }
476
-
477
- fn is_possibly_remote_type ( ty : Ty < ' _ > , _in_crate : InCrate ) -> bool {
478
- match ty. kind {
479
- ty:: Projection ( ..) | ty:: Param ( ..) => true ,
480
- _ => false ,
481
412
}
413
+ // If we exit above loop, never found a local type.
414
+ debug ! ( "orphan_check_trait_ref: no local type" ) ;
415
+ Err ( OrphanCheckErr :: NonLocalInputType ( non_local_spans) )
482
416
}
483
417
484
418
fn ty_is_non_local < ' t > ( tcx : TyCtxt < ' t > , ty : Ty < ' t > , in_crate : InCrate ) -> Option < Vec < Ty < ' t > > > {
0 commit comments