Skip to content

Commit 8be8f60

Browse files
committed
Do not allow extern unsized_fn_param
1 parent f96442b commit 8be8f60

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

compiler/rustc_hir_typeck/src/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub(super) fn check_fn<'a, 'tcx>(
8383
}
8484

8585
// Check that argument is Sized.
86-
if !params_can_be_unsized {
86+
if !params_can_be_unsized || matches!(param_ty.kind(), ty::Foreign(..)) {
8787
fcx.require_type_is_sized(
8888
param_ty,
8989
param.pat.span,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// https://github.com/rust-lang/rust/issues/123887
2+
// Do not ICE on unsized extern parameter
3+
//@ compile-flags: -Clink-dead-code --emit=link
4+
#![feature(extern_types, unsized_fn_params)]
5+
6+
extern "C" {
7+
type ExternType;
8+
}
9+
10+
fn f(_: ExternType) {} //~ ERROR the size for values of type `ExternType` cannot be known at compilation time
11+
12+
fn main() {}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0277]: the size for values of type `ExternType` cannot be known at compilation time
2+
--> $DIR/extern-parameter-issue-123887.rs:10:6
3+
|
4+
LL | fn f(_: ExternType) {}
5+
| ^ doesn't have a size known at compile-time
6+
|
7+
= help: the trait `Sized` is not implemented for `ExternType`
8+
help: function arguments must have a statically known size, borrowed types always have a known size
9+
|
10+
LL | fn f(_: &ExternType) {}
11+
| +
12+
13+
error: aborting due to 1 previous error
14+
15+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)