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