From 2c3267e8a4962370e6b80d66d03b9af764a024d2 Mon Sep 17 00:00:00 2001 From: Giulio Agostini Date: Tue, 7 Jul 2026 07:23:44 +0200 Subject: [PATCH] Remove unused imports in parser.rs Box return values in LoxError - Box Return.value in LoxError - Deref boxed value when assigning to ret - Box value when constructing Return variants - Update Cargo.toml edition to 2024 and add nightly toolchain --- Cargo.toml | 2 +- rust-toolchain.toml | 2 ++ src/backend/interpreter.rs | 8 ++++---- src/common/lox_result.rs | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) create mode 100644 rust-toolchain.toml diff --git a/Cargo.toml b/Cargo.toml index 3d27665..9ef8f3f 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rlox" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..5d56faf --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly" diff --git a/src/backend/interpreter.rs b/src/backend/interpreter.rs index 00969ef..3bfe552 100755 --- a/src/backend/interpreter.rs +++ b/src/backend/interpreter.rs @@ -112,7 +112,7 @@ impl Interpreter { match self.eval_expr(body) { Ok(val) => ret = val, Err(LoxError::Return { value, .. }) => { - ret = value; + ret = *value; break; } Err(err) => return Err(err), @@ -136,7 +136,7 @@ impl Interpreter { match self.eval_expr(body) { Ok(val) => ret = val, Err(LoxError::Return { value, .. }) => { - ret = value; + ret = *value; break; } Err(err) => return Err(err), @@ -217,7 +217,7 @@ impl Interpreter { // Execute the function body let result = match self.eval_expr(&func.body) { Ok(value) => Ok(value), - Err(LoxError::Return { value, .. }) => Ok(value), + Err(LoxError::Return { value, .. }) => Ok(*value), Err(err) => Err(err), }; @@ -328,7 +328,7 @@ impl Interpreter { result = Err(LoxError::Return { source_slice: statement.source_slice.clone(), - value, + value: Box::new(value), return_label: "Hi".to_string(), }); break; diff --git a/src/common/lox_result.rs b/src/common/lox_result.rs index 602d7c3..f374e8e 100755 --- a/src/common/lox_result.rs +++ b/src/common/lox_result.rs @@ -28,7 +28,7 @@ pub enum LoxError { }, Return { source_slice: SourceSlice, - value: BaseValue, + value: Box, return_label: String, }, }