Skip to content

Commit 262644d

Browse files
And for closures
1 parent 20121fa commit 262644d

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
746746
format!("arguments to this {} are incorrect", call_name),
747747
);
748748
// Call out where the function is defined
749-
self.label_fn_like(&mut err, fn_def_id, callee_ty, Some(expected_idx.as_usize()), is_method);
749+
self.label_fn_like(
750+
&mut err,
751+
fn_def_id,
752+
callee_ty,
753+
Some(expected_idx.as_usize()),
754+
is_method,
755+
);
750756
err.emit();
751757
return;
752758
}
@@ -1896,6 +1902,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18961902

18971903
let def_kind = self.tcx.def_kind(def_id);
18981904
err.span_note(spans, &format!("{} defined here", def_kind.descr(def_id)));
1905+
} else if let Some(hir::Node::Expr(e)) = self.tcx.hir().get_if_local(def_id)
1906+
&& let hir::ExprKind::Closure(hir::Closure { body, .. }) = &e.kind
1907+
{
1908+
let param = expected_idx
1909+
.and_then(|expected_idx| self.tcx.hir().body(*body).params.get(expected_idx));
1910+
let (kind, span) = if let Some(param) = param {
1911+
("closure parameter", param.span)
1912+
} else {
1913+
("closure", self.tcx.def_span(def_id))
1914+
};
1915+
err.span_note(span, &format!("{} defined here", kind));
18991916
} else {
19001917
let def_kind = self.tcx.def_kind(def_id);
19011918
err.span_note(

src/test/ui/unboxed-closures/unboxed-closures-type-mismatch.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ LL | let z = f(1_usize, 2);
66
| |
77
| arguments to this function are incorrect
88
|
9-
note: closure defined here
10-
--> $DIR/unboxed-closures-type-mismatch.rs:4:17
9+
note: closure parameter defined here
10+
--> $DIR/unboxed-closures-type-mismatch.rs:4:18
1111
|
1212
LL | let mut f = |x: isize, y: isize| -> isize { x + y };
13-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13+
| ^^^^^^^^^
1414
help: change the type of the numeric literal from `usize` to `isize`
1515
|
1616
LL | let z = f(1_isize, 2);

0 commit comments

Comments
 (0)