<p dir="auto">The following code <a href="https://play.rust-lang.org/?gist=e60dc1ef64e84de09aae&amp;version=nightly" rel="nofollow">ICEs in nightly on play.rust-lang.org</a>, as well as in 1.0 stable:</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="extern {
    fn foo(x: Option&lt;str&gt;);
}
fn main() {
}"><pre class="notranslate"><span class="pl-k">extern</span> <span class="pl-kos">{</span>
    <span class="pl-k">fn</span> <span class="pl-en">foo</span><span class="pl-kos">(</span><span class="pl-s1">x</span><span class="pl-kos">:</span> <span class="pl-smi">Option</span><span class="pl-kos">&lt;</span><span class="pl-smi">str</span><span class="pl-kos">&gt;</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>
<span class="pl-k">fn</span> <span class="pl-en">main</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
<span class="pl-kos">}</span></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;anon&gt;: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
&lt;anon&gt;:2     fn foo(x: Option&lt;str&gt;);
                       ^~~~~~~~~~~
&lt;anon&gt;:2:5: 2:28 warning: foreign function is never used: `foo`, #[warn(dead_code)] on by default
&lt;anon&gt;:2     fn foo(x: Option&lt;str&gt;);
             ^~~~~~~~~~~~~~~~~~~~~~~
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&lt;str&gt; for ty=core::option::Option&lt;str&gt;', /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_trans/trans/type_of.rs:354"><pre class="notranslate"><code class="notranslate">&lt;anon&gt;: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
&lt;anon&gt;:2     fn foo(x: Option&lt;str&gt;);
                       ^~~~~~~~~~~
&lt;anon&gt;:2:5: 2:28 warning: foreign function is never used: `foo`, #[warn(dead_code)] on by default
&lt;anon&gt;:2     fn foo(x: Option&lt;str&gt;);
             ^~~~~~~~~~~~~~~~~~~~~~~
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&lt;str&gt; for ty=core::option::Option&lt;str&gt;', /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_trans/trans/type_of.rs:354
</code></pre></div>
<p dir="auto">Between this and <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="77766696" data-permission-text="Title is private" data-url="https://github.com/rust-lang/rust/issues/25581" data-hovercard-type="issue" data-hovercard-url="/rust-lang/rust/issues/25581/hovercard" href="https://github.com/rust-lang/rust/issues/25581">#25581</a>, I'm increasingly believing that Rust should firmly disallow non-C-compatible types in <code class="notranslate">extern</code> functions, not merely lint on them. <code class="notranslate">extern "C"</code> means to use the C ABI, and there <em>is no</em> C ABI support for passing slices, <code class="notranslate">str</code>s, etc. around.</p>
<p dir="auto">We don't check that types in method signatures are well-formed, or even when they are Sized. I mean, this compiles:</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="pub struct U&lt;T: Send+Sync+Copy+::std::fmt::Display&gt;(*const T);

pub trait Trait { }

pub trait OtherTrait {
    fn f(self, u: U&lt;Trait&gt;);
    fn g(self, u: [u8]);
}

impl OtherTrait for () {
    fn f(self, u: U&lt;Trait&gt;) { }
    fn g(self, ref u: [u8]) {}
}

fn main () {}"><pre class="notranslate"><span class="pl-k">pub</span> <span class="pl-k">struct</span> <span class="pl-smi">U</span><span class="pl-kos">&lt;</span><span class="pl-smi">T</span><span class="pl-kos">:</span> <span class="pl-smi">Send</span>+<span class="pl-smi">Sync</span>+<span class="pl-smi">Copy</span>+<span class="pl-kos">::</span>std<span class="pl-kos">::</span>fmt<span class="pl-kos">::</span><span class="pl-smi">Display</span><span class="pl-kos">&gt;</span><span class="pl-kos">(</span><span class="pl-c1">*</span><span class="pl-k">const</span> <span class="pl-smi">T</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-k">pub</span> <span class="pl-k">trait</span> <span class="pl-smi">Trait</span> <span class="pl-kos">{</span> <span class="pl-kos">}</span>

<span class="pl-k">pub</span> <span class="pl-k">trait</span> <span class="pl-smi">OtherTrait</span> <span class="pl-kos">{</span>
    <span class="pl-k">fn</span> <span class="pl-en">f</span><span class="pl-kos">(</span><span class="pl-smi">self</span><span class="pl-kos">,</span> <span class="pl-s1">u</span><span class="pl-kos">:</span> <span class="pl-smi">U</span><span class="pl-kos">&lt;</span><span class="pl-smi">Trait</span><span class="pl-kos">&gt;</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">fn</span> <span class="pl-en">g</span><span class="pl-kos">(</span><span class="pl-smi">self</span><span class="pl-kos">,</span> <span class="pl-s1">u</span><span class="pl-kos">:</span> <span class="pl-kos">[</span><span class="pl-smi">u8</span><span class="pl-kos">]</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">impl</span> <span class="pl-smi">OtherTrait</span> <span class="pl-k">for</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">fn</span> <span class="pl-en">f</span><span class="pl-kos">(</span><span class="pl-smi">self</span><span class="pl-kos">,</span> <span class="pl-s1">u</span><span class="pl-kos">:</span> <span class="pl-smi">U</span><span class="pl-kos">&lt;</span><span class="pl-smi">Trait</span><span class="pl-kos">&gt;</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-kos">}</span>
    <span class="pl-k">fn</span> <span class="pl-en">g</span><span class="pl-kos">(</span><span class="pl-smi">self</span><span class="pl-kos">,</span> <span class="pl-k">ref</span> u<span class="pl-kos">:</span> <span class="pl-kos">[</span><span class="pl-smi">u8</span><span class="pl-kos">]</span><span class="pl-kos">)</span> <span class="pl-kos">{</span><span class="pl-kos">}</span>
<span class="pl-kos">}</span>

<span class="pl-k">fn</span> <span class="pl-en">main</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span><span class="pl-kos">}</span></pre></div>