@@ -3,7 +3,7 @@ use std::collections::HashMap;
3
3
use chalk_parse:: ast:: * ;
4
4
use lalrpop_intern:: intern;
5
5
6
- use cast:: Cast ;
6
+ use cast:: { Cast , Caster } ;
7
7
use errors:: * ;
8
8
use ir;
9
9
@@ -167,6 +167,7 @@ impl LowerProgram for Program {
167
167
id : info. id ,
168
168
name : defn. name . str ,
169
169
parameter_kinds : parameter_kinds,
170
+ where_clauses : vec ! [ ] ,
170
171
} ) ;
171
172
}
172
173
}
@@ -725,8 +726,19 @@ impl<'k> LowerGoal<Env<'k>> for Goal {
725
726
g. lower_quantified ( env, ir:: QuantifierKind :: ForAll , ids) ,
726
727
Goal :: Exists ( ref ids, ref g) =>
727
728
g. lower_quantified ( env, ir:: QuantifierKind :: Exists , ids) ,
728
- Goal :: Implies ( ref wc, ref g) =>
729
- Ok ( Box :: new ( ir:: Goal :: Implies ( wc. lower ( env) ?, g. lower ( env) ?) ) ) ,
729
+ Goal :: Implies ( ref wc, ref g, elaborate) => {
730
+ let mut where_clauses = wc. lower ( env) ?;
731
+ if elaborate {
732
+ where_clauses = ir:: with_current_program ( |program| {
733
+ let program = program. expect ( "cannot elaborate without a program" ) ;
734
+ where_clauses. into_iter ( )
735
+ . flat_map ( |wc| wc. expanded ( program) )
736
+ . casted ( )
737
+ . collect ( )
738
+ } ) ;
739
+ }
740
+ Ok ( Box :: new ( ir:: Goal :: Implies ( where_clauses, g. lower ( env) ?) ) )
741
+ }
730
742
Goal :: And ( ref g1, ref g2) =>
731
743
Ok ( Box :: new ( ir:: Goal :: And ( g1. lower ( env) ?, g2. lower ( env) ?) ) ) ,
732
744
Goal :: Not ( ref g) =>
@@ -803,7 +815,7 @@ impl ir::ImplDatum {
803
815
. iter ( )
804
816
. cloned ( )
805
817
. flat_map ( |wc| wc. expanded ( program) )
806
- . map ( |wc| wc . cast ( ) )
818
+ . casted ( )
807
819
. collect ( ) ,
808
820
}
809
821
} ) ,
@@ -935,12 +947,13 @@ impl ir::StructDatum {
935
947
. iter ( )
936
948
. filter_map ( |pk| pk. as_ref ( ) . ty ( ) )
937
949
. cloned ( )
938
- . map ( |ty| ir:: WellFormed :: Ty ( ty) . cast ( ) ) ;
950
+ . map ( |ty| ir:: WellFormed :: Ty ( ty) )
951
+ . casted ( ) ;
939
952
940
953
let where_clauses = bound_datum. where_clauses . iter ( )
941
954
. cloned ( )
942
955
. flat_map ( |wc| wc. expanded ( program) )
943
- . map ( |wc| wc . cast ( ) ) ;
956
+ . casted ( ) ;
944
957
945
958
tys. chain ( where_clauses) . collect ( )
946
959
}
@@ -987,9 +1000,10 @@ impl ir::TraitDatum {
987
1000
. iter ( )
988
1001
. filter_map ( |pk| pk. as_ref ( ) . ty ( ) )
989
1002
. cloned ( )
990
- . map ( |ty| ir:: WellFormed :: Ty ( ty) . cast ( ) ) ;
1003
+ . map ( |ty| ir:: WellFormed :: Ty ( ty) )
1004
+ . casted ( ) ;
991
1005
992
- tys. chain ( where_clauses. iter ( ) . cloned ( ) . map ( |wc| wc . cast ( ) ) ) . collect ( )
1006
+ tys. chain ( where_clauses. iter ( ) . cloned ( ) . casted ( ) ) . collect ( )
993
1007
}
994
1008
}
995
1009
} ) ,
0 commit comments