Update closure errors to emit context for FnMut

It now handles both FnMut and FnOnce case.
This commit is contained in:
Tommy Ip 2017-06-06 09:06:56 +01:00
parent 9cbb5f9a24
commit 94c808c1d3

View File

@ -657,13 +657,18 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
};
if let Some(tables) = infer_tables {
if let Some(&(ty::ClosureKind::FnOnce, Some((span, name)))) =
tables.closure_kinds.get(&node_id)
{
err.span_note(
span,
&format!("closure is `FnOnce` because it moves the \
variable `{}` out of its environment", name));
match tables.closure_kinds.get(&node_id) {
Some(&(ty::ClosureKind::FnOnce, Some((span, name)))) => {
err.span_note(span, &format!(
"closure is `FnOnce` because it moves the \
variable `{}` out of its environment", name));
},
Some(&(ty::ClosureKind::FnMut, Some((span, name)))) => {
err.span_note(span, &format!(
"closure is `FnMut` because it mutates the \
variable `{}` here", name));
},
_ => {}
}
} else {
err.span_note(