Skip to content

[ICE]: "improper_ctypes: Option nonnull optimization not applied?" #155479

@theemathas

Description

@theemathas

Code

#[repr(align(16))]
pub enum MyOption {
    Some(&'static ()),
    None,
}

pub extern "C" fn foo(_: MyOption) {}

See also #155412 and #88290

cc @RalfJung

Meta

Reproducible on the playground with version 1.97.0-nightly (2026-04-17 e9e32aca5a4ffd08cbc2)

Error output

error: internal compiler error: /rustc-dev/e9e32aca5a4ffd08cbc29547b039d64b92a2c03b/compiler/rustc_lint/src/types.rs:882:17: improper_ctypes: Option nonnull optimization not applied?
Backtrace

thread 'rustc' (27) panicked at /rustc-dev/e9e32aca5a4ffd08cbc29547b039d64b92a2c03b/compiler/rustc_lint/src/types.rs:882:17:
Box<dyn Any>
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::diagnostic::BugAbort as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   2: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   3: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   4: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
   5: rustc_middle::util::bug::bug_fmt
   6: rustc_lint::types::repr_nullable_ptr.cold
   7: <rustc_lint::types::improper_ctypes::ImproperCTypesVisitor>::visit_type
   8: <rustc_lint::types::improper_ctypes::ImproperCTypesVisitor>::check_type
   9: <rustc_lint::types::improper_ctypes::ImproperCTypesLint>::check_foreign_fn
  10: <rustc_lint::BuiltinCombinedModuleLateLintPass as rustc_lint::passes::LateLintPass>::check_fn
  11: <rustc_lint::late::LateContextAndPass<rustc_lint::BuiltinCombinedModuleLateLintPass> as rustc_hir::intravisit::Visitor>::visit_nested_item
  12: rustc_lint::lint_mod
  13: rustc_query_impl::execution::try_execute_query::<rustc_middle::query::caches::DefaultCache<rustc_span::def_id::LocalModDefId, rustc_middle::query::erase::ErasedData<[u8; 0]>>, false>
  14: rustc_lint::late::check_crate::{closure#1}
  15: rustc_lint::late::check_crate
  16: rustc_interface::passes::analysis::{closure#0}::{closure#0}::{closure#2}
  17: rustc_data_structures::sync::parallel::par_fns
  18: rustc_interface::passes::analysis::{closure#0}::{closure#0}
  19: rustc_data_structures::sync::parallel::par_fns
  20: rustc_interface::passes::analysis
  21: rustc_query_impl::execution::try_execute_query::<rustc_middle::query::caches::SingleCache<rustc_middle::query::erase::ErasedData<[u8; 0]>>, false>
  22: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: please make sure that you have updated to the latest nightly

note: please attach the file at `/playground/rustc-ice-2026-04-18T08_56_39-25.txt` to your bug report

note: rustc 1.97.0-nightly (e9e32aca5 2026-04-17) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [lint_mod] linting top-level module
#1 [analysis] running analysis passes on crate `playground`
end of query stack
error: could not compile `playground` (lib)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-alignArea: alignment control (`repr(align(N))` and so on)A-layoutArea: Memory layout of typesA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-reprArea: the `#[repr(stuff)]` attributeC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️L-improper_ctypesLint: improper_ctypesT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions