@@ -16,7 +16,6 @@ use middle::region;
1616use middle:: subst:: { self , TypeSpace , FnSpace , ParamSpace , SelfSpace } ;
1717use middle:: traits;
1818use middle:: ty:: { self , Ty } ;
19- use middle:: ty:: liberate_late_bound_regions;
2019use middle:: ty_fold:: { TypeFolder , TypeFoldable , super_fold_ty} ;
2120use util:: ppaux:: { Repr , UserString } ;
2221
@@ -510,10 +509,7 @@ impl<'cx,'tcx> BoundsChecker<'cx,'tcx> {
510509 & trait_predicates) ;
511510
512511 self . fcx . add_obligations_for_parameters (
513- traits:: ObligationCause :: new (
514- self . span ,
515- self . fcx . body_id ,
516- traits:: ItemObligation ( trait_ref. def_id ) ) ,
512+ self . cause ( traits:: ItemObligation ( trait_ref. def_id ) ) ,
517513 & bounds) ;
518514
519515 for & ty in trait_ref. substs . types . iter ( ) {
@@ -532,8 +528,13 @@ impl<'cx,'tcx> BoundsChecker<'cx,'tcx> {
532528 ty. fold_with ( self ) ;
533529 self . binding_count -= 1 ;
534530 }
531+
532+ fn cause ( & self , code : traits:: ObligationCauseCode < ' tcx > ) -> traits:: ObligationCause < ' tcx > {
533+ traits:: ObligationCause :: new ( self . span , self . fcx . body_id , code)
534+ }
535535}
536536
537+ // Note: TypeFolder here is used as a visitor.
537538impl < ' cx , ' tcx > TypeFolder < ' tcx > for BoundsChecker < ' cx , ' tcx > {
538539 fn tcx ( & self ) -> & ty:: ctxt < ' tcx > {
539540 self . fcx . tcx ( )
@@ -543,7 +544,7 @@ impl<'cx,'tcx> TypeFolder<'tcx> for BoundsChecker<'cx,'tcx> {
543544 where T : TypeFoldable < ' tcx > + Repr < ' tcx >
544545 {
545546 self . binding_count += 1 ;
546- let value = liberate_late_bound_regions (
547+ let value = ty :: liberate_late_bound_regions (
547548 self . fcx . tcx ( ) ,
548549 region:: DestructionScopeData :: new ( self . scope ) ,
549550 binder) ;
@@ -554,6 +555,24 @@ impl<'cx,'tcx> TypeFolder<'tcx> for BoundsChecker<'cx,'tcx> {
554555 ty:: Binder ( value)
555556 }
556557
558+
559+ fn fold_fn_sig ( & mut self , sig : & ty:: FnSig < ' tcx > ) -> ty:: FnSig < ' tcx > {
560+ if let ty:: FnConverging ( ret) = sig. output {
561+ self . fcx . register_builtin_bound ( self . fold_ty ( ret) ,
562+ ty:: BoundSized ,
563+ self . cause ( traits:: ReturnType ) ) ;
564+ }
565+
566+ for input in & sig. inputs {
567+ self . fcx . register_builtin_bound ( self . fold_ty ( input) ,
568+ ty:: BoundSized ,
569+ self . cause ( traits:: ArgumentType ) ) ;
570+ }
571+
572+ sig. clone ( )
573+ }
574+
575+
557576 fn fold_ty ( & mut self , t : Ty < ' tcx > ) -> Ty < ' tcx > {
558577 debug ! ( "BoundsChecker t={}" ,
559578 t. repr( self . tcx( ) ) ) ;
@@ -569,7 +588,23 @@ impl<'cx,'tcx> TypeFolder<'tcx> for BoundsChecker<'cx,'tcx> {
569588 None => { }
570589 }
571590
572- match t. sty {
591+ match t. sty {
592+ ty:: ty_vec( ety, _) => {
593+ self . fcx . register_builtin_bound ( self . fold_ty ( ety) ,
594+ ty:: BoundSized ,
595+ self . cause ( traits:: VecElemSized ) ) ;
596+ t
597+ }
598+ ty:: ty_tup( ref tys) => {
599+ for ty in tys {
600+ self . fcx . register_builtin_bound ( self . fold_ty ( ty) ,
601+ ty:: BoundSized ,
602+ self . cause ( traits:: TupleElemSized )
603+ ) ;
604+
605+ }
606+ t
607+ }
573608 ty:: ty_struct( type_id, substs) |
574609 ty:: ty_enum( type_id, substs) => {
575610 let type_predicates = ty:: lookup_predicates ( self . fcx . tcx ( ) , type_id) ;
@@ -578,9 +613,7 @@ impl<'cx,'tcx> TypeFolder<'tcx> for BoundsChecker<'cx,'tcx> {
578613
579614 if self . binding_count == 0 {
580615 self . fcx . add_obligations_for_parameters (
581- traits:: ObligationCause :: new ( self . span ,
582- self . fcx . body_id ,
583- traits:: ItemObligation ( type_id) ) ,
616+ self . cause ( traits:: ItemObligation ( type_id) ) ,
584617 & bounds) ;
585618 } else {
586619 // There are two circumstances in which we ignore
@@ -605,22 +638,22 @@ impl<'cx,'tcx> TypeFolder<'tcx> for BoundsChecker<'cx,'tcx> {
605638 //
606639 // (I believe we should do the same for traits, but
607640 // that will require an RFC. -nmatsakis)
641+ //
642+ // TODO(arielb1): this also seems to be triggered
643+ // when you have something like
644+ // for<'a> Trait<&'a (), &'free1 &'free2 ()>
608645 let bounds = filter_to_trait_obligations ( bounds) ;
609646 self . fcx . add_obligations_for_parameters (
610- traits:: ObligationCause :: new ( self . span ,
611- self . fcx . body_id ,
612- traits:: ItemObligation ( type_id) ) ,
647+ self . cause ( traits:: ItemObligation ( type_id) ) ,
613648 & bounds) ;
614649 }
615-
616650 self . fold_substs ( substs) ;
651+ t
617652 }
618653 _ => {
619- super_fold_ty ( self , t) ;
654+ super_fold_ty ( self , t)
620655 }
621656 }
622-
623- t // we're not folding to produce a new type, so just return `t` here
624657 }
625658}
626659
0 commit comments