Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Feb 9, 2020
1 parent 109d5c1 commit d51f2bd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
13 changes: 7 additions & 6 deletions src/librustc_mir/borrow_check/diagnostics/mutability_errors.rs
Expand Up @@ -447,7 +447,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {

/// Targetted error when encountering an `FnMut` closure where an `Fn` closure was expected.
fn expected_fn_found_fn_mut_call(&self, err: &mut DiagnosticBuilder<'_>, sp: Span, act: &str) {
err.span_label(sp, format!("cannot {ACT}", ACT = act));
err.span_label(sp, format!("cannot {}", act));

let hir = self.infcx.tcx.hir();
let closure_id = hir.as_local_hir_id(self.mir_def_id).unwrap();
Expand Down Expand Up @@ -528,13 +528,14 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
kind: hir::ImplItemKind::Method(sig, _),
..
}) => {
err.span_label(ident.span, "you might have to change this...");
err.span_label(sig.decl.output.span(), "...to return `FnMut` instead of `Fn`");
err.span_label(ident.span, "");
err.span_label(
sig.decl.output.span(),
"change this to return `FnMut` instead of `Fn`",
);
err.span_label(self.body.span, "in this closure");
}
parent => {
err.note(&format!("parent {:?}", parent));
}
_ => {}
}
}
}
Expand Down
8 changes: 2 additions & 6 deletions src/test/ui/borrowck/borrow-immutable-upvar-mutation.stderr
Expand Up @@ -68,9 +68,7 @@ error[E0594]: cannot assign to `x`, as it is a captured variable in a `Fn` closu
--> $DIR/borrow-immutable-upvar-mutation.rs:43:9
|
LL | fn foo() -> Box<dyn Fn() -> usize> {
| --- ---------------------- ...to return `FnMut` instead of `Fn`
| |
| you might have to change this...
| --- ---------------------- change this to return `FnMut` instead of `Fn`
LL | let mut x = 0;
LL | Box::new(move || {
| ______________-
Expand All @@ -84,9 +82,7 @@ error[E0594]: cannot assign to `x`, as it is a captured variable in a `Fn` closu
--> $DIR/borrow-immutable-upvar-mutation.rs:51:9
|
LL | fn bar() -> impl Fn() -> usize {
| --- ------------------ ...to return `FnMut` instead of `Fn`
| |
| you might have to change this...
| --- ------------------ change this to return `FnMut` instead of `Fn`
LL | let mut x = 0;
LL | / move || {
LL | | x += 1;
Expand Down

0 comments on commit d51f2bd

Please sign in to comment.