Skip to content

Commit a04fe4d

Browse files
committed
Do not allow extern unsized_fn_param in Rust type
1 parent 8be8f60 commit a04fe4d

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

compiler/rustc_hir_typeck/src/check.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ pub(super) fn check_fn<'a, 'tcx>(
8383
}
8484

8585
// Check that argument is Sized.
86-
if !params_can_be_unsized || matches!(param_ty.kind(), ty::Foreign(..)) {
86+
let tail = fcx.tcx.struct_tail_with_normalize(param_ty, |ty| ty, || {});
87+
if !params_can_be_unsized || matches!(tail.kind(), ty::Foreign(..)) {
8788
fcx.require_type_is_sized(
8889
param_ty,
8990
param.pat.span,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
struct Wrapper<T: ?Sized>(T);
11+
fn f(_: Wrapper<ExternType>) {} //~ ERROR the size for values of type `ExternType` cannot be known at compilation time
12+
13+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0277]: the size for values of type `ExternType` cannot be known at compilation time
2+
--> $DIR/extern-parameter-issue-123887-wrapped.rs:11:6
3+
|
4+
LL | fn f(_: Wrapper<ExternType>) {}
5+
| ^ doesn't have a size known at compile-time
6+
|
7+
= help: within `Wrapper<ExternType>`, the trait `Sized` is not implemented for `ExternType`, which is required by `Wrapper<ExternType>: Sized`
8+
note: required because it appears within the type `Wrapper<ExternType>`
9+
--> $DIR/extern-parameter-issue-123887-wrapped.rs:10:8
10+
|
11+
LL | struct Wrapper<T: ?Sized>(T);
12+
| ^^^^^^^
13+
help: function arguments must have a statically known size, borrowed types always have a known size
14+
|
15+
LL | fn f(_: &Wrapper<ExternType>) {}
16+
| +
17+
18+
error: aborting due to 1 previous error
19+
20+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)