Skip to content

Commit 00b6d0b

Browse files
authored
Unrolled build for rust-lang#136651
Rollup merge of rust-lang#136651 - Jarcho:fn_ctxt3, r=compiler-errors Label mismatched parameters at the def site for foreign functions Nice and simple. Adds parameter marking for the only missing definition type. r? ``@compiler-errors``
2 parents d2f335d + 2dd6dc1 commit 00b6d0b

File tree

8 files changed

+48
-12
lines changed

8 files changed

+48
-12
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+9-3
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

@@ -2700,7 +2705,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
27002705
))
27012706
}
27022707
(None, Some(params)) => {
2703-
let params = params.get(is_method as usize..)?;
2708+
let params =
2709+
params.get(is_method as usize..params.len() - sig.decl.c_variadic as usize)?;
27042710
debug_assert_eq!(params.len(), fn_inputs.len());
27052711
Some((
27062712
fn_inputs.zip(params.iter().map(|param| FnParam::Name(param))).collect(),

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/c-variadic/variadic-ffi-1.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ note: function defined here
1414
--> $DIR/variadic-ffi-1.rs:15:8
1515
|
1616
LL | fn foo(f: isize, x: u8, ...);
17-
| ^^^
17+
| ^^^ - -
1818
help: provide the arguments
1919
|
2020
LL | foo(/* isize */, /* u8 */);
@@ -30,7 +30,7 @@ note: function defined here
3030
--> $DIR/variadic-ffi-1.rs:15:8
3131
|
3232
LL | fn foo(f: isize, x: u8, ...);
33-
| ^^^
33+
| ^^^ -
3434
help: provide the argument
3535
|
3636
LL | foo(1, /* u8 */);

tests/ui/error-codes/E0060.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ note: function defined here
88
--> $DIR/E0060.rs:2:8
99
|
1010
LL | fn printf(_: *const u8, ...) -> u32;
11-
| ^^^^^^
11+
| ^^^^^^ -
1212
help: provide the argument
1313
|
1414
LL | unsafe { printf(/* *const u8 */); }

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`.

tests/ui/mismatched_types/issue-26480.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ note: function defined here
1313
--> $DIR/issue-26480.rs:2:8
1414
|
1515
LL | fn write(fildes: i32, buf: *const i8, nbyte: u64) -> i64;
16-
| ^^^^^
16+
| ^^^^^ -----
1717
= note: this error originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info)
1818
help: you can convert a `usize` to a `u64` and panic if the converted value doesn't fit
1919
|

tests/ui/suggestions/suggest-null-ptr.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ note: function defined here
1212
--> $DIR/suggest-null-ptr.rs:7:8
1313
|
1414
LL | fn foo(ptr: *const u8);
15-
| ^^^
15+
| ^^^ ---
1616
help: if you meant to create a null pointer, use `std::ptr::null()`
1717
|
1818
LL | foo(std::ptr::null());
@@ -32,7 +32,7 @@ note: function defined here
3232
--> $DIR/suggest-null-ptr.rs:9:8
3333
|
3434
LL | fn foo_mut(ptr: *mut u8);
35-
| ^^^^^^^
35+
| ^^^^^^^ ---
3636
help: if you meant to create a null pointer, use `std::ptr::null_mut()`
3737
|
3838
LL | foo_mut(std::ptr::null_mut());
@@ -52,7 +52,7 @@ note: function defined here
5252
--> $DIR/suggest-null-ptr.rs:11:8
5353
|
5454
LL | fn usize(ptr: *const usize);
55-
| ^^^^^
55+
| ^^^^^ ---
5656
help: if you meant to create a null pointer, use `std::ptr::null()`
5757
|
5858
LL | usize(std::ptr::null());
@@ -72,7 +72,7 @@ note: function defined here
7272
--> $DIR/suggest-null-ptr.rs:13:8
7373
|
7474
LL | fn usize_mut(ptr: *mut usize);
75-
| ^^^^^^^^^
75+
| ^^^^^^^^^ ---
7676
help: if you meant to create a null pointer, use `std::ptr::null_mut()`
7777
|
7878
LL | usize_mut(std::ptr::null_mut());

0 commit comments

Comments
 (0)