@@ -418,7 +418,7 @@ fn orphan_check_trait_ref<'tcx>(
418418 . substs
419419 . types ( )
420420 . 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) ) ;
422422
423423 debug ! ( "orphan_check_trait_ref: uncovered ty local_type: `{:?}`" , local_type) ;
424424
@@ -435,20 +435,16 @@ fn orphan_check_trait_ref<'tcx>(
435435 Err ( OrphanCheckErr :: NonLocalInputType ( non_local_spans) )
436436}
437437
438+ // FIXME: Return a `Vec` without `Option` here.
438439fn 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] )
452448 }
453449}
454450
@@ -493,8 +489,7 @@ fn def_id_is_local(def_id: DefId, in_crate: InCrate) -> bool {
493489 }
494490}
495491
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 {
498493 debug ! ( "ty_is_non_local_constructor({:?})" , ty) ;
499494
500495 match ty. kind {
@@ -513,29 +508,17 @@ fn ty_is_non_local_constructor(ty: Ty<'_>, in_crate: InCrate) -> Option<Ty<'_>>
513508 | ty:: Never
514509 | ty:: Tuple ( ..)
515510 | ty:: Param ( ..)
516- | ty:: Projection ( ..) => Some ( ty ) ,
511+ | ty:: Projection ( ..) => false ,
517512
518513 ty:: Placeholder ( ..) | ty:: Bound ( ..) | ty:: Infer ( ..) => match in_crate {
519- InCrate :: Local => Some ( ty ) ,
514+ InCrate :: Local => false ,
520515 // The inference variable might be unified with a local
521516 // type in that remote crate.
522- InCrate :: Remote => None ,
517+ InCrate :: Remote => true ,
523518 } ,
524519
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) ,
539522 ty:: Opaque ( ..) => {
540523 // This merits some explanation.
541524 // 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<'_>>
553536 // the underlying type *within the same crate*. When an
554537 // opaque type is used from outside the module
555538 // 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.
557540 //
558541 // The alternative would be to look at the underlying type
559542 // 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<'_>>
562545 // to a remote type. This would violate the rule that opaque
563546 // types should be completely opaque apart from the traits
564547 // that they implement, so we don't use this behavior.
565- Some ( ty )
548+ false
566549 }
567550
568551 ty:: Dynamic ( ref tt, ..) => {
569552 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)
571554 } else {
572- Some ( ty )
555+ false
573556 }
574557 }
575558
576- ty:: Error ( _) => None ,
559+ ty:: Error ( _) => true ,
577560
578561 ty:: Closure ( ..) | ty:: Generator ( ..) | ty:: GeneratorWitness ( ..) => {
579562 bug ! ( "ty_is_local invoked on unexpected type: {:?}" , ty)
0 commit comments