@@ -389,7 +389,7 @@ fn orphan_check_trait_ref<'tcx>(
389
389
) -> Vec < Ty < ' tcx > > {
390
390
// FIXME(eddyb) figure out if this is redundant with `ty_is_non_local`,
391
391
// 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 ( ) {
393
393
if let Some ( inner_tys) = fundamental_ty_inner_tys ( tcx, ty) {
394
394
return inner_tys
395
395
. flat_map ( |ty| uncover_fundamental_ty ( tcx, ty, in_crate) )
@@ -408,8 +408,8 @@ fn orphan_check_trait_ref<'tcx>(
408
408
. enumerate ( )
409
409
{
410
410
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 ( ) {
413
413
debug ! ( "orphan_check_trait_ref: ty_is_local `{:?}`" , input_ty) ;
414
414
return Ok ( ( ) ) ;
415
415
} else if let ty:: Param ( _) = input_ty. kind {
@@ -424,27 +424,30 @@ fn orphan_check_trait_ref<'tcx>(
424
424
425
425
return Err ( OrphanCheckErr :: UncoveredTy ( input_ty, local_type) ) ;
426
426
}
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 ) ) ;
431
430
}
432
431
}
433
432
// If we exit above loop, never found a local type.
434
433
debug ! ( "orphan_check_trait_ref: no local type" ) ;
435
434
Err ( OrphanCheckErr :: NonLocalInputType ( non_local_spans) )
436
435
}
437
436
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 > > {
440
442
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 ( )
446
444
} 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
+ }
448
451
}
449
452
}
450
453
0 commit comments