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
This commit is contained in:
Giulio Agostini
2026-07-07 07:23:44 +02:00
parent 2498b3b345
commit 2c3267e8a4
4 changed files with 8 additions and 6 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "rlox"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]
+2
View File
@@ -0,0 +1,2 @@
[toolchain]
channel = "nightly"
+4 -4
View File
@@ -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;
+1 -1
View File
@@ -28,7 +28,7 @@ pub enum LoxError {
},
Return {
source_slice: SourceSlice,
value: BaseValue,
value: Box<BaseValue>,
return_label: String,
},
}