Closed
Description
The following code ICEs in nightly on play.rust-lang.org, as well as in 1.0 stable:
extern {
fn foo(x: Option<str>);
}
fn main() {
}
<anon>:2:15: 2:26 warning: found type without foreign-function-safe representation annotation in foreign module, consider adding a #[repr(...)] attribute to the type, #[warn(improper_ctypes)] on by default
<anon>:2 fn foo(x: Option<str>);
^~~~~~~~~~~
<anon>:2:5: 2:28 warning: foreign function is never used: `foo`, #[warn(dead_code)] on by default
<anon>:2 fn foo(x: Option<str>);
^~~~~~~~~~~~~~~~~~~~~~~
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'Unexpected type returned from struct_tail: core::option::Option<str> for ty=core::option::Option<str>', /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_trans/trans/type_of.rs:354
Between this and #25581, I'm increasingly believing that Rust should firmly disallow non-C-compatible types in extern
functions, not merely lint on them. extern "C"
means to use the C ABI, and there is no C ABI support for passing slices, str
s, etc. around.