@@ -389,7 +389,7 @@ fn orphan_check_trait_ref<'tcx>(
389389 ) -> Vec < Ty < ' tcx > > {
390390 // FIXME(eddyb) figure out if this is redundant with `ty_is_non_local`,
391391 // or maybe if this should be calling `ty_is_non_local_constructor`.
392- if ty_is_non_local ( tcx, ty, in_crate) . is_some ( ) {
392+ if ! contained_non_local_types ( tcx, ty, in_crate) . is_empty ( ) {
393393 if let Some ( inner_tys) = fundamental_ty_inner_tys ( tcx, ty) {
394394 return inner_tys
395395 . flat_map ( |ty| uncover_fundamental_ty ( tcx, ty, in_crate) )
@@ -408,8 +408,8 @@ fn orphan_check_trait_ref<'tcx>(
408408 . enumerate ( )
409409 {
410410 debug ! ( "orphan_check_trait_ref: check ty `{:?}`" , input_ty) ;
411- let non_local_tys = ty_is_non_local ( tcx, input_ty, in_crate) ;
412- if non_local_tys. is_none ( ) {
411+ let non_local_tys = contained_non_local_types ( tcx, input_ty, in_crate) ;
412+ if non_local_tys. is_empty ( ) {
413413 debug ! ( "orphan_check_trait_ref: ty_is_local `{:?}`" , input_ty) ;
414414 return Ok ( ( ) ) ;
415415 } else if let ty:: Param ( _) = input_ty. kind {
@@ -424,27 +424,30 @@ fn orphan_check_trait_ref<'tcx>(
424424
425425 return Err ( OrphanCheckErr :: UncoveredTy ( input_ty, local_type) ) ;
426426 }
427- if let Some ( non_local_tys) = non_local_tys {
428- for input_ty in non_local_tys {
429- non_local_spans. push ( ( input_ty, i == 0 ) ) ;
430- }
427+
428+ for input_ty in non_local_tys {
429+ non_local_spans. push ( ( input_ty, i == 0 ) ) ;
431430 }
432431 }
433432 // If we exit above loop, never found a local type.
434433 debug ! ( "orphan_check_trait_ref: no local type" ) ;
435434 Err ( OrphanCheckErr :: NonLocalInputType ( non_local_spans) )
436435}
437436
438- // FIXME: Return a `Vec` without `Option` here.
439- fn ty_is_non_local ( tcx : TyCtxt < ' tcx > , ty : Ty < ' tcx > , in_crate : InCrate ) -> Option < Vec < Ty < ' tcx > > > {
437+ /// Returns a list of relevant non-local types for `ty`.
438+ ///
439+ /// This is just `ty` itself unless `ty` is `#[fundamental]`,
440+ /// in which case we recursively look into this type.
441+ fn contained_non_local_types ( tcx : TyCtxt < ' tcx > , ty : Ty < ' tcx > , in_crate : InCrate ) -> Vec < Ty < ' tcx > > {
440442 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) }
443+ Vec :: new ( )
446444 } else {
447- Some ( vec ! [ ty] )
445+ match fundamental_ty_inner_tys ( tcx, ty) {
446+ Some ( inner_tys) => {
447+ inner_tys. flat_map ( |ty| contained_non_local_types ( tcx, ty, in_crate) ) . collect ( )
448+ }
449+ None => vec ! [ ty] ,
450+ }
448451 }
449452}
450453
0 commit comments