rust-lang / rust-lang/rust

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

Open
#155,479 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-align A-layout A-lints A-repr C-bug I-ICE L-improper_ctypes T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with compiler/rustc_lint/src/types.rs around line 882, then trace the improper_ctypes visitor through repr_nullable_ptr and check_type. Reproduce the provided example on the noted nightly and compare related issues #155412 and #88290. Done means the example no longer causes an internal compiler error and the relevant lint path handles it normally.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.