@@ -28,6 +28,11 @@ impl<'context> Elaborator<'context> {
2828 self . recover_generics ( |this| {
2929 this. current_trait = Some ( * trait_id) ;
3030
31+ let the_trait = this. interner . get_trait ( * trait_id) ;
32+ let self_typevar = the_trait. self_type_typevar . clone ( ) ;
33+ let self_type = Type :: TypeVariable ( self_typevar. clone ( ) ) ;
34+ this. self_type = Some ( self_type. clone ( ) ) ;
35+
3136 let resolved_generics = this. interner . get_trait ( * trait_id) . generics . clone ( ) ;
3237 this. add_existing_generics (
3338 & unresolved_trait. trait_def . generics ,
@@ -48,12 +53,15 @@ impl<'context> Elaborator<'context> {
4853 . add_trait_dependency ( DependencyId :: Trait ( bound. trait_id ) , * trait_id) ;
4954 }
5055
56+ this. interner . update_trait ( * trait_id, |trait_def| {
57+ trait_def. set_trait_bounds ( resolved_trait_bounds) ;
58+ trait_def. set_where_clause ( where_clause) ;
59+ } ) ;
60+
5161 let methods = this. resolve_trait_methods ( * trait_id, unresolved_trait) ;
5262
5363 this. interner . update_trait ( * trait_id, |trait_def| {
5464 trait_def. set_methods ( methods) ;
55- trait_def. set_trait_bounds ( resolved_trait_bounds) ;
56- trait_def. set_where_clause ( where_clause) ;
5765 } ) ;
5866 } ) ;
5967
@@ -94,7 +102,7 @@ impl<'context> Elaborator<'context> {
94102 parameters,
95103 return_type,
96104 where_clause,
97- body : _ ,
105+ body,
98106 is_unconstrained,
99107 visibility : _,
100108 is_comptime : _,
@@ -103,7 +111,6 @@ impl<'context> Elaborator<'context> {
103111 self . recover_generics ( |this| {
104112 let the_trait = this. interner . get_trait ( trait_id) ;
105113 let self_typevar = the_trait. self_type_typevar . clone ( ) ;
106- let self_type = Type :: TypeVariable ( self_typevar. clone ( ) ) ;
107114 let name_span = the_trait. name . span ( ) ;
108115
109116 this. add_existing_generic (
@@ -115,9 +122,12 @@ impl<'context> Elaborator<'context> {
115122 span : name_span,
116123 } ,
117124 ) ;
118- this. self_type = Some ( self_type. clone ( ) ) ;
119125
120126 let func_id = unresolved_trait. method_ids [ & name. 0 . contents ] ;
127+ let mut where_clause = where_clause. to_vec ( ) ;
128+
129+ // Attach any trait constraints on the trait to the function
130+ where_clause. extend ( unresolved_trait. trait_def . where_clause . clone ( ) ) ;
121131
122132 this. resolve_trait_function (
123133 trait_id,
@@ -127,6 +137,7 @@ impl<'context> Elaborator<'context> {
127137 parameters,
128138 return_type,
129139 where_clause,
140+ body,
130141 func_id,
131142 ) ;
132143
@@ -188,20 +199,22 @@ impl<'context> Elaborator<'context> {
188199 generics : & UnresolvedGenerics ,
189200 parameters : & [ ( Ident , UnresolvedType ) ] ,
190201 return_type : & FunctionReturnType ,
191- where_clause : & [ UnresolvedTraitConstraint ] ,
202+ where_clause : Vec < UnresolvedTraitConstraint > ,
203+ body : & Option < BlockExpression > ,
192204 func_id : FuncId ,
193205 ) {
194- let old_generic_count = self . generics . len ( ) ;
195-
196- self . scopes . start_function ( ) ;
206+ let body = match body {
207+ Some ( body) => body. clone ( ) ,
208+ None => BlockExpression { statements : Vec :: new ( ) } ,
209+ } ;
197210
198211 let kind = FunctionKind :: Normal ;
199212 let mut def = FunctionDefinition :: normal (
200213 name,
201214 is_unconstrained,
202215 generics,
203216 parameters,
204- & BlockExpression { statements : Vec :: new ( ) } ,
217+ body ,
205218 where_clause,
206219 return_type,
207220 ) ;
@@ -210,10 +223,6 @@ impl<'context> Elaborator<'context> {
210223
211224 let mut function = NoirFunction { kind, def } ;
212225 self . define_function_meta ( & mut function, func_id, Some ( trait_id) ) ;
213- self . elaborate_function ( func_id) ;
214- let _ = self . scopes . end_function ( ) ;
215- // Don't check the scope tree for unused variables, they can't be used in a declaration anyway.
216- self . generics . truncate ( old_generic_count) ;
217226 }
218227}
219228
0 commit comments