Skip to content

extend test for ICE when using #[no_mangle] on a generic item#5143

Merged
RalfJung merged 1 commit into
rust-lang:masterfrom
folkertdev:generic-exported-symbol
Jun 28, 2026
Merged

extend test for ICE when using #[no_mangle] on a generic item#5143
RalfJung merged 1 commit into
rust-lang:masterfrom
folkertdev:generic-exported-symbol

Conversation

@folkertdev

Copy link
Copy Markdown
Contributor

The Instance::mono function panics when its input has generic parameters. The requires_monomorphization function detects exactly those cases.

The things you run into when messing with stdarch intrinsics and miri...

Here is the full ICE backtrace for posterity

Details ``` error: internal compiler error: /rustc-dev/942ac9ce4116d4ea784c9882659372b34978b1f8/compiler/rustc_middle/src/ty/instance.rs:466:17: Instance::mono: DefId(0:3 ~ exported_symbol_generic[a039]::generic_const) has const parameters

thread 'rustc' (51023) panicked at /rustc-dev/942ac9ce4116d4ea784c9882659372b34978b1f8/compiler/rustc_middle/src/ty/instance.rs:466:17:
Box
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_middle::ty::list::RawList<(), rustc_middle::ty::generic_args::GenericArg>>::fill_item::<<rustc_middle::ty::instance::Instance>::mono::{closure#0}>.llvm.2786884126274762998.cold
7: <rustc_middle::ty::instance::Instance>::mono
8: <rustc_const_eval::interpret::eval_context::InterpCxmiri::machine::MiriMachine as miri::shims::foreign_items::EvalContextExt>::lookup_exported_symbol::{closure#0}
at ./src/shims/foreign_items.rs:165:36
9: miri::helpers::iter_exported_symbols::<<rustc_const_eval::interpret::eval_context::InterpCxmiri::machine::MiriMachine as miri::shims::foreign_items::EvalContextExt>::lookup_exported_symbol::{closure#0}>
at ./src/helpers.rs:133:13
10: <rustc_const_eval::interpret::eval_context::InterpCxmiri::machine::MiriMachine as miri::shims::foreign_items::EvalContextExt>::lookup_exported_symbol
at ./src/shims/foreign_items.rs:147:17
11: miri::shims::sig::check_shim_symbol_clash
at ./src/shims/sig.rs:207:42
12: <rustc_const_eval::interpret::eval_context::InterpCxmiri::machine::MiriMachine as miri::shims::sig::EvalContextExt>::check_shim_sig_variadic_lenient::<2>
at ./src/shims/sig.rs:308:9
13: <rustc_const_eval::interpret::eval_context::InterpCxmiri::machine::MiriMachine as miri::shims::unix::foreign_items::EvalContextExt>::emulate_foreign_item_inner
at ./src/shims/unix/foreign_items.rs:316:26
14: <rustc_const_eval::interpret::eval_context::InterpCxmiri::machine::MiriMachine as miri::shims::foreign_items::EvalContextExtPriv>::emulate_foreign_item_inner
at ./src/shims/foreign_items.rs:886:25
15: <rustc_const_eval::interpret::eval_context::InterpCxmiri::machine::MiriMachine as miri::shims::foreign_items::EvalContextExt>::emulate_foreign_item
at ./src/shims/foreign_items.rs:76:20
16: <miri::machine::MiriMachine as rustc_const_eval::interpret::machine::Machine>::find_mir_or_eval_fn
at ./src/machine.rs:1267:24
17: <rustc_const_eval::interpret::eval_context::InterpCxmiri::machine::MiriMachine>::init_fn_call
at /home/folkertdev/.rustup/toolchains/miri/lib/rustlib/rustc-src/rust/compiler/rustc_const_eval/src/interpret/call.rs:670:46
18: <rustc_const_eval::interpret::eval_context::InterpCxmiri::machine::MiriMachine>::eval_terminator
at /home/folkertdev/.rustup/toolchains/miri/lib/rustlib/rustc-src/rust/compiler/rustc_const_eval/src/interpret/step.rs:559:22
19: <rustc_const_eval::interpret::eval_context::InterpCxmiri::machine::MiriMachine>::step
at /home/folkertdev/.rustup/toolchains/miri/lib/rustlib/rustc-src/rust/compiler/rustc_const_eval/src/interpret/step.rs:67:14
20: <rustc_const_eval::interpret::eval_context::InterpCxmiri::machine::MiriMachine as miri::concurrency::thread::EvalContextExt>::miri_step
at ./src/concurrency/thread.rs:863:18
21: <rustc_const_eval::interpret::eval_context::InterpCxmiri::machine::MiriMachine as miri::concurrency::thread::EvalContextExt>::run_threads
at ./src/concurrency/thread.rs:1309:26
22: miri::eval::eval_entry::{closure#0}
at ./src/eval.rs:539:53
23: <miri::eval::eval_entry::{closure#0} as core::ops::function::FnOnce<()>>::call_once
at /home/folkertdev/.rustup/toolchains/miri/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
24: <core::panic::unwind_safe::AssertUnwindSafemiri::eval::eval_entry::{closure#0} as core::ops::function::FnOnce<()>>::call_once
at /home/folkertdev/.rustup/toolchains/miri/lib/rustlib/src/rust/library/core/src/panic/unwind_safe.rs:275:9
25: std::panicking::catch_unwind::do_call::<core::panic::unwind_safe::AssertUnwindSafemiri::eval::eval_entry::{closure#0}, rustc_middle::mir::interpret::error::InterpResult<!>>
at /home/folkertdev/.rustup/toolchains/miri/lib/rustlib/src/rust/library/std/src/panicking.rs:575:43
26: std::panicking::catch_unwind::<rustc_middle::mir::interpret::error::InterpResult<!>, core::panic::unwind_safe::AssertUnwindSafemiri::eval::eval_entry::{closure#0}>
at /home/folkertdev/.rustup/toolchains/miri/lib/rustlib/src/rust/library/std/src/panicking.rs:543:19
27: std::panic::catch_unwind::<core::panic::unwind_safe::AssertUnwindSafemiri::eval::eval_entry::{closure#0}, rustc_middle::mir::interpret::error::InterpResult<!>>
at /home/folkertdev/.rustup/toolchains/miri/lib/rustlib/src/rust/library/std/src/panic.rs:359:14
28: miri::eval::eval_entry
at ./src/eval.rs:539:9
29: <miri::MiriCompilerCalls as rustc_driver_impl::Callbacks>::after_analysis
at ./src/bin/miri.rs:216:13
30: 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/miri/issues/new

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

note: please attach the file at /home/folkertdev/rust/miri/rustc-ice-2026-06-28T10_34_34-51021.txt to your bug report

note: rustc 1.98.0-nightly (942ac9ce4 2026-06-22) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z ui-testing

query stack during panic:
end of query stack

Miri caused an ICE during evaluation. Here's the interpreter backtrace at the time of the panic:
note: the place in the program where the ICE was triggered
--> /home/folkertdev/.rustup/toolchains/miri/lib/rustlib/src/rust/library/std/src/sys/pal/unix/mod.rs:136:20
|
LL | if libc::fcntl(fd, libc::F_GETFD) == -1 && errno() == libc::EBADF {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: stack backtrace:
0: std::sys::pal::unix::init::sanitize_standard_fds
at /home/folkertdev/.rustup/toolchains/miri/lib/rustlib/src/rust/library/std/src/sys/pal/unix/mod.rs:136:20: 136:50
1: std::sys::pal::unix::init
at /home/folkertdev/.rustup/toolchains/miri/lib/rustlib/src/rust/library/std/src/sys/pal/unix/mod.rs:27:5: 27:28
2: std::rt::init
at /home/folkertdev/.rustup/toolchains/miri/lib/rustlib/src/rust/library/std/src/rt.rs:118:9: 118:39
3: std::rt::lang_start_internal::{closure#0}
at /home/folkertdev/.rustup/toolchains/miri/lib/rustlib/src/rust/library/std/src/rt.rs:173:18: 173:43
4: std::panicking::catch_unwind::do_call::<{closure@std::rt::lang_start_internal::{closure#0}}, isize>
at /home/folkertdev/.rustup/toolchains/miri/lib/rustlib/src/rust/library/std/src/panicking.rs:575:43: 575:46
5: std::panicking::catch_unwind::<isize, {closure@std::rt::lang_start_internal::{closure#0}}>
at /home/folkertdev/.rustup/toolchains/miri/lib/rustlib/src/rust/library/std/src/panicking.rs:543:19: 543:77
6: std::panic::catch_unwind::<{closure@std::rt::lang_start_internal::{closure#0}}, isize>
at /home/folkertdev/.rustup/toolchains/miri/lib/rustlib/src/rust/library/std/src/panic.rs:359:14: 359:40
7: std::rt::lang_start_internal
at /home/folkertdev/.rustup/toolchains/miri/lib/rustlib/src/rust/library/std/src/rt.rs:171:5: 193:7
8: std::rt::lang_start::<()>
at /home/folkertdev/.rustup/toolchains/miri/lib/rustlib/src/rust/library/std/src/rt.rs:205:5: 210:6

error: aborting due to 1 previous error

full stderr:
error: internal compiler error: /rustc-dev/942ac9ce4116d4ea784c9882659372b34978b1f8/compiler/rustc_middle/src/ty/instance.rs:466:17: Instance::mono: DefId(0:3 ~ exported_symbol_generic[a039]::generic_const) has const parameters

</details>

@rustbot rustbot added the S-waiting-on-review Status: Waiting for a review to complete label Jun 28, 2026
@RalfJung

Copy link
Copy Markdown
Member

Isn't this already fixed by #5129?

@folkertdev

Copy link
Copy Markdown
Contributor Author

oh, looks like it, but that hasn't made it to nightly yet. I have a bit more test coverage here (for const too).

@RalfJung

Copy link
Copy Markdown
Member

Yeah the sync (rust-lang/rust#158501) landed after the most recent nightly came out.

@folkertdev folkertdev force-pushed the generic-exported-symbol branch from 0c69d4a to 5e95e7f Compare June 28, 2026 11:48
@rustbot

rustbot commented Jun 28, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@RalfJung RalfJung changed the title fix ICE when using #[no_mangle] on a generic item extend test for ICE when using #[no_mangle] on a generic item Jun 28, 2026
@RalfJung RalfJung enabled auto-merge June 28, 2026 11:56
@RalfJung RalfJung added this pull request to the merge queue Jun 28, 2026
Merged via the queue into rust-lang:master with commit 5a912ea Jun 28, 2026
14 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Waiting for a review to complete label Jun 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants