Skip to content

Commit 4b19873

Browse files
committed
Label mismatched parameters at the def site for foreign functions.
1 parent 79f82ad commit 4b19873

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -2641,8 +2641,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
26412641
}
26422642

26432643
/// Returns the parameters of a function, with their generic parameters if those are the full
2644-
/// type of that parameter. Returns `None` if the function has no generics or the body is
2645-
/// unavailable (eg is an instrinsic).
2644+
/// type of that parameter.
2645+
///
2646+
/// Returns `None` if the body is not a named function (e.g. a closure).
26462647
fn get_hir_param_info(
26472648
&self,
26482649
def_id: DefId,
@@ -2667,6 +2668,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
26672668
kind: hir::ItemKind::Fn { sig, generics, body, .. },
26682669
..
26692670
}) => (sig, generics, Some(body), None),
2671+
hir::Node::ForeignItem(&hir::ForeignItem {
2672+
kind: hir::ForeignItemKind::Fn(sig, params, generics),
2673+
..
2674+
}) => (sig, generics, None, Some(params)),
26702675
_ => return None,
26712676
};
26722677

tests/ui/argument-suggestions/extern-fn-arg-names.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ note: function defined here
1414
--> $DIR/extern-fn-arg-names.rs:2:8
1515
|
1616
LL | fn dstfn(src: i32, dst: err);
17-
| ^^^^^
17+
| ^^^^^ ---
1818
help: provide the argument
1919
|
2020
LL | dstfn(1, /* dst */);

tests/ui/fn/param-mismatch-foreign.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
extern "C" {
2+
fn foo(x: i32, y: u32, z: i32);
3+
//~^ NOTE function defined here
4+
}
5+
6+
fn main() {
7+
foo(1i32, 2i32);
8+
//~^ ERROR this function takes 3 arguments but 2 arguments were supplied
9+
//~| NOTE argument #2 of type `u32` is missing
10+
//~| HELP provide the argument
11+
}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0061]: this function takes 3 arguments but 2 arguments were supplied
2+
--> $DIR/param-mismatch-foreign.rs:7:5
3+
|
4+
LL | foo(1i32, 2i32);
5+
| ^^^ ---- argument #2 of type `u32` is missing
6+
|
7+
note: function defined here
8+
--> $DIR/param-mismatch-foreign.rs:2:8
9+
|
10+
LL | fn foo(x: i32, y: u32, z: i32);
11+
| ^^^ -
12+
help: provide the argument
13+
|
14+
LL | foo(1i32, /* u32 */, 2i32);
15+
| ~~~~~~~~~~~~~~~~~~~~~~~
16+
17+
error: aborting due to 1 previous error
18+
19+
For more information about this error, try `rustc --explain E0061`.

0 commit comments

Comments
 (0)