@@ -50,18 +50,23 @@ pub fn type_check_func(interner: &mut NodeInterner, func_id: FuncId) -> Vec<Type
5050 type_checker. current_function = Some ( func_id) ;
5151
5252 let meta = type_checker. interner . function_meta ( & func_id) ;
53+ let parameters = meta. parameters . clone ( ) ;
54+ let expected_return_type = meta. return_type . clone ( ) ;
55+ let expected_trait_constraints = meta. trait_constraints . clone ( ) ;
56+ let name_span = meta. name . location . span ;
57+
5358 let mut errors = Vec :: new ( ) ;
5459
5560 // Temporarily add any impls in this function's `where` clause to scope
56- for constraint in & meta . trait_constraints {
61+ for constraint in & expected_trait_constraints {
5762 let object = constraint. typ . clone ( ) ;
5863 let trait_id = constraint. trait_id ;
5964
6065 if !type_checker. interner . add_assumed_trait_implementation ( object, trait_id) {
6166 if let Some ( the_trait) = type_checker. interner . try_get_trait ( trait_id) {
6267 let trait_name = the_trait. name . to_string ( ) ;
6368 let typ = constraint. typ . clone ( ) ;
64- let span = meta . name . location . span ;
69+ let span = name_span ;
6570 errors. push ( TypeCheckError :: UnneededTraitConstraint { trait_name, typ, span } ) ;
6671 }
6772 }
@@ -70,7 +75,7 @@ pub fn type_check_func(interner: &mut NodeInterner, func_id: FuncId) -> Vec<Type
7075 // Bind each parameter to its annotated type.
7176 // This is locally obvious, but it must be bound here so that the
7277 // Definition object of the parameter in the NodeInterner is given the correct type.
73- for param in meta . parameters . into_iter ( ) {
78+ for param in parameters {
7479 type_checker. bind_pattern ( & param. 0 , param. 1 ) ;
7580 }
7681
@@ -93,7 +98,7 @@ pub fn type_check_func(interner: &mut NodeInterner, func_id: FuncId) -> Vec<Type
9398 errors. append ( & mut type_checker. errors ) ;
9499
95100 // Now remove all the `where` clause constraints we added
96- for constraint in & meta . trait_constraints {
101+ for constraint in & expected_trait_constraints {
97102 interner. remove_assumed_trait_implementations_for_trait ( constraint. trait_id ) ;
98103 }
99104
@@ -107,7 +112,7 @@ pub fn type_check_func(interner: &mut NodeInterner, func_id: FuncId) -> Vec<Type
107112 expected : declared_return_type. clone ( ) ,
108113 actual : function_last_type,
109114 span : func_span,
110- source : Source :: Return ( meta . return_type , expr_span) ,
115+ source : Source :: Return ( expected_return_type , expr_span) ,
111116 } ;
112117 errors. push ( error) ;
113118 }
@@ -122,7 +127,7 @@ pub fn type_check_func(interner: &mut NodeInterner, func_id: FuncId) -> Vec<Type
122127 expected : declared_return_type. clone ( ) ,
123128 actual : function_last_type. clone ( ) ,
124129 span : func_span,
125- source : Source :: Return ( meta . return_type , expr_span) ,
130+ source : Source :: Return ( expected_return_type , expr_span) ,
126131 } ;
127132
128133 if empty_function {
0 commit comments