Hello.
While working on something, I came across this problem:
fn visit_arraynode(&mut self, node: Node, context: &mut Context, exprs: Vec<Node>) -> RTResult {
let mut res = RTResult {exception: InterpreterException {failed: false, name: "".to_string(), msg: "".to_string(), ucmsg: "".to_string(), start: node.start.clone(), end: node.end.clone(), context: Some(context.clone())}, value: Type {value: Value::NullType, start: node.start.clone(), end: node.end.clone(), context: context.clone()}};
let mut arraytype = None;
let mut values = vec![];
let mut expr: Type;
for i in exprs {
let expr = res.register(self.visit(i, context));
if res.exception.failed {
return res;
}
match arraytype {
Some(_) => {},
None => {
arraytype = Some(expr.clone().gettype());
}
}
values.push(expr.clone());
}
match arraytype {
Some(arraytype) => {
return res.success(Type {
value: Value::ArrayType(values.clone(), arraytype.to_string()),
start: node.start, end: node.end, context: context.clone()
});
},
None => {
let arraytype = Type {
value: Value::NullType,
start: node.clone().start, end: node.clone().end, context: context.clone()
};
return res.success(Type {
value: Value::ArrayType(values, arraytype.gettype().to_string()),
start: node.clone().start, end: node.clone().end, context: context.clone()
});
}
}
}
On the line arraytype = Some(expr.clone().gettype());
it complains that expr.clone()
is dropped while borrowed. What does this mean and how can I fix it?
Here is the error:
error[E0716]: temporary value dropped while borrowed
--> src/version/interpreter.rs:160:38
|
160 | arraytype = Some(expr.clone().gettype());
| ^^^^^^^^^^^^ - temporary value is freed at the end of this statement
| |
| creates a temporary which is freed while still in use
...
167 | match arraytype {
| --------- borrow later used here
|
= note: consider using a `let` binding to create a longer lived value