Skip to content

Commit 94c808c

Browse files
committed
Update closure errors to emit context for FnMut
It now handles both FnMut and FnOnce case.
1 parent 9cbb5f9 commit 94c808c

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/librustc/traits/error_reporting.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -657,13 +657,18 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
657657
};
658658

659659
if let Some(tables) = infer_tables {
660-
if let Some(&(ty::ClosureKind::FnOnce, Some((span, name)))) =
661-
tables.closure_kinds.get(&node_id)
662-
{
663-
err.span_note(
664-
span,
665-
&format!("closure is `FnOnce` because it moves the \
666-
variable `{}` out of its environment", name));
660+
match tables.closure_kinds.get(&node_id) {
661+
Some(&(ty::ClosureKind::FnOnce, Some((span, name)))) => {
662+
err.span_note(span, &format!(
663+
"closure is `FnOnce` because it moves the \
664+
variable `{}` out of its environment", name));
665+
},
666+
Some(&(ty::ClosureKind::FnMut, Some((span, name)))) => {
667+
err.span_note(span, &format!(
668+
"closure is `FnMut` because it mutates the \
669+
variable `{}` here", name));
670+
},
671+
_ => {}
667672
}
668673
} else {
669674
err.span_note(

0 commit comments

Comments
 (0)