Skip to content

[ICE]: improper c types lint get_nullable_type().unwrap() #158511

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

use std::num;
extern "C" {
    fn result_nonzero_u32_t(x: Result<num::NonZero<char>, ()>);
}
fn main() {}

original:

use std::num;
extern { fn result_nonzero_u32_t(x : Result<num::NonZero<char>, ()>); }
fn main() {}

Version information

rustc 1.98.0-nightly (fd07dbfc9 2026-06-28)
binary: rustc
commit-hash: fd07dbfc91b7b6b3fa76d957e130c51e654131ee
commit-date: 2026-06-28
host: x86_64-unknown-linux-gnu
release: 1.98.0-nightly
LLVM version: 22.1.8

Possibly related line of code:

WrappingRange { start: 0, end }
if end == field_ty_scalar.size(&tcx).unsigned_int_max() - 1 =>
{
return Some(get_nullable_type(tcx, typing_env, field_ty).unwrap());
}
WrappingRange { start: 1, .. } => {
return Some(get_nullable_type(tcx, typing_env, field_ty).unwrap());
}
WrappingRange { start, end } => {
unreachable!("Unhandled start and end range: ({}, {})", start, end)
}
};
}

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

warning: function `result_nonzero_u32_t` is never used
 --> /tmp/icemaker_global_tempdir.PwhNsOV8NEfw/rustc_testrunner_tmpdir_reporting.DOeIpjtGsxQl/mvce.rs:3:8
  |
3 |     fn result_nonzero_u32_t(x: Result<num::NonZero<char>, ()>);
  |        ^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default


thread 'rustc' (1864665) panicked at /rustc-dev/fd07dbfc91b7b6b3fa76d957e130c51e654131ee/compiler/rustc_lint/src/types.rs:901:82:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0:     0x7efc1a4d3d09 - <<std[fd5358557e4939aa]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[824893b31d0d62cd]::fmt::Display>::fmt
   1:     0x7efc1ac0f288 - core[824893b31d0d62cd]::fmt::write
   2:     0x7efc1a4ea376 - <std[fd5358557e4939aa]::sys::stdio::unix::Stderr as std[fd5358557e4939aa]::io::Write>::write_fmt
   3:     0x7efc1a4a8e6e - std[fd5358557e4939aa]::panicking::default_hook::{closure#0}
   4:     0x7efc1a4c6883 - std[fd5358557e4939aa]::panicking::default_hook
   5:     0x7efc194b63a1 - std[fd5358557e4939aa]::panicking::update_hook::<alloc[b6d51ad5583e1cd2]::boxed::Box<rustc_driver_impl[5bc58d79d7fe6386]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7efc1a4c6cd2 - std[fd5358557e4939aa]::panicking::panic_with_hook
   7:     0x7efc1a4a8f64 - std[fd5358557e4939aa]::panicking::panic_handler::{closure#0}
   8:     0x7efc1a49fbf9 - std[fd5358557e4939aa]::sys::backtrace::__rust_end_short_backtrace::<std[fd5358557e4939aa]::panicking::panic_handler::{closure#0}, !>
   9:     0x7efc1a4aa99d - __rustc[3637667c58aa7985]::rust_begin_unwind
  10:     0x7efc175ca1dc - core[824893b31d0d62cd]::panicking::panic_fmt
  11:     0x7efc18049ad2 - core[824893b31d0d62cd]::panicking::panic
  12:     0x7efc17624189 - core[824893b31d0d62cd]::option::unwrap_failed
  13:     0x7efc1c170040 - rustc_lint[58986c05f69fc0dd]::types::repr_nullable_ptr
  14:     0x7efc1b6599bf - <rustc_lint[58986c05f69fc0dd]::types::improper_ctypes::ImproperCTypesVisitor>::visit_type
  15:     0x7efc1b65916a - <rustc_lint[58986c05f69fc0dd]::types::improper_ctypes::ImproperCTypesVisitor>::check_type
  16:     0x7efc1b658b87 - <rustc_lint[58986c05f69fc0dd]::types::improper_ctypes::ImproperCTypesLint>::check_foreign_fn
  17:     0x7efc1b649c1d - <rustc_lint[58986c05f69fc0dd]::late::LateContextAndPass<rustc_lint[58986c05f69fc0dd]::BuiltinCombinedLateLintModPass> as rustc_hir[e8c7897eb954285b]::intravisit::Visitor>::visit_nested_item
  18:     0x7efc1b64b40c - rustc_lint[58986c05f69fc0dd]::lint_mod
  19:     0x7efc1ba350a6 - rustc_query_impl[363d8420d406e095]::execution::try_execute_query::<rustc_middle[eddce6fccf027369]::query::caches::DefaultCache<rustc_span[5521c16fdf99d052]::def_id::LocalModDefId, rustc_middle[eddce6fccf027369]::query::erase::ErasedData<[u8; 0usize]>>, false>
  20:     0x7efc1ba3318e - rustc_query_impl[363d8420d406e095]::query_impl::lint_mod::execute_query_non_incr::__rust_end_short_backtrace
  21:     0x7efc1ba32c8d - rustc_lint[58986c05f69fc0dd]::late::check_crate::{closure#1}
  22:     0x7efc1ba328b7 - rustc_lint[58986c05f69fc0dd]::late::check_crate
  23:     0x7efc1ba326b0 - rustc_interface[b2016dfbaec51b1d]::passes::analysis::{closure#0}::{closure#0}::{closure#2}
  24:     0x7efc1ba3249a - rustc_data_structures[2dcf1c254b064446]::sync::parallel::par_fns
  25:     0x7efc1ba32429 - rustc_interface[b2016dfbaec51b1d]::passes::analysis::{closure#0}::{closure#0}
  26:     0x7efc1ba3249a - rustc_data_structures[2dcf1c254b064446]::sync::parallel::par_fns
  27:     0x7efc1af4b735 - rustc_interface[b2016dfbaec51b1d]::passes::analysis
  28:     0x7efc1bda8247 - rustc_query_impl[363d8420d406e095]::execution::try_execute_query::<rustc_middle[eddce6fccf027369]::query::caches::SingleCache<rustc_middle[eddce6fccf027369]::query::erase::ErasedData<[u8; 0usize]>>, false>
  29:     0x7efc1bda7f29 - rustc_query_impl[363d8420d406e095]::query_impl::analysis::execute_query_non_incr::__rust_end_short_backtrace
  30:     0x7efc1bd7c0c0 - rustc_interface[b2016dfbaec51b1d]::interface::run_compiler::<(), rustc_driver_impl[5bc58d79d7fe6386]::run_compiler::{closure#0}>::{closure#1}
  31:     0x7efc1bdbcb3a - std[fd5358557e4939aa]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[b2016dfbaec51b1d]::util::run_in_thread_with_globals<rustc_interface[b2016dfbaec51b1d]::util::run_in_thread_pool_with_globals<rustc_interface[b2016dfbaec51b1d]::interface::run_compiler<(), rustc_driver_impl[5bc58d79d7fe6386]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  32:     0x7efc1bdbc8ed - <std[fd5358557e4939aa]::thread::lifecycle::spawn_unchecked<rustc_interface[b2016dfbaec51b1d]::util::run_in_thread_with_globals<rustc_interface[b2016dfbaec51b1d]::util::run_in_thread_pool_with_globals<rustc_interface[b2016dfbaec51b1d]::interface::run_compiler<(), rustc_driver_impl[5bc58d79d7fe6386]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[824893b31d0d62cd]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  33:     0x7efc1bdb2f90 - <std[fd5358557e4939aa]::sys::thread::unix::Thread>::new::thread_start
  34:     0x7efc156981b9 - <unknown>
  35:     0x7efc1571d21c - <unknown>
  36:                0x0 - <unknown>

error: the compiler unexpectedly panicked. This is a bug

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: rustc 1.98.0-nightly (fd07dbfc9 2026-06-28) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [lint_mod] linting top-level module
#1 [analysis] running analysis passes on crate `mvce`
end of query stack
warning: 1 warning emitted


Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsC-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.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

Type

No type

Fields

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