@@ -418,7 +418,7 @@ fn orphan_check_trait_ref<'tcx>(
418
418
. substs
419
419
. types ( )
420
420
. flat_map ( |ty| uncover_fundamental_ty ( tcx, ty, in_crate) )
421
- . find ( |ty| ty_is_non_local_constructor ( ty, in_crate) . is_none ( ) ) ;
421
+ . find ( |ty| ty_is_local_constructor ( ty, in_crate) ) ;
422
422
423
423
debug ! ( "orphan_check_trait_ref: uncovered ty local_type: `{:?}`" , local_type) ;
424
424
@@ -435,20 +435,16 @@ fn orphan_check_trait_ref<'tcx>(
435
435
Err ( OrphanCheckErr :: NonLocalInputType ( non_local_spans) )
436
436
}
437
437
438
+ // FIXME: Return a `Vec` without `Option` here.
438
439
fn ty_is_non_local ( tcx : TyCtxt < ' tcx > , ty : Ty < ' tcx > , in_crate : InCrate ) -> Option < Vec < Ty < ' tcx > > > {
439
- match ty_is_non_local_constructor ( ty, in_crate) {
440
- Some ( ty) => {
441
- if let Some ( inner_tys) = fundamental_ty_inner_tys ( tcx, ty) {
442
- let tys: Vec < _ > = inner_tys
443
- . filter_map ( |ty| ty_is_non_local ( tcx, ty, in_crate) )
444
- . flatten ( )
445
- . collect ( ) ;
446
- if tys. is_empty ( ) { None } else { Some ( tys) }
447
- } else {
448
- Some ( vec ! [ ty] )
449
- }
450
- }
451
- None => None ,
440
+ if ty_is_local_constructor ( ty, in_crate) {
441
+ None
442
+ } else if let Some ( inner_tys) = fundamental_ty_inner_tys ( tcx, ty) {
443
+ let tys: Vec < _ > =
444
+ inner_tys. filter_map ( |ty| ty_is_non_local ( tcx, ty, in_crate) ) . flatten ( ) . collect ( ) ;
445
+ if tys. is_empty ( ) { None } else { Some ( tys) }
446
+ } else {
447
+ Some ( vec ! [ ty] )
452
448
}
453
449
}
454
450
@@ -493,8 +489,7 @@ fn def_id_is_local(def_id: DefId, in_crate: InCrate) -> bool {
493
489
}
494
490
}
495
491
496
- // FIXME(eddyb) this can just return `bool` as it always returns `Some(ty)` or `None`.
497
- fn ty_is_non_local_constructor ( ty : Ty < ' _ > , in_crate : InCrate ) -> Option < Ty < ' _ > > {
492
+ fn ty_is_local_constructor ( ty : Ty < ' _ > , in_crate : InCrate ) -> bool {
498
493
debug ! ( "ty_is_non_local_constructor({:?})" , ty) ;
499
494
500
495
match ty. kind {
@@ -513,29 +508,17 @@ fn ty_is_non_local_constructor(ty: Ty<'_>, in_crate: InCrate) -> Option<Ty<'_>>
513
508
| ty:: Never
514
509
| ty:: Tuple ( ..)
515
510
| ty:: Param ( ..)
516
- | ty:: Projection ( ..) => Some ( ty ) ,
511
+ | ty:: Projection ( ..) => false ,
517
512
518
513
ty:: Placeholder ( ..) | ty:: Bound ( ..) | ty:: Infer ( ..) => match in_crate {
519
- InCrate :: Local => Some ( ty ) ,
514
+ InCrate :: Local => false ,
520
515
// The inference variable might be unified with a local
521
516
// type in that remote crate.
522
- InCrate :: Remote => None ,
517
+ InCrate :: Remote => true ,
523
518
} ,
524
519
525
- ty:: Adt ( def, _) => {
526
- if def_id_is_local ( def. did , in_crate) {
527
- None
528
- } else {
529
- Some ( ty)
530
- }
531
- }
532
- ty:: Foreign ( did) => {
533
- if def_id_is_local ( did, in_crate) {
534
- None
535
- } else {
536
- Some ( ty)
537
- }
538
- }
520
+ ty:: Adt ( def, _) => def_id_is_local ( def. did , in_crate) ,
521
+ ty:: Foreign ( did) => def_id_is_local ( did, in_crate) ,
539
522
ty:: Opaque ( ..) => {
540
523
// This merits some explanation.
541
524
// Normally, opaque types are not involed when performing
@@ -553,7 +536,7 @@ fn ty_is_non_local_constructor(ty: Ty<'_>, in_crate: InCrate) -> Option<Ty<'_>>
553
536
// the underlying type *within the same crate*. When an
554
537
// opaque type is used from outside the module
555
538
// where it is declared, it should be impossible to observe
556
- // anyything about it other than the traits that it implements.
539
+ // anything about it other than the traits that it implements.
557
540
//
558
541
// The alternative would be to look at the underlying type
559
542
// to determine whether or not the opaque type itself should
@@ -562,18 +545,18 @@ fn ty_is_non_local_constructor(ty: Ty<'_>, in_crate: InCrate) -> Option<Ty<'_>>
562
545
// to a remote type. This would violate the rule that opaque
563
546
// types should be completely opaque apart from the traits
564
547
// that they implement, so we don't use this behavior.
565
- Some ( ty )
548
+ false
566
549
}
567
550
568
551
ty:: Dynamic ( ref tt, ..) => {
569
552
if let Some ( principal) = tt. principal ( ) {
570
- if def_id_is_local ( principal. def_id ( ) , in_crate) { None } else { Some ( ty ) }
553
+ def_id_is_local ( principal. def_id ( ) , in_crate)
571
554
} else {
572
- Some ( ty )
555
+ false
573
556
}
574
557
}
575
558
576
- ty:: Error ( _) => None ,
559
+ ty:: Error ( _) => true ,
577
560
578
561
ty:: Closure ( ..) | ty:: Generator ( ..) | ty:: GeneratorWitness ( ..) => {
579
562
bug ! ( "ty_is_local invoked on unexpected type: {:?}" , ty)
0 commit comments