Change:
<!-- Thank you for finding an Internal Compiler Error! If possible, try to provide a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for how to create smaller examples. -- at <details<summary<strongBacktrace</strong</summary<p</p</detailssearched nightlies: from nightly-2023-01-01 to nightly-2023-08-14 regressed nightly: nightly-2023-07-04 searched commit range: regressed commit: <details<summarybisected with <a href=''cargo-bisect-rustc</av0.6.6</summaryHost triple: x8664-unknown-linux-gnu Reproduce with: </details<!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOT_END --
As referenced in the other issue this now also happens on stable since = 1.70. The culprint seems to be this type alias: Removing the reference in the Option works around this panic.
Here's a minimal example that reproduces the issue: Interestingly, this only happens while the function is extern "C".
WG-prioritization assigning priority (). cc: for the bisection pointing to label -I-prioritize +P-high
claim
The panic originates in the on this line: It happens because returns which it does because normalization of fails. The reason the normalization fails is because trait resolution fails for the projection due to not being sufficiently bound. If, for example, I change in 's example above to by adding a bound, the panic goes away as trait resolution succeeds now. Since the normalization failure can be legitimate as in this case, I feel this unwrap: should be removed to fix the issue. However, I'm not sure what the enclosing method should do upon receiving a from . I'd presume it should return . Please review and let me know if this analysis makes sense. cc:
Closely related PR: . It fixes an ICE due to similar causes but on a different line. In fact the very next line.
Yeah, I think making not and just bubble up the is the right behavior here.

Discussion:
// At this point, the field's type is known to be nonnull and the parent enum is Option-like. // If the computed size for the field and the enum are different, the nonnull optimization isn't // being applied (and we've got a problem somewhere). <del> let compute_size_skeleton = |t| SizeSkeleton::compute(t, tcx, param_env).unwrap(); if !compute_size_skeleton(ty).same_size(compute_size_skeleton(field_ty)) { </del> <ins> let compute_size_skeleton = |t| SizeSkeleton::compute(t, tcx, param_env).ok(); if !compute_size_skeleton(ty)?.same_size(compute_size_skeleton(field_ty)?) { </ins> bug!("improper_ctypes: Option nonnull optimization not applied?"); }

type Foo = extern "C" fn([u8]); //~^ ERROR `extern` fn uses type `[u8]`, which is not FFI-safe <ins> pub trait FooTrait { type FooType; } pub type Foo2<T> = extern "C" fn(Option<&<T as FooTrait>::FooType>); //~^ ERROR `extern` fn uses type `Option<&<T as FooTrait>::FooType>`, which is not FFI-safe </ins> pub struct FfiUnsafe; #[allow(improper_ctypes_definitions)]

= help: consider using a raw pointer instead = note: slices have no C equivalent <ins> error: `extern` fn uses type `Option<&<T as FooTrait>::FooType>`, which is not FFI-safe --> $DIR/lint-ctypes-94223.rs:31:20 | LL | pub type Foo2<T> = extern "C" fn(Option<&<T as FooTrait>::FooType>); |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe | = help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum = note: enum has no representation hint </ins> error: `extern` fn uses type `FfiUnsafe`, which is not FFI-safe <del> --> $DIR/lint-ctypes-94223.rs:34:17 </del> <ins> --> $DIR/lint-ctypes-94223.rs:41:17 </ins> | LL | pub static BAD: extern "C" fn(FfiUnsafe) = f; |                 ^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe

= help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct = note: this struct has unspecified layout note: the type is defined here <del> --> $DIR/lint-ctypes-94223.rs:27:1 </del> <ins> --> $DIR/lint-ctypes-94223.rs:34:1 </ins> | LL | pub struct FfiUnsafe; | ^^^^^^^^^^^^^^^^^^^^ error: `extern` fn uses type `FfiUnsafe`, which is not FFI-safe <del> --> $DIR/lint-ctypes-94223.rs:37:30 </del> <ins> --> $DIR/lint-ctypes-94223.rs:44:30 </ins> | LL | pub static BAD_TWICE: Result<extern "C" fn(FfiUnsafe), extern "C" fn(FfiUnsafe)> = Ok(f); |                              ^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe

= help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct = note: this struct has unspecified layout note: the type is defined here <del> --> $DIR/lint-ctypes-94223.rs:27:1 </del> <ins> --> $DIR/lint-ctypes-94223.rs:34:1 </ins> | LL | pub struct FfiUnsafe; | ^^^^^^^^^^^^^^^^^^^^ error: `extern` fn uses type `FfiUnsafe`, which is not FFI-safe <del> --> $DIR/lint-ctypes-94223.rs:37:56 </del> <ins> --> $DIR/lint-ctypes-94223.rs:44:56 </ins> | LL | pub static BAD_TWICE: Result<extern "C" fn(FfiUnsafe), extern "C" fn(FfiUnsafe)> = Ok(f); |                                                        ^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe

= help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct = note: this struct has unspecified layout note: the type is defined here <del> --> $DIR/lint-ctypes-94223.rs:27:1 </del> <ins> --> $DIR/lint-ctypes-94223.rs:34:1 </ins> | LL | pub struct FfiUnsafe; | ^^^^^^^^^^^^^^^^^^^^ error: `extern` fn uses type `FfiUnsafe`, which is not FFI-safe <del> --> $DIR/lint-ctypes-94223.rs:41:22 </del> <ins> --> $DIR/lint-ctypes-94223.rs:48:22 </ins> | LL | pub const BAD_CONST: extern "C" fn(FfiUnsafe) = f; |                      ^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe

= help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct = note: this struct has unspecified layout note: the type is defined here <del> --> $DIR/lint-ctypes-94223.rs:27:1 </del> <ins> --> $DIR/lint-ctypes-94223.rs:34:1 </ins> | LL | pub struct FfiUnsafe; | ^^^^^^^^^^^^^^^^^^^^ <del> error: aborting due to 11 previous errors </del> <ins> error: aborting due to 12 previous errors </ins>