@@ -191,6 +191,7 @@ impl LowerProgram for Program {
191191 id : info. id ,
192192 name : defn. name . str ,
193193 parameter_kinds : parameter_kinds,
194+ bounds : defn. bounds . lower ( & env) ?,
194195 where_clauses : defn. where_clauses . lower ( & env) ?,
195196 } ,
196197 ) ;
@@ -634,6 +635,107 @@ impl LowerTraitRef for TraitRef {
634635 }
635636}
636637
638+ trait LowerTraitBound {
639+ fn lower_trait_bound ( & self , env : & Env ) -> Result < ir:: TraitBound > ;
640+ }
641+
642+ impl LowerTraitBound for TraitBound {
643+ fn lower_trait_bound ( & self , env : & Env ) -> Result < ir:: TraitBound > {
644+ let id = match env. lookup ( self . trait_name ) ? {
645+ NameLookup :: Type ( id) => id,
646+ NameLookup :: Parameter ( _) => bail ! ( ErrorKind :: NotTrait ( self . trait_name) ) ,
647+ } ;
648+
649+ let k = env. type_kind ( id) ;
650+ if k. sort != ir:: TypeSort :: Trait {
651+ bail ! ( ErrorKind :: NotTrait ( self . trait_name) ) ;
652+ }
653+
654+ let parameters = self . args_no_self
655+ . iter ( )
656+ . map ( |a| Ok ( a. lower ( env) ?) )
657+ . collect :: < Result < Vec < _ > > > ( ) ?;
658+
659+ if parameters. len ( ) != k. binders . len ( ) {
660+ bail ! (
661+ "wrong number of parameters, expected `{:?}`, got `{:?}`" ,
662+ k. binders. len( ) ,
663+ parameters. len( )
664+ )
665+ }
666+
667+ for ( binder, param) in k. binders . binders . iter ( ) . zip ( parameters. iter ( ) ) {
668+ check_type_kinds ( "incorrect kind for trait parameter" , binder, param) ?;
669+ }
670+
671+ Ok ( ir:: TraitBound {
672+ trait_id : id,
673+ args_no_self : parameters,
674+ } )
675+ }
676+ }
677+
678+ trait LowerInlineBound {
679+ fn lower ( & self , env : & Env ) -> Result < ir:: InlineBound > ;
680+ }
681+
682+ impl LowerInlineBound for TraitBound {
683+ fn lower ( & self , env : & Env ) -> Result < ir:: InlineBound > {
684+ Ok ( ir:: InlineBound :: TraitBound ( self . lower_trait_bound ( & env) ?) )
685+ }
686+ }
687+
688+ impl LowerInlineBound for ProjectionEqBound {
689+ fn lower ( & self , env : & Env ) -> Result < ir:: InlineBound > {
690+ let trait_bound = self . trait_bound . lower_trait_bound ( env) ?;
691+ let info = match env. associated_ty_infos . get ( & ( trait_bound. trait_id , self . name . str ) ) {
692+ Some ( info) => info,
693+ None => bail ! ( "no associated type `{}` defined in trait" , self . name. str ) ,
694+ } ;
695+ let args: Vec < _ > = try!( self . args . iter ( ) . map ( |a| a. lower ( env) ) . collect ( ) ) ;
696+
697+ if args. len ( ) != info. addl_parameter_kinds . len ( ) {
698+ bail ! (
699+ "wrong number of parameters for associated type (expected {}, got {})" ,
700+ info. addl_parameter_kinds. len( ) ,
701+ args. len( )
702+ )
703+ }
704+
705+ for ( param, arg) in info. addl_parameter_kinds . iter ( ) . zip ( args. iter ( ) ) {
706+ check_type_kinds ( "incorrect kind for associated type parameter" , param, arg) ?;
707+ }
708+
709+ Ok ( ir:: InlineBound :: ProjectionEqBound ( ir:: ProjectionEqBound {
710+ trait_bound,
711+ associated_ty_id : info. id ,
712+ parameters : args,
713+ value : self . value . lower ( env) ?,
714+ } ) )
715+ }
716+ }
717+
718+ impl LowerInlineBound for InlineBound {
719+ fn lower ( & self , env : & Env ) -> Result < ir:: InlineBound > {
720+ match self {
721+ InlineBound :: TraitBound ( b) => b. lower ( & env) ,
722+ InlineBound :: ProjectionEqBound ( b) => b. lower ( & env) ,
723+ }
724+ }
725+ }
726+
727+ trait LowerInlineBounds {
728+ fn lower ( & self , env : & Env ) -> Result < Vec < ir:: InlineBound > > ;
729+ }
730+
731+ impl LowerInlineBounds for Vec < InlineBound > {
732+ fn lower ( & self , env : & Env ) -> Result < Vec < ir:: InlineBound > > {
733+ self . iter ( )
734+ . map ( |b| b. lower ( env) )
735+ . collect ( )
736+ }
737+ }
738+
637739trait LowerPolarizedTraitRef {
638740 fn lower ( & self , env : & Env ) -> Result < ir:: PolarizedTraitRef > ;
639741}
0 commit comments