Skip to content

ICE in improper_ctypes lint with specialization and associated type projection in extern static #152405

@trait-Cong

Description

@trait-Cong

I tried this code:

#![feature(specialization)]
trait Newtrait1 {
    type Item;
}
trait Newtrait2 {
    type Item;
}
impl<T: Newtrait1> Newtrait2 for T {
    type Item = T::Item;
}
impl<T> Newtrait1 for T {
    default type Item = u32;
}

extern "C" {
    fn ffi_get() -> <u32 as Newtrait2>::Item;
}
fn main() {
unsafe {
        let _ = ffi_get();
    }
}
Release channel Result
Current Stable error
Current Nightly ICE
Current Nightly(-Z next-solver=globally) ICE

Meta

rustc --version --verbose:

rustc 1.95.0-nightly (db3e99bba 2026-02-04)
binary: rustc
commit-hash: db3e99bbab28c6ca778b13222becdea54533d908
commit-date: 2026-02-04
host: x86_64-unknown-linux-gnu
release: 1.95.0-nightly
LLVM version: 22.1.0
Backtrace

thread 'rustc' panicked at /rustc-dev/db3e99bbab28c6ca778b13222becdea54533d908/compiler/rustc_lint/src/types/improper_ctypes.rs:686:32:
Box<dyn Any>
stack backtrace:
   0:     0x7f849c1fbf4b - <std[5b6453b30570829a]::backtrace::Backtrace>::create
   1:     0x7f849c1fbe95 - <std[5b6453b30570829a]::backtrace::Backtrace>::force_capture
   2:     0x7f849b1fe7b5 - std[5b6453b30570829a]::panicking::update_hook::<alloc[4b4e8be454901a39]::boxed::Box<rustc_driver_impl[70175e87f37eb535]::install_ice_hook::{closure#1}>>::{closure#0}
   3:     0x7f849c20ea42 - std[5b6453b30570829a]::panicking::panic_with_hook
   4:     0x7f849b2336b1 - std[5b6453b30570829a]::panicking::begin_panic::<rustc_errors[811e7740c6293f69]::ExplicitBug>::{closure#0}
   5:     0x7f849b22a606 - std[5b6453b30570829a]::sys::backtrace::__rust_end_short_backtrace::<std[5b6453b30570829a]::panicking::begin_panic<rustc_errors[811e7740c6293f69]::ExplicitBug>::{closure#0}, !>
   6:     0x7f849b227a58 - std[5b6453b30570829a]::panicking::begin_panic::<rustc_errors[811e7740c6293f69]::ExplicitBug>
   7:     0x7f849b23ef11 - <rustc_errors[811e7740c6293f69]::diagnostic::BugAbort as rustc_errors[811e7740c6293f69]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   8:     0x7f849b7ea759 - rustc_middle[945890ed1064710a]::util::bug::opt_span_bug_fmt::<rustc_span[64ec0f452ae8c55c]::span_encoding::Span>::{closure#0}
   9:     0x7f849b7ea8e2 - rustc_middle[945890ed1064710a]::ty::context::tls::with_opt::<rustc_middle[945890ed1064710a]::util::bug::opt_span_bug_fmt<rustc_span[64ec0f452ae8c55c]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  10:     0x7f849b7dba3b - rustc_middle[945890ed1064710a]::ty::context::tls::with_context_opt::<rustc_middle[945890ed1064710a]::ty::context::tls::with_opt<rustc_middle[945890ed1064710a]::util::bug::opt_span_bug_fmt<rustc_span[64ec0f452ae8c55c]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  11:     0x7f8498d591f4 - rustc_middle[945890ed1064710a]::util::bug::bug_fmt
  12:     0x7f849d7350a7 - <rustc_lint[8695433ab86834aa]::types::improper_ctypes::ImproperCTypesVisitor>::visit_type
  13:     0x7f849d7348b8 - <rustc_lint[8695433ab86834aa]::types::improper_ctypes::ImproperCTypesVisitor>::check_type
  14:     0x7f849d734633 - <rustc_lint[8695433ab86834aa]::types::improper_ctypes::ImproperCTypesLint>::check_foreign_fn
  15:     0x7f849d0b5208 - <rustc_lint[8695433ab86834aa]::late::LateContextAndPass<rustc_lint[8695433ab86834aa]::BuiltinCombinedModuleLateLintPass> as rustc_hir[a9e131cadb307f85]::intravisit::Visitor>::visit_nested_item
  16:     0x7f849d0b2f3f - rustc_lint[8695433ab86834aa]::lint_mod
  17:     0x7f849d0b2b17 - rustc_query_impl[5ce950bad06ac490]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[5ce950bad06ac490]::query_impl::lint_mod::make_query_vtable::{closure#1}::{closure#0}, rustc_middle[945890ed1064710a]::query::erase::ErasedData<[u8; 0usize]>>
  18:     0x7f849d665b15 - rustc_query_system[cb5650c2b33f578c]::query::plumbing::try_execute_query::<rustc_query_impl[5ce950bad06ac490]::SemiDynamicQueryDispatcher<rustc_query_system[cb5650c2b33f578c]::query::caches::DefaultCache<rustc_span[64ec0f452ae8c55c]::def_id::LocalModDefId, rustc_middle[945890ed1064710a]::query::erase::ErasedData<[u8; 0usize]>>, {rustc_query_impl[5ce950bad06ac490]::QueryFlags { is_anon: false, is_depth_limit: false, is_feedable: false }}>, false>
  19:     0x7f849d665899 - rustc_query_impl[5ce950bad06ac490]::query_impl::lint_mod::get_query_non_incr::__rust_end_short_backtrace
  20:     0x7f849d664990 - rustc_lint[8695433ab86834aa]::late::check_crate::{closure#1}
  21:     0x7f849d66457a - rustc_lint[8695433ab86834aa]::late::check_crate
  22:     0x7f849cd43f4e - rustc_interface[391380b3dd77dca3]::passes::analysis
  23:     0x7f849cd4366b - rustc_query_impl[5ce950bad06ac490]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[5ce950bad06ac490]::query_impl::analysis::make_query_vtable::{closure#1}::{closure#0}, rustc_middle[945890ed1064710a]::query::erase::ErasedData<[u8; 0usize]>>
  24:     0x7f849d9625e6 - rustc_query_system[cb5650c2b33f578c]::query::plumbing::try_execute_query::<rustc_query_impl[5ce950bad06ac490]::SemiDynamicQueryDispatcher<rustc_query_system[cb5650c2b33f578c]::query::caches::SingleCache<rustc_middle[945890ed1064710a]::query::erase::ErasedData<[u8; 0usize]>>, {rustc_query_impl[5ce950bad06ac490]::QueryFlags { is_anon: false, is_depth_limit: false, is_feedable: false }}>, false>
  25:     0x7f849d962348 - rustc_query_impl[5ce950bad06ac490]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  26:     0x7f849dad2da7 - <rustc_interface[391380b3dd77dca3]::passes::create_and_enter_global_ctxt<core[94716341d7c778ad]::option::Option<rustc_interface[391380b3dd77dca3]::queries::Linker>, rustc_driver_impl[70175e87f37eb535]::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core[94716341d7c778ad]::ops::function::FnOnce<(&rustc_session[79dda06290ce4e69]::session::Session, rustc_middle[945890ed1064710a]::ty::context::CurrentGcx, alloc[4b4e8be454901a39]::sync::Arc<rustc_data_structures[1e615b1a93145c8c]::jobserver::Proxy>, &std[5b6453b30570829a]::sync::once_lock::OnceLock<rustc_middle[945890ed1064710a]::ty::context::GlobalCtxt>, &rustc_data_structures[1e615b1a93145c8c]::sync::worker_local::WorkerLocal<rustc_middle[945890ed1064710a]::arena::Arena>, &rustc_data_structures[1e615b1a93145c8c]::sync::worker_local::WorkerLocal<rustc_hir[a9e131cadb307f85]::Arena>, rustc_driver_impl[70175e87f37eb535]::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
  27:     0x7f849d9840be - rustc_interface[391380b3dd77dca3]::interface::run_compiler::<(), rustc_driver_impl[70175e87f37eb535]::run_compiler::{closure#0}>::{closure#1}
  28:     0x7f849d9c66fe - std[5b6453b30570829a]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[391380b3dd77dca3]::util::run_in_thread_with_globals<rustc_interface[391380b3dd77dca3]::util::run_in_thread_pool_with_globals<rustc_interface[391380b3dd77dca3]::interface::run_compiler<(), rustc_driver_impl[70175e87f37eb535]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  29:     0x7f849d9c6c20 - <std[5b6453b30570829a]::thread::lifecycle::spawn_unchecked<rustc_interface[391380b3dd77dca3]::util::run_in_thread_with_globals<rustc_interface[391380b3dd77dca3]::util::run_in_thread_pool_with_globals<rustc_interface[391380b3dd77dca3]::interface::run_compiler<(), rustc_driver_impl[70175e87f37eb535]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[94716341d7c778ad]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  30:     0x7f849d9c7aac - <std[5b6453b30570829a]::sys::thread::unix::Thread>::new::thread_start
  31:     0x7f849757f609 - start_thread
                               at /build/glibc-B3wQXB/glibc-2.31/nptl/pthread_create.c:477:8
  32:     0x7f84974a4353 - clone
                               at /build/glibc-B3wQXB/glibc-2.31/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:95:0
  33:                0x0 - <unknown>


rustc version: 1.95.0-nightly (db3e99bba 2026-02-04)
platform: x86_64-unknown-linux-gnu

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


Metadata

Metadata

Assignees

No one assigned

    Labels

    A-specializationArea: Trait impl specializationC-bugCategory: This is a bug.F-specialization`#![feature(specialization)]`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.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.

    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