Skip to content

ICE: export stable: unreachable #140693

Open
@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

#![crate_type = "sdylib"]

pub mod tys {
    pub trait Trait {
        type Type;
    }
    pub struct S;

    #[export_stable]
    pub extern "C" fn foo1(x: <S as Trait>::Type) -> u32 {
        x.0
    }
}
original code

original:

//@ compile-flags: -Zunstable-options -Csymbol-mangling-version=v0

#![crate_type = "sdylib"]
#![allow(incomplete_features, improper_ctypes_definitions)]
#![feature(export_stable)]
#![feature(inherent_associated_types)]

mod m {
    #[export_stable]
    pub struct S;
    //~^ ERROR private items are not exportable

    pub fn foo() -> i32 { 0 }
    //~^ ERROR only functions with "C" ABI are exportable
}

#[export_stable]
pub use m::foo;

#[export_stable]
pub mod m1 {
    #[repr(C)]
    pub struct S1; // OK, public type with stable repr

    struct S2;

    pub struct S3;
    //~^ ERROR types with unstable layout are not exportable
}

pub mod fn_sig {
    #[export_stable]
    pub fn foo1() {}
    //~^ ERROR only functions with "C" ABI are exportable

    #[export_stable]
    #[repr(C)]
    pub struct S;

    #[export_stable]
    pub extern "C" fn foo2(x: S) -> i32 { 0 }

    #[export_stable]
    pub extern "C" fn foo3(x: Box<S>) -> u32 { 0 }
    //~^ ERROR function with `#[export_stable]` attribute uses type `Box<fn_sig::S>`, which is not exportable
}

pub mod impl_item {
    pub struct S;

    impl S {
        #[export_stable]
        pub extern "C" fn foo1(&self) -> i32 { 0 }
        //~^ ERROR method with `#[export_stable]` attribute uses type `&impl_item::S`, which is not exportable

        #[export_stable]
        pub extern "C" fn foo2(self) -> i32 { 0 }
        //~^ ERROR method with `#[export_stable]` attribute uses type `impl_item::S`, which is not exportable
    }

    pub struct S2<T>(T);

    impl<T> S2<T> {
        #[export_stable]
        pub extern "C" fn foo1(&self) {}
        //~^ ERROR generic functions are not exportable
    }
}

pub mod tys {
    pub trait Trait {
        type Type;
    }
    pub struct S;

    impl<T> S2<T> {
        #[export_stable]
        pub extern "C" fn foo1(_x: Type) {}
        //~^ ERROR generic functions are not exportable
    }

    #[export_stable]
    pub extern "C" fn foo1(x: <S as Trait>::Type) -> u32 { x.0 }
    //~^ ERROR function with `#[export_stable]` attribute uses type `(u32,)`, which is not exportable

    #[export_stable]
    pub type Type = [i32; 4];

    #[export_stable]
    pub extern "C" fn foo2(_x: Type) {}
    //~^ ERROR function with `#[export_stable]` attribute uses type `[i32; 4]`, which is not exportable

    impl S {
        #[export_stable]
        pub type Type = extern "C" fn();
    }

    #[export_stable]
    pub extern "C" fn foo3(_x: S::Type) {}
    //~^ ERROR function with `#[export_stable]` attribute uses type `extern "C" fn()`, which is not exportable

    #[export_stable]
    pub extern "C" fn foo4() -> impl Copy {
    //~^ ERROR function with `#[export_stable]` attribute uses type `impl Copy`, which is not exportable
        0
    }
}

pub mod privacy {
    #[export_stable]
    #[repr(C)]
    pub struct S1 {
        pub x: i32
    }

    #[export_stable]
    #[repr(C)]
    pub struct S2 {
    //~^ ERROR ADT types with private fields are not exportable
        x: i32
    }

    #[export_stable]
    #[repr(i32)]
    enum E {
    //~^ ERROR private items are not exportable
        Variant1 { x: i32 }
    }
}

pub mod use_site {
    #[export_stable]
    pub trait Trait {}
    //~^ ERROR trait's are not exportable

    #[export_stable]
    pub const C: i32 = 0;
    //~^ ERROR constant's are not exportable
}

fn main() {}

Version information

rustc 1.88.0-nightly (4a0969e06 2025-05-05)
binary: rustc
commit-hash: 4a0969e06dbeaaa43914d2d00b2e843d49aa3886
commit-date: 2025-05-05
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.4

Possibly related line of code:

| ty::Never
| ty::UnsafeBinder(_)
| ty::Alias(ty::AliasTyKind::Opaque, _) => {
return ControlFlow::Break(ty);
}
ty::Alias(..) | ty::Infer(_) | ty::Placeholder(_) | ty::Bound(..) => unreachable!(),
}
ControlFlow::Continue(())
}
}
/// Exportable items:

Program output

error[E0658]: `sdylib` crate type is unstable
  |
  = note: see issue #139939 <https://github.com/rust-lang/rust/issues/139939> for more information
  = help: add `#![feature(export_stable)]` to the crate attributes to enable
  = note: this compiler was built on 2025-05-05; consider upgrading it if it is out of date

error[E0658]: the `#[export_stable]` attribute is an experimental feature
 --> /tmp/icemaker_global_tempdir.byJkfAgCAC9o/rustc_testrunner_tmpdir_reporting.JiMazKFR2XRS/mvce.rs:9:5
  |
9 |     #[export_stable]
  |     ^^^^^^^^^^^^^^^^
  |
  = note: see issue #139939 <https://github.com/rust-lang/rust/issues/139939> for more information
  = help: add `#![feature(export_stable)]` to the crate attributes to enable
  = note: this compiler was built on 2025-05-05; consider upgrading it if it is out of date


thread 'rustc' panicked at compiler/rustc_passes/src/check_export.rs:314:82:
internal error: entered unreachable code
stack backtrace:
   0:     0x7328f4119d43 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hb403cd2fac0f6c35
   1:     0x7328f48059c7 - core::fmt::write::h97f9b980855afdb0
   2:     0x7328f5840951 - std::io::Write::write_fmt::hfe7060805776d40d
   3:     0x7328f4119ba2 - std::sys::backtrace::BacktraceLock::print::hcaf5d44ed33dd540
   4:     0x7328f411d9ea - std::panicking::default_hook::{{closure}}::hb71d08c73046b819
   5:     0x7328f411d56f - std::panicking::default_hook::he64b7baf4c601acf
   6:     0x7328f315dec3 - std[497b135e77342dfe]::panicking::update_hook::<alloc[5a025c98fe0abec9]::boxed::Box<rustc_driver_impl[93230f812dffb5e0]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x7328f411e263 - std::panicking::rust_panic_with_hook::h891e87933e43eb50
   8:     0x7328f411df26 - std::panicking::begin_panic_handler::{{closure}}::h263154ab5bcd08b7
   9:     0x7328f411a219 - std::sys::backtrace::__rust_end_short_backtrace::hb378e569ab779db4
  10:     0x7328f411dc1d - __rustc[7c4bd70fde5450d7]::rust_begin_unwind
  11:     0x7328f0a7d320 - core::panicking::panic_fmt::h00901a220ab693a7
  12:     0x7328f0a8145c - core::panicking::panic::hea40ae5f747e880b
  13:     0x7328f3ab6dd6 - <rustc_passes[41af3e947a78c530]::check_export::ExportableItemsChecker as rustc_type_ir[7a338a7a95dfce26]::visit::TypeVisitor<rustc_middle[dbca81a53272c93]::ty::context::TyCtxt>>::visit_ty
  14:     0x7328f3ab663c - <rustc_passes[41af3e947a78c530]::check_export::ExportableItemsChecker>::check_nested_types_are_exportable
  15:     0x7328f5629826 - rustc_passes[41af3e947a78c530]::check_export::exportable_items_provider_local
  16:     0x7328f562a2f3 - rustc_query_impl[cdf8c0c3437f76cf]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[cdf8c0c3437f76cf]::query_impl::exportable_items::dynamic_query::{closure#2}::{closure#0}, rustc_middle[dbca81a53272c93]::query::erase::Erased<[u8; 16usize]>>
  17:     0x7328f562a2c9 - <rustc_query_impl[cdf8c0c3437f76cf]::query_impl::exportable_items::dynamic_query::{closure#2} as core[e97d2bc10e1a68ca]::ops::function::FnOnce<(rustc_middle[dbca81a53272c93]::ty::context::TyCtxt, rustc_span[545b9213dc14cd2d]::def_id::CrateNum)>>::call_once
  18:     0x7328f5626c4c - rustc_query_system[1fb475752ad60c19]::query::plumbing::try_execute_query::<rustc_query_impl[cdf8c0c3437f76cf]::DynamicConfig<rustc_data_structures[51b8745ee49836b]::vec_cache::VecCache<rustc_span[545b9213dc14cd2d]::def_id::CrateNum, rustc_middle[dbca81a53272c93]::query::erase::Erased<[u8; 16usize]>, rustc_query_system[1fb475752ad60c19]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[cdf8c0c3437f76cf]::plumbing::QueryCtxt, true>
  19:     0x7328f562a996 - rustc_query_impl[cdf8c0c3437f76cf]::query_impl::exportable_items::get_query_incr::__rust_end_short_backtrace
  20:     0x7328f4d3fb20 - rustc_interface[d8aa27404aa0decf]::passes::run_required_analyses
  21:     0x7328f577d31e - rustc_interface[d8aa27404aa0decf]::passes::analysis
  22:     0x7328f577d2f5 - rustc_query_impl[cdf8c0c3437f76cf]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[cdf8c0c3437f76cf]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[dbca81a53272c93]::query::erase::Erased<[u8; 0usize]>>
  23:     0x7328f5777ec6 - rustc_query_system[1fb475752ad60c19]::query::plumbing::try_execute_query::<rustc_query_impl[cdf8c0c3437f76cf]::DynamicConfig<rustc_query_system[1fb475752ad60c19]::query::caches::SingleCache<rustc_middle[dbca81a53272c93]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[cdf8c0c3437f76cf]::plumbing::QueryCtxt, true>
  24:     0x7328f57777e8 - rustc_query_impl[cdf8c0c3437f76cf]::query_impl::analysis::get_query_incr::__rust_end_short_backtrace
  25:     0x7328f5a46807 - rustc_interface[d8aa27404aa0decf]::passes::create_and_enter_global_ctxt::<core[e97d2bc10e1a68ca]::option::Option<rustc_interface[d8aa27404aa0decf]::queries::Linker>, rustc_driver_impl[93230f812dffb5e0]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  26:     0x7328f587fca6 - rustc_interface[d8aa27404aa0decf]::interface::run_compiler::<(), rustc_driver_impl[93230f812dffb5e0]::run_compiler::{closure#0}>::{closure#1}
  27:     0x7328f5837f3e - std[497b135e77342dfe]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[d8aa27404aa0decf]::util::run_in_thread_with_globals<rustc_interface[d8aa27404aa0decf]::util::run_in_thread_pool_with_globals<rustc_interface[d8aa27404aa0decf]::interface::run_compiler<(), rustc_driver_impl[93230f812dffb5e0]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  28:     0x7328f58383b4 - <<std[497b135e77342dfe]::thread::Builder>::spawn_unchecked_<rustc_interface[d8aa27404aa0decf]::util::run_in_thread_with_globals<rustc_interface[d8aa27404aa0decf]::util::run_in_thread_pool_with_globals<rustc_interface[d8aa27404aa0decf]::interface::run_compiler<(), rustc_driver_impl[93230f812dffb5e0]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[e97d2bc10e1a68ca]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  29:     0x7328f58397ab - std::sys::pal::unix::thread::Thread::new::thread_start::hac1b1fa51fe18dfe
  30:     0x7328ef6a370a - <unknown>
  31:     0x7328ef727aac - <unknown>
  32:                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.88.0-nightly (4a0969e06 2025-05-05) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z incremental-verify-ich=yes -C incremental=[REDACTED] -C debuginfo=2 -C link-dead-code=true -Z validate-mir

query stack during panic:
#0 [exportable_items] fetching all exportable items in a crate
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0658`.

@rustbot label +F-export_stable

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-has-bisectionStatus: A bisection has been found for this issueS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions