Start improving mutable capture error

This commit is contained in:
132ikl
2025-03-03 18:20:56 -05:00
parent 9eaa8908d2
commit 9ed2b2df00
3 changed files with 24 additions and 5 deletions

View File

@ -6522,7 +6522,12 @@ pub fn discover_captures_in_expr(
if !seen.contains(var_id) {
if let Some(variable) = working_set.get_variable_if_possible(*var_id) {
if variable.mutable {
return Err(ParseError::CaptureOfMutableVar(*span));
let var_name = working_set.get_span_contents(*span);
return Err(ParseError::CaptureOfMutableVar {
var: String::from_utf8_lossy(var_name).into_owned(),
var_span: span.before(),
closure_span: block.span,
});
}
}
}