diff --git a/compiler/passes/src/symbol_table/variable_scope.rs b/compiler/passes/src/symbol_table/variable_scope.rs index 8d9cc98099..d2b4693fdc 100644 --- a/compiler/passes/src/symbol_table/variable_scope.rs +++ b/compiler/passes/src/symbol_table/variable_scope.rs @@ -37,7 +37,7 @@ pub struct VariableScope<'a> { impl<'a> VariableScope<'a> { pub fn check_shadowing(&self, symbol: &Symbol) -> Result<()> { if let Some(var) = self.variables.get(symbol) { - Err(AstError::shadowed_variable(symbol, var.span).into()) + Err(AstError::shadowed_variable(symbol, &var.span).into()) } else if let Some(parent) = &self.parent { parent.check_shadowing(symbol) } else { diff --git a/compiler/passes/src/symbol_table/variable_symbol.rs b/compiler/passes/src/symbol_table/variable_symbol.rs index bcd2463206..c96aaffecb 100644 --- a/compiler/passes/src/symbol_table/variable_symbol.rs +++ b/compiler/passes/src/symbol_table/variable_symbol.rs @@ -41,7 +41,7 @@ impl Display for Declaration { #[derive(Clone, Debug, Eq, PartialEq)] pub struct VariableSymbol<'a> { pub type_: &'a Type, - pub span: &'a Span, + pub span: Span, pub declaration: Declaration, } diff --git a/compiler/passes/src/type_checker/check_expressions.rs b/compiler/passes/src/type_checker/check_expressions.rs index bcbccba8eb..c6c1274556 100644 --- a/compiler/passes/src/type_checker/check_expressions.rs +++ b/compiler/passes/src/type_checker/check_expressions.rs @@ -39,14 +39,14 @@ fn return_incorrect_type(t1: Option, t2: Option, expected: Option TypeChecker<'a> { - pub(crate) fn compare_expr_type(&mut self, expr: &Expression, expected: Option, span: &Span) -> Option { + pub(crate) fn compare_expr_type(&mut self, expr: &Expression, expected: Option, span: Span) -> Option { match expr { Expression::Identifier(ident) => { if let Some(var) = self.symbol_table.lookup_variable(&ident.name) { Some(self.assert_type(var.type_.clone(), expected, span)) } else { self.handler - .emit_err(TypeCheckerError::unknown_sym("variable", ident.name, span).into()); + .emit_err(TypeCheckerError::unknown_sym("variable", ident.name, &span).into()); None } } @@ -67,7 +67,7 @@ impl<'a> TypeChecker<'a> { if int.parse::().is_err() { self.handler - .emit_err(TypeCheckerError::invalid_int_value(int, "i8", value.span()).into()); + .emit_err(TypeCheckerError::invalid_int_value(int, "i8", &value.span()).into()); } } IntegerType::I16 => { @@ -80,7 +80,7 @@ impl<'a> TypeChecker<'a> { if int.parse::().is_err() { self.handler - .emit_err(TypeCheckerError::invalid_int_value(int, "i16", value.span()).into()); + .emit_err(TypeCheckerError::invalid_int_value(int, "i16", &value.span()).into()); } } IntegerType::I32 => { @@ -93,7 +93,7 @@ impl<'a> TypeChecker<'a> { if int.parse::().is_err() { self.handler - .emit_err(TypeCheckerError::invalid_int_value(int, "i32", value.span()).into()); + .emit_err(TypeCheckerError::invalid_int_value(int, "i32", &value.span()).into()); } } IntegerType::I64 => { @@ -106,7 +106,7 @@ impl<'a> TypeChecker<'a> { if int.parse::().is_err() { self.handler - .emit_err(TypeCheckerError::invalid_int_value(int, "i64", value.span()).into()); + .emit_err(TypeCheckerError::invalid_int_value(int, "i64", &value.span()).into()); } } IntegerType::I128 => { @@ -119,25 +119,25 @@ impl<'a> TypeChecker<'a> { if int.parse::().is_err() { self.handler - .emit_err(TypeCheckerError::invalid_int_value(int, "i128", value.span()).into()); + .emit_err(TypeCheckerError::invalid_int_value(int, "i128", &value.span()).into()); } } IntegerType::U8 if str_content.parse::().is_err() => self .handler - .emit_err(TypeCheckerError::invalid_int_value(str_content, "u8", value.span()).into()), + .emit_err(TypeCheckerError::invalid_int_value(str_content, "u8", &value.span()).into()), IntegerType::U16 if str_content.parse::().is_err() => self .handler - .emit_err(TypeCheckerError::invalid_int_value(str_content, "u16", value.span()).into()), + .emit_err(TypeCheckerError::invalid_int_value(str_content, "u16", &value.span()).into()), IntegerType::U32 if str_content.parse::().is_err() => self .handler - .emit_err(TypeCheckerError::invalid_int_value(str_content, "u32", value.span()).into()), + .emit_err(TypeCheckerError::invalid_int_value(str_content, "u32", &value.span()).into()), IntegerType::U64 if str_content.parse::().is_err() => self .handler - .emit_err(TypeCheckerError::invalid_int_value(str_content, "u64", value.span()).into()), + .emit_err(TypeCheckerError::invalid_int_value(str_content, "u64", &value.span()).into()), IntegerType::U128 if str_content.parse::().is_err() => self .handler - .emit_err(TypeCheckerError::invalid_int_value(str_content, "u128", value.span()).into()), + .emit_err(TypeCheckerError::invalid_int_value(str_content, "u128", &value.span()).into()), _ => {} } Some(self.assert_type(Type::IntegerType(*type_), expected, value.span())) @@ -195,7 +195,7 @@ impl<'a> TypeChecker<'a> { // But Type B was not a unsigned int. (Some(Type::IntegerType(_)), Some(t)) => { self.handler.emit_err( - TypeCheckerError::incorrect_pow_exponent_type("unsigned int", t, binary.right.span()) + TypeCheckerError::incorrect_pow_exponent_type("unsigned int", t, &binary.right.span()) .into(), ); } @@ -208,13 +208,13 @@ impl<'a> TypeChecker<'a> { // But Type B was not an int. (Some(Type::Field), Some(t)) => { self.handler.emit_err( - TypeCheckerError::incorrect_pow_exponent_type("int", t, binary.right.span()).into(), + TypeCheckerError::incorrect_pow_exponent_type("int", t, &binary.right.span()).into(), ); } // The base is some type thats not an int or field. (Some(t), _) => { self.handler - .emit_err(TypeCheckerError::incorrect_pow_base_type(t, binary.left.span()).into()); + .emit_err(TypeCheckerError::incorrect_pow_base_type(t, &binary.left.span()).into()); } _ => {} } @@ -261,7 +261,7 @@ impl<'a> TypeChecker<'a> { ) => self.negate = !self.negate, Some(t) => self .handler - .emit_err(TypeCheckerError::type_is_not_negatable(t, unary.inner.span()).into()), + .emit_err(TypeCheckerError::type_is_not_negatable(t, &unary.inner.span()).into()), _ => {} }; self.compare_expr_type(&unary.inner, expected, unary.inner.span()) @@ -283,7 +283,7 @@ impl<'a> TypeChecker<'a> { TypeCheckerError::incorrect_num_args_to_call( func.input.len(), call.arguments.len(), - call.span(), + &call.span(), ) .into(), ); @@ -303,7 +303,7 @@ impl<'a> TypeChecker<'a> { Some(ret) } else { self.handler - .emit_err(TypeCheckerError::unknown_sym("function", &ident.name, ident.span()).into()); + .emit_err(TypeCheckerError::unknown_sym("function", &ident.name, &ident.span()).into()); None } } diff --git a/compiler/passes/src/type_checker/check_statements.rs b/compiler/passes/src/type_checker/check_statements.rs index 21f8ef53ef..218f4bec3d 100644 --- a/compiler/passes/src/type_checker/check_statements.rs +++ b/compiler/passes/src/type_checker/check_statements.rs @@ -63,10 +63,10 @@ impl<'a> StatementVisitor<'a> for TypeChecker<'a> { match &var.declaration { Declaration::Const => self .handler - .emit_err(TypeCheckerError::cannont_assign_to_const_var(var_name, var.span).into()), + .emit_err(TypeCheckerError::cannont_assign_to_const_var(var_name, &var.span).into()), Declaration::Input(ParamMode::Constant) => self .handler - .emit_err(TypeCheckerError::cannont_assign_to_const_input(var_name, var.span).into()), + .emit_err(TypeCheckerError::cannont_assign_to_const_input(var_name, &var.span).into()), _ => {} } diff --git a/compiler/passes/src/type_checker/checker.rs b/compiler/passes/src/type_checker/checker.rs index 2039a66cdd..fa6d02116b 100644 --- a/compiler/passes/src/type_checker/checker.rs +++ b/compiler/passes/src/type_checker/checker.rs @@ -79,18 +79,18 @@ impl<'a> TypeChecker<'a> { } } - pub(crate) fn assert_type(&self, type_: Type, expected: Option, span: &Span) -> Type { + pub(crate) fn assert_type(&self, type_: Type, expected: Option, span: Span) -> Type { if let Some(expected) = expected { if type_ != expected { self.handler - .emit_err(TypeCheckerError::type_should_be(type_.clone(), expected, span).into()); + .emit_err(TypeCheckerError::type_should_be(type_.clone(), expected, &span).into()); } } type_ } - pub(crate) fn assert_one_of_types(&self, type_: Option, expected: &[Type], span: &Span) -> Option { + pub(crate) fn assert_one_of_types(&self, type_: Option, expected: &[Type], span: Span) -> Option { if let Some(type_) = type_.clone() { for t in expected.iter() { if &type_ == t { @@ -102,7 +102,7 @@ impl<'a> TypeChecker<'a> { TypeCheckerError::expected_one_type_of( expected.iter().map(|t| t.to_string() + ",").collect::(), type_, - span, + &span, ) .into(), ); @@ -111,15 +111,15 @@ impl<'a> TypeChecker<'a> { type_ } - pub(crate) fn assert_arith_type(&self, type_: Option, span: &Span) -> Option { + pub(crate) fn assert_arith_type(&self, type_: Option, span: Span) -> Option { self.assert_one_of_types(type_, ARITHMETIC_TYPES, span) } - pub(crate) fn assert_field_or_int_type(&self, type_: Option, span: &Span) -> Option { + pub(crate) fn assert_field_or_int_type(&self, type_: Option, span: Span) -> Option { self.assert_one_of_types(type_, FIELD_AND_INT_TYPES, span) } - pub(crate) fn assert_int_type(&self, type_: Option, span: &Span) -> Option { + pub(crate) fn assert_int_type(&self, type_: Option, span: Span) -> Option { self.assert_one_of_types(type_, INT_TYPES, span) } }