Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE: unexpected type in foreign function: {type error}' #121451

Closed
matthiaskrgr opened this issue Feb 22, 2024 · 2 comments
Closed

ICE: unexpected type in foreign function: {type error}' #121451

matthiaskrgr opened this issue Feb 22, 2024 · 2 comments
Assignees
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Feb 22, 2024

auto-reduced (treereduce-rust):

use std::mem;

macro_rules! define_reify_functions {
    ($(
        fn $name:ident $(<$($param:ident),*>)?
            for $(extern $abi:tt)? fn($($arg:ident: $arg_ty:ty),*) -> $ret_ty:ty;
    )+) => {
        $(pub const fn $name<
            $($($param,)*)?
            F: Fn($($arg_ty),*) -> $ret_ty + Copy
        >(f: F) -> $(extern $abi)? fn($($arg_ty),*) -> $ret_ty {


            assert!(mem::size_of::<F>() == 0, );

            $(extern $abi)? fn wrapper<
                $($($param,)*)?
                F: Fn($($arg_ty),*) -> $ret_ty + Copy
            >($($arg: $arg_ty),*) -> $ret_ty {
                let f = unsafe {


                    mem::MaybeUninit::<F>::uninit().assume_init()
                };
                f($($arg),*)
            }
            let _f_proof = f;
            wrapper::<
                $($($param,)*)?
                F
            >
        })+
    }
}

define_reify_functions! {
    fn _reify_to_extern_c_fn_unary<A, R> for extern "C" fn(arg: A) -> R;
    fn reify_to_extern_c_fn_hrt_bridge<R> for extern "C" fn(bridge: super::BridgeConfig<'_>) -> R;
}
original code

original:

//! Abstraction for creating `fn` pointers from any callable that *effectively*
//! has the equivalent of implementing `Default`, even if the compiler neither
//! provides `Default` nor allows reifying closures (i.e. creating `fn` pointers)
//! other than those with absolutely no captures.
//!
//! More specifically, for a closure-like type to be "effectively `Default`":
//! * it must be a ZST (zero-sized type): no information contained within, so
//!   that `Default`'s return value (if it were implemented) is unambiguous
//! * it must be `Copy`: no captured "unique ZST tokens" or any other similar
//!   types that would make duplicating values at will unsound
//!   * combined with the ZST requirement, this confers a kind of "telecopy"
//!     ability: similar to `Copy`, but without keeping the value around, and
//!     instead "reconstructing" it (a noop given it's a ZST) when needed
//! * it must be *provably* inhabited: no captured uninhabited types or any
//!   other types that cannot be constructed by the user of this abstraction
//!   * the proof is a value of the closure-like type itself, in a sense the
//!     "seed" for the "telecopy" process made possible by ZST + `Copy`
//!   * this requirement is the only reason an abstraction limited to a specific
//!     usecase is required: ZST + `Copy` can be checked with *at worst* a panic
//!     at the "attempted `::default()` call" time, but that doesn't guarantee
//!     that the value can be soundly created, and attempting to use the typical
//!     "proof ZST token" approach leads yet again to having a ZST + `Copy` type
//!     that is not proof of anything without a value (i.e. isomorphic to a
//!     newtype of the type it's trying to prove the inhabitation of)
//!
//! A more flexible (and safer) solution to the general problem could exist once
//! `const`-generic parameters can have type parameters in their types:
//!
//! ```rust,ignore (needs future const-generics)
//! extern "C" fn ffi_wrapper<
//!     A, R,
//!     F: Fn(A) -> R,
//!     const f: F, // <-- this `const`-generic is not yet allowed
//! >(arg: A) -> R {
//!     f(arg)
//! }
//! ```

use std::mem;

// FIXME(eddyb) this could be `trait` impls except for the `const fn` requirement.
macro_rules! define_reify_functions {
    ($(
        fn $name:ident $(<$($param:ident),*>)?
            for $(extern $abi:tt)? fn($($arg:ident: $arg_ty:ty),*) -> $ret_ty:ty;
    )+) => {
        $(pub const fn $name<
            $($($param,)*)?
            F: Fn($($arg_ty),*) -> $ret_ty + Copy
        >(f: F) -> $(extern $abi)? fn($($arg_ty),*) -> $ret_ty {
            // FIXME(eddyb) describe the `F` type (e.g. via `type_name::<F>`) once panic
            // formatting becomes possible in `const fn`.
            assert!(mem::size_of::<F>() == 0, "selfless_reify: closure must be zero-sized");

            $(extern $abi)? fn wrapper<
                $($($param,)*)?
                F: Fn($($arg_ty),*) -> $ret_ty + Copy
            >($($arg: $arg_ty),*) -> $ret_ty {
                let f = unsafe {
                    // SAFETY: `F` satisfies all criteria for "out of thin air"
                    // reconstructability (see module-level doc comment).
                    mem::MaybeUninit::<F>::uninit().assume_init()
                };
                f($($arg),*)
            }
            let _f_proof = f;
            wrapper::<
                $($($param,)*)?
                F
            >
        })+
    }
}

define_reify_functions! {
    fn _reify_to_extern_c_fn_unary<A, R> for extern "C" fn(arg: A) -> R;

    // HACK(eddyb) this abstraction is used with `for<'a> fn(BridgeConfig<'a>)
    // -> T` but that doesn't work with just `reify_to_extern_c_fn_unary`
    // because of the `fn` pointer type being "higher-ranked" (i.e. the
    // `for<'a>` binder).
    // FIXME(eddyb) try to remove the lifetime from `BridgeConfig`, that'd help.
    fn reify_to_extern_c_fn_hrt_bridge<R> for extern "C" fn(bridge: super::BridgeConfig<'_>) -> R;
}

Version information

rustc 1.78.0-nightly (f70f19fef 2024-02-22)
binary: rustc
commit-hash: f70f19fef41cfdda75c92f163434c29ad046cf09
commit-date: 2024-02-22
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0

Command:
/home/gh-matthiaskrgr/.rustup/toolchains/master/bin/rustc --crate-type=lib

Program output

error: internal compiler error: compiler/rustc_lint/src/types.rs:1439:32: unexpected type in foreign function: {type error}

thread 'rustc' panicked at compiler/rustc_middle/src/util/bug.rs:35:44:
Box<dyn Any>
stack backtrace:
   0:     0x7f9ec8d8caf6 - std::backtrace_rs::backtrace::libunwind::trace::hef019eae7250a090
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7f9ec8d8caf6 - std::backtrace_rs::backtrace::trace_unsynchronized::h163c9c558e7f1e4e
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f9ec8d8caf6 - std::sys_common::backtrace::_print_fmt::h84a7f2dbeae8e017
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7f9ec8d8caf6 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hf7737af35c1403cd
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f9ec8ddda7c - core::fmt::rt::Argument::fmt::h027f33016919ab54
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/core/src/fmt/rt.rs:142:9
   5:     0x7f9ec8ddda7c - core::fmt::write::hed9b631feef55974
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/core/src/fmt/mod.rs:1120:17
   6:     0x7f9ec8d814bf - std::io::Write::write_fmt::h3b1c8483aebfcef8
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/std/src/io/mod.rs:1846:15
   7:     0x7f9ec8d8c8a4 - std::sys_common::backtrace::_print::h526b95c0b60f4650
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f9ec8d8c8a4 - std::sys_common::backtrace::print::h3322d8b0a1d6207a
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f9ec8d8f5eb - std::panicking::default_hook::{{closure}}::h9f07e6147b1c8a2e
  10:     0x7f9ec8d8f339 - std::panicking::default_hook::h395b386ace4fbcb6
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/std/src/panicking.rs:292:9
  11:     0x7f9ecbc7073c - std[d26ecb90c771e100]::panicking::update_hook::<alloc[100d4e65626f4394]::boxed::Box<rustc_driver_impl[ab901dc85bea4c82]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f9ec8d8fd50 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h1a188bbe7a6bf646
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/alloc/src/boxed.rs:2030:9
  13:     0x7f9ec8d8fd50 - std::panicking::rust_panic_with_hook::h1eec7c1097026ee4
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/std/src/panicking.rs:786:13
  14:     0x7f9ecbc9ce14 - std[d26ecb90c771e100]::panicking::begin_panic::<rustc_errors[e9339b16b54c0bc0]::ExplicitBug>::{closure#0}
  15:     0x7f9ecbc99d36 - std[d26ecb90c771e100]::sys_common::backtrace::__rust_end_short_backtrace::<std[d26ecb90c771e100]::panicking::begin_panic<rustc_errors[e9339b16b54c0bc0]::ExplicitBug>::{closure#0}, !>
  16:     0x7f9ecbc99a16 - std[d26ecb90c771e100]::panicking::begin_panic::<rustc_errors[e9339b16b54c0bc0]::ExplicitBug>
  17:     0x7f9eca618a41 - <rustc_errors[e9339b16b54c0bc0]::diagnostic::BugAbort as rustc_errors[e9339b16b54c0bc0]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  18:     0x7f9ecc07ae3c - <rustc_errors[e9339b16b54c0bc0]::DiagCtxt>::bug::<alloc[100d4e65626f4394]::string::String>
  19:     0x7f9ecc11faab - rustc_middle[771c523b66a87e77]::util::bug::opt_span_bug_fmt::<rustc_span[4d20b27f335b5d92]::span_encoding::Span>::{closure#0}
  20:     0x7f9ecc1033aa - rustc_middle[771c523b66a87e77]::ty::context::tls::with_opt::<rustc_middle[771c523b66a87e77]::util::bug::opt_span_bug_fmt<rustc_span[4d20b27f335b5d92]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0x7f9ecc103248 - rustc_middle[771c523b66a87e77]::ty::context::tls::with_context_opt::<rustc_middle[771c523b66a87e77]::ty::context::tls::with_opt<rustc_middle[771c523b66a87e77]::util::bug::opt_span_bug_fmt<rustc_span[4d20b27f335b5d92]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0x7f9eca590ee0 - rustc_middle[771c523b66a87e77]::util::bug::bug_fmt
  23:     0x7f9ece1cc3af - <rustc_lint[ee0ae86ad0d71ee5]::types::ImproperCTypesVisitor>::check_type_for_ffi.cold.0
  24:     0x7f9ecd1421ca - <rustc_lint[ee0ae86ad0d71ee5]::types::ImproperCTypesVisitor>::check_type_for_ffi
  25:     0x7f9ecd14161e - <rustc_lint[ee0ae86ad0d71ee5]::types::ImproperCTypesVisitor>::check_type_for_ffi_and_report_errors
  26:     0x7f9ecd75d352 - <rustc_lint[ee0ae86ad0d71ee5]::types::ImproperCTypesVisitor>::check_fn
  27:     0x7f9ecd75c0be - <rustc_lint[ee0ae86ad0d71ee5]::BuiltinCombinedModuleLateLintPass as rustc_lint[ee0ae86ad0d71ee5]::passes::LateLintPass>::check_fn
  28:     0x7f9ecd3a8cbe - <rustc_lint[ee0ae86ad0d71ee5]::late::LateContextAndPass<rustc_lint[ee0ae86ad0d71ee5]::BuiltinCombinedModuleLateLintPass> as rustc_hir[c73f1de04e7d2c16]::intravisit::Visitor>::visit_nested_item
  29:     0x7f9ecd3a70bf - rustc_lint[ee0ae86ad0d71ee5]::lint_mod
  30:     0x7f9ecd3a6eb9 - rustc_query_impl[9d2321c4f9b7ef6e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9d2321c4f9b7ef6e]::query_impl::lint_mod::dynamic_query::{closure#2}::{closure#0}, rustc_middle[771c523b66a87e77]::query::erase::Erased<[u8; 0usize]>>
  31:     0x7f9ecdba4cad - rustc_query_system[1927276894a91dd8]::query::plumbing::try_execute_query::<rustc_query_impl[9d2321c4f9b7ef6e]::DynamicConfig<rustc_query_system[1927276894a91dd8]::query::caches::DefaultCache<rustc_span[4d20b27f335b5d92]::def_id::LocalModDefId, rustc_middle[771c523b66a87e77]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[9d2321c4f9b7ef6e]::plumbing::QueryCtxt, false>
  32:     0x7f9ecdba35bf - rustc_query_impl[9d2321c4f9b7ef6e]::query_impl::lint_mod::get_query_non_incr::__rust_end_short_backtrace
  33:     0x7f9ecdba315f - rustc_lint[ee0ae86ad0d71ee5]::late::check_crate::{closure#1}
  34:     0x7f9ecdba2b5e - rustc_lint[ee0ae86ad0d71ee5]::late::check_crate
  35:     0x7f9ecdb9ca65 - rustc_interface[863afa250f767019]::passes::analysis
  36:     0x7f9ecdb9b759 - rustc_query_impl[9d2321c4f9b7ef6e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9d2321c4f9b7ef6e]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[771c523b66a87e77]::query::erase::Erased<[u8; 1usize]>>
  37:     0x7f9ecdd45303 - rustc_query_system[1927276894a91dd8]::query::plumbing::try_execute_query::<rustc_query_impl[9d2321c4f9b7ef6e]::DynamicConfig<rustc_query_system[1927276894a91dd8]::query::caches::SingleCache<rustc_middle[771c523b66a87e77]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[9d2321c4f9b7ef6e]::plumbing::QueryCtxt, false>
  38:     0x7f9ecdd4507f - rustc_query_impl[9d2321c4f9b7ef6e]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  39:     0x7f9ecdd54556 - rustc_interface[863afa250f767019]::interface::run_compiler::<core[17d6b7ce805ba05e]::result::Result<(), rustc_span[4d20b27f335b5d92]::ErrorGuaranteed>, rustc_driver_impl[ab901dc85bea4c82]::run_compiler::{closure#0}>::{closure#0}
  40:     0x7f9ecdfbe305 - std[d26ecb90c771e100]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[863afa250f767019]::util::run_in_thread_with_globals<rustc_interface[863afa250f767019]::util::run_in_thread_pool_with_globals<rustc_interface[863afa250f767019]::interface::run_compiler<core[17d6b7ce805ba05e]::result::Result<(), rustc_span[4d20b27f335b5d92]::ErrorGuaranteed>, rustc_driver_impl[ab901dc85bea4c82]::run_compiler::{closure#0}>::{closure#0}, core[17d6b7ce805ba05e]::result::Result<(), rustc_span[4d20b27f335b5d92]::ErrorGuaranteed>>::{closure#0}, core[17d6b7ce805ba05e]::result::Result<(), rustc_span[4d20b27f335b5d92]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[17d6b7ce805ba05e]::result::Result<(), rustc_span[4d20b27f335b5d92]::ErrorGuaranteed>>
  41:     0x7f9ecdfbe132 - <<std[d26ecb90c771e100]::thread::Builder>::spawn_unchecked_<rustc_interface[863afa250f767019]::util::run_in_thread_with_globals<rustc_interface[863afa250f767019]::util::run_in_thread_pool_with_globals<rustc_interface[863afa250f767019]::interface::run_compiler<core[17d6b7ce805ba05e]::result::Result<(), rustc_span[4d20b27f335b5d92]::ErrorGuaranteed>, rustc_driver_impl[ab901dc85bea4c82]::run_compiler::{closure#0}>::{closure#0}, core[17d6b7ce805ba05e]::result::Result<(), rustc_span[4d20b27f335b5d92]::ErrorGuaranteed>>::{closure#0}, core[17d6b7ce805ba05e]::result::Result<(), rustc_span[4d20b27f335b5d92]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[17d6b7ce805ba05e]::result::Result<(), rustc_span[4d20b27f335b5d92]::ErrorGuaranteed>>::{closure#1} as core[17d6b7ce805ba05e]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  42:     0x7f9ec8d99725 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h1e27cc9781dd2875
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/alloc/src/boxed.rs:2016:9
  43:     0x7f9ec8d99725 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h4e0d9eddec111fd1
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/alloc/src/boxed.rs:2016:9
  44:     0x7f9ec8d99725 - std::sys::pal::unix::thread::Thread::new::thread_start::h8ca0c4b428df1792
                               at /rustc/f70f19fef41cfdda75c92f163434c29ad046cf09/library/std/src/sys/pal/unix/thread.rs:108:17
  45:     0x7f9ec8a94ac3 - start_thread
                               at ./nptl/pthread_create.c:442:8
  46:     0x7f9ec8b26850 - __GI___clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
  47:                0x0 - <unknown>

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: rustc 1.78.0-nightly (f70f19fef 2024-02-22) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -Z dump-mir-dir=dir

query stack during panic:
#0 [lint_mod] linting top-level module
#1 [analysis] running analysis passes on this crate
end of query stack
error[E0433]: failed to resolve: there are too many leading `super` keywords
  --> /tmp/icemaker_global_tempdir.lTYtezpoweDB/rustc_testrunner_tmpdir_reporting.5A2nqZBfiMNU/mvce.rs:53:69
   |
53 |     fn reify_to_extern_c_fn_hrt_bridge<R> for extern "C" fn(bridge: super::BridgeConfig<'_>) -> R;
   |                                                                     ^^^^^ there are too many leading `super` keywords

error: aborting due to 2 previous errors

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

@matthiaskrgr matthiaskrgr added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Feb 22, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 22, 2024
@matthiaskrgr matthiaskrgr changed the title ICE: ´unexpected type in foreign function: {type error}'` ICE: unexpected type in foreign function: {type error}' Feb 22, 2024
@matthiaskrgr
Copy link
Member Author

smaller:

auto-reduced (treereduce-rust):

#![crate_type = "lib"]

pub extern "C" fn cb() -> libc::uintptr_t {}

original:

#![crate_name = "externcallback"]
#![crate_type = "lib"]
#![feature(rustc_private)]

extern crate libc;

pub mod rustrt {
    extern crate libc;

    #[link(name = "rust_test_helpers", kind = c"static")]
    extern "C" {
        pub fn rust_dbg_call(
            cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t,
            data: libc::uintptr_t,
        ) -> Self::Routing;
    }
}

pub fn fact(n: libc::uintptr_t) -> libc::uintptr_t {
    unsafe {
        println!("n = {}", n);
        rustrt::rust_dbg_call(cb, n)
    }
}

pub extern "C" fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
    if data == 1 { data } else { fact(data - 1) * data }
}

Version information

rustc 1.78.0-nightly (52cea084b 2024-02-23)
binary: rustc
commit-hash: 52cea084bd5bbac12ecfa5c0499f5c777025c968
commit-date: 2024-02-23
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc --edition=2021

Program output

error: internal compiler error: compiler/rustc_lint/src/types.rs:1439:32: unexpected type in foreign function: {type error}

thread 'rustc' panicked at compiler/rustc_middle/src/util/bug.rs:35:44:
Box<dyn Any>
stack backtrace:
   0:     0x7f1335d8caf6 - std::backtrace_rs::backtrace::libunwind::trace::he0282bd7aa79d0f5
                               at /rustc/52cea084bd5bbac12ecfa5c0499f5c777025c968/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7f1335d8caf6 - std::backtrace_rs::backtrace::trace_unsynchronized::hd257d30ae267ec37
                               at /rustc/52cea084bd5bbac12ecfa5c0499f5c777025c968/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f1335d8caf6 - std::sys_common::backtrace::_print_fmt::h4d76d87d5818822c
                               at /rustc/52cea084bd5bbac12ecfa5c0499f5c777025c968/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7f1335d8caf6 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hda8b13640513c0ca
                               at /rustc/52cea084bd5bbac12ecfa5c0499f5c777025c968/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f1335ddda7c - core::fmt::rt::Argument::fmt::h0e78e7472c6726f6
                               at /rustc/52cea084bd5bbac12ecfa5c0499f5c777025c968/library/core/src/fmt/rt.rs:142:9
   5:     0x7f1335ddda7c - core::fmt::write::h92726084111378c3
                               at /rustc/52cea084bd5bbac12ecfa5c0499f5c777025c968/library/core/src/fmt/mod.rs:1120:17
   6:     0x7f1335d814bf - std::io::Write::write_fmt::hae4e2cfe04fc8ffe
                               at /rustc/52cea084bd5bbac12ecfa5c0499f5c777025c968/library/std/src/io/mod.rs:1846:15
   7:     0x7f1335d8c8a4 - std::sys_common::backtrace::_print::ha088f411ecf7b854
                               at /rustc/52cea084bd5bbac12ecfa5c0499f5c777025c968/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f1335d8c8a4 - std::sys_common::backtrace::print::h3cf71d8220ad62fb
                               at /rustc/52cea084bd5bbac12ecfa5c0499f5c777025c968/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f1335d8f5eb - std::panicking::default_hook::{{closure}}::h40fbaa4ba62f2a25
  10:     0x7f1335d8f339 - std::panicking::default_hook::h4bae8cc7cdeafbdc
                               at /rustc/52cea084bd5bbac12ecfa5c0499f5c777025c968/library/std/src/panicking.rs:292:9
  11:     0x7f1338c859dc - std[67003dfa8d3cf222]::panicking::update_hook::<alloc[39168ee3c7236603]::boxed::Box<rustc_driver_impl[7f540b76ed15adf]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f1335d8fd50 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h9766e5d4d8db67de
                               at /rustc/52cea084bd5bbac12ecfa5c0499f5c777025c968/library/alloc/src/boxed.rs:2030:9
  13:     0x7f1335d8fd50 - std::panicking::rust_panic_with_hook::h8e53bf6707538e9c
                               at /rustc/52cea084bd5bbac12ecfa5c0499f5c777025c968/library/std/src/panicking.rs:786:13
  14:     0x7f1338cb2084 - std[67003dfa8d3cf222]::panicking::begin_panic::<rustc_errors[69afeb585d680721]::ExplicitBug>::{closure#0}
  15:     0x7f1338caecd6 - std[67003dfa8d3cf222]::sys_common::backtrace::__rust_end_short_backtrace::<std[67003dfa8d3cf222]::panicking::begin_panic<rustc_errors[69afeb585d680721]::ExplicitBug>::{closure#0}, !>
  16:     0x7f1338caa496 - std[67003dfa8d3cf222]::panicking::begin_panic::<rustc_errors[69afeb585d680721]::ExplicitBug>
  17:     0x7f1338cbba71 - <rustc_errors[69afeb585d680721]::diagnostic::BugAbort as rustc_errors[69afeb585d680721]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  18:     0x7f1339092f4c - <rustc_errors[69afeb585d680721]::DiagCtxt>::bug::<alloc[39168ee3c7236603]::string::String>
  19:     0x7f1339137c9b - rustc_middle[71d5f388b7d1fdf2]::util::bug::opt_span_bug_fmt::<rustc_span[9f840697e39ebf3c]::span_encoding::Span>::{closure#0}
  20:     0x7f133911b4ea - rustc_middle[71d5f388b7d1fdf2]::ty::context::tls::with_opt::<rustc_middle[71d5f388b7d1fdf2]::util::bug::opt_span_bug_fmt<rustc_span[9f840697e39ebf3c]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0x7f133911b368 - rustc_middle[71d5f388b7d1fdf2]::ty::context::tls::with_context_opt::<rustc_middle[71d5f388b7d1fdf2]::ty::context::tls::with_opt<rustc_middle[71d5f388b7d1fdf2]::util::bug::opt_span_bug_fmt<rustc_span[9f840697e39ebf3c]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0x7f133757bb40 - rustc_middle[71d5f388b7d1fdf2]::util::bug::bug_fmt
  23:     0x7f133b27d827 - <rustc_lint[5786b41d6dda3288]::types::ImproperCTypesVisitor>::check_type_for_ffi.cold.0
  24:     0x7f133a2a2e60 - <rustc_lint[5786b41d6dda3288]::types::ImproperCTypesVisitor>::check_type_for_ffi_and_report_errors
  25:     0x7f133a2a3346 - <rustc_lint[5786b41d6dda3288]::types::ImproperCTypesVisitor>::check_foreign_fn
  26:     0x7f133a7ab0a9 - <rustc_lint[5786b41d6dda3288]::BuiltinCombinedModuleLateLintPass as rustc_lint[5786b41d6dda3288]::passes::LateLintPass>::check_fn
  27:     0x7f133a37e112 - <rustc_lint[5786b41d6dda3288]::late::LateContextAndPass<rustc_lint[5786b41d6dda3288]::BuiltinCombinedModuleLateLintPass> as rustc_hir[bf0ffd38f13728af]::intravisit::Visitor>::visit_nested_item
  28:     0x7f133a37c519 - rustc_lint[5786b41d6dda3288]::lint_mod
  29:     0x7f133a37c317 - rustc_query_impl[921380be43ec1358]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[921380be43ec1358]::query_impl::lint_mod::dynamic_query::{closure#2}::{closure#0}, rustc_middle[71d5f388b7d1fdf2]::query::erase::Erased<[u8; 0usize]>>
  30:     0x7f133ac01ced - rustc_query_system[1909eca902444a27]::query::plumbing::try_execute_query::<rustc_query_impl[921380be43ec1358]::DynamicConfig<rustc_query_system[1909eca902444a27]::query::caches::DefaultCache<rustc_span[9f840697e39ebf3c]::def_id::LocalModDefId, rustc_middle[71d5f388b7d1fdf2]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[921380be43ec1358]::plumbing::QueryCtxt, false>
  31:     0x7f133ac005ff - rustc_query_impl[921380be43ec1358]::query_impl::lint_mod::get_query_non_incr::__rust_end_short_backtrace
  32:     0x7f133ac0019f - rustc_lint[5786b41d6dda3288]::late::check_crate::{closure#1}
  33:     0x7f133abffb9e - rustc_lint[5786b41d6dda3288]::late::check_crate
  34:     0x7f133abf9aa5 - rustc_interface[5d7beb8844659dcb]::passes::analysis
  35:     0x7f133abf8799 - rustc_query_impl[921380be43ec1358]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[921380be43ec1358]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[71d5f388b7d1fdf2]::query::erase::Erased<[u8; 1usize]>>
  36:     0x7f133ad25443 - rustc_query_system[1909eca902444a27]::query::plumbing::try_execute_query::<rustc_query_impl[921380be43ec1358]::DynamicConfig<rustc_query_system[1909eca902444a27]::query::caches::SingleCache<rustc_middle[71d5f388b7d1fdf2]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[921380be43ec1358]::plumbing::QueryCtxt, false>
  37:     0x7f133ad251bf - rustc_query_impl[921380be43ec1358]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  38:     0x7f133ad34696 - rustc_interface[5d7beb8844659dcb]::interface::run_compiler::<core[e4f656a50871fc5f]::result::Result<(), rustc_span[9f840697e39ebf3c]::ErrorGuaranteed>, rustc_driver_impl[7f540b76ed15adf]::run_compiler::{closure#0}>::{closure#0}
  39:     0x7f133afc4a45 - std[67003dfa8d3cf222]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[5d7beb8844659dcb]::util::run_in_thread_with_globals<rustc_interface[5d7beb8844659dcb]::util::run_in_thread_pool_with_globals<rustc_interface[5d7beb8844659dcb]::interface::run_compiler<core[e4f656a50871fc5f]::result::Result<(), rustc_span[9f840697e39ebf3c]::ErrorGuaranteed>, rustc_driver_impl[7f540b76ed15adf]::run_compiler::{closure#0}>::{closure#0}, core[e4f656a50871fc5f]::result::Result<(), rustc_span[9f840697e39ebf3c]::ErrorGuaranteed>>::{closure#0}, core[e4f656a50871fc5f]::result::Result<(), rustc_span[9f840697e39ebf3c]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[e4f656a50871fc5f]::result::Result<(), rustc_span[9f840697e39ebf3c]::ErrorGuaranteed>>
  40:     0x7f133afc4872 - <<std[67003dfa8d3cf222]::thread::Builder>::spawn_unchecked_<rustc_interface[5d7beb8844659dcb]::util::run_in_thread_with_globals<rustc_interface[5d7beb8844659dcb]::util::run_in_thread_pool_with_globals<rustc_interface[5d7beb8844659dcb]::interface::run_compiler<core[e4f656a50871fc5f]::result::Result<(), rustc_span[9f840697e39ebf3c]::ErrorGuaranteed>, rustc_driver_impl[7f540b76ed15adf]::run_compiler::{closure#0}>::{closure#0}, core[e4f656a50871fc5f]::result::Result<(), rustc_span[9f840697e39ebf3c]::ErrorGuaranteed>>::{closure#0}, core[e4f656a50871fc5f]::result::Result<(), rustc_span[9f840697e39ebf3c]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[e4f656a50871fc5f]::result::Result<(), rustc_span[9f840697e39ebf3c]::ErrorGuaranteed>>::{closure#1} as core[e4f656a50871fc5f]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  41:     0x7f1335d99725 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hd7bd2141211518c4
                               at /rustc/52cea084bd5bbac12ecfa5c0499f5c777025c968/library/alloc/src/boxed.rs:2016:9
  42:     0x7f1335d99725 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h21602226b6e0c057
                               at /rustc/52cea084bd5bbac12ecfa5c0499f5c777025c968/library/alloc/src/boxed.rs:2016:9
  43:     0x7f1335d99725 - std::sys::pal::unix::thread::Thread::new::thread_start::h41536a58e5007e48
                               at /rustc/52cea084bd5bbac12ecfa5c0499f5c777025c968/library/std/src/sys/pal/unix/thread.rs:108:17
  44:     0x7f1335b819eb - <unknown>
  45:     0x7f1335c057cc - <unknown>
  46:                0x0 - <unknown>

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: rustc 1.78.0-nightly (52cea084b 2024-02-23) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z dump-mir-dir=dir

query stack during panic:
#0 [lint_mod] linting top-level module
#1 [analysis] running analysis passes on this crate
end of query stack
error[E0433]: failed to resolve: use of undeclared crate or module `libc`
 --> /tmp/icemaker_global_tempdir.D7QMTMHKPUt0/rustc_testrunner_tmpdir_reporting.UDMzaOZ6XWcn/mvce.rs:3:27
  |
3 | pub extern "C" fn cb() -> libc::uintptr_t {}
  |                           ^^^^ use of undeclared crate or module `libc`

error: aborting due to 2 previous errors

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

@matthiaskrgr
Copy link
Member Author

#121206 cc @nnethercote

@nnethercote nnethercote self-assigned this Feb 26, 2024
nnethercote added a commit to nnethercote/rust that referenced this issue Feb 27, 2024
Stashed errors used to be counted as errors, but could then be
cancelled, leading to `ErrorGuaranteed` soundness holes. rust-lang#120828 changed
that, closing the soundness hole. But it introduced other difficulties
because you sometimes have to account for pending stashed errors when
making decisions about whether errors have occured/will occur and it's
easy to overlook these.

This commit aims for a middle ground.
- Stashed errors (not warnings) are counted immediately as emitted
  errors, avoiding the possibility of forgetting to consider them.
- The ability to cancel (or downgrade) stashed errors is eliminated, by
  disallowing the use of `steal_diagnostic` with errors, and introducing
  the more restrictive methods `try_steal_{modify,replace}_and_emit_err`
  that can be used instead.

Other things:
- `DiagnosticBuilder::stash` and `DiagCtxt::stash_diagnostic` now both
  return `Option<ErrorGuaranteed>`, which enables the removal of two
  `delayed_bug` calls and one `Ty::new_error_with_message` call. This is
  possible because we store error guarantees in
  `DiagCtxt::stashed_diagnostics`.
- Storing the guarantees also saves us having to maintain a counter.
- Calls to the `stashed_err_count` method are no longer necessary
  alongside calls to `has_errors`, which is a nice simplification, and
  eliminates two more `span_delayed_bug` calls and one FIXME comment.
- Tests are added for three of the four fixed PRs mentioned below.
- `issue-121108.rs`'s output improved slightly, omitting a non-useful
  error message.

Fixes rust-lang#121451.
Fixes rust-lang#121477.
Fixes rust-lang#121504.
Fixes rust-lang#121508.
nnethercote added a commit to nnethercote/rust that referenced this issue Feb 27, 2024
Stashed errors used to be counted as errors, but could then be
cancelled, leading to `ErrorGuaranteed` soundness holes. rust-lang#120828 changed
that, closing the soundness hole. But it introduced other difficulties
because you sometimes have to account for pending stashed errors when
making decisions about whether errors have occured/will occur and it's
easy to overlook these.

This commit aims for a middle ground.
- Stashed errors (not warnings) are counted immediately as emitted
  errors, avoiding the possibility of forgetting to consider them.
- The ability to cancel (or downgrade) stashed errors is eliminated, by
  disallowing the use of `steal_diagnostic` with errors, and introducing
  the more restrictive methods `try_steal_{modify,replace}_and_emit_err`
  that can be used instead.

Other things:
- `DiagnosticBuilder::stash` and `DiagCtxt::stash_diagnostic` now both
  return `Option<ErrorGuaranteed>`, which enables the removal of two
  `delayed_bug` calls and one `Ty::new_error_with_message` call. This is
  possible because we store error guarantees in
  `DiagCtxt::stashed_diagnostics`.
- Storing the guarantees also saves us having to maintain a counter.
- Calls to the `stashed_err_count` method are no longer necessary
  alongside calls to `has_errors`, which is a nice simplification, and
  eliminates two more `span_delayed_bug` calls and one FIXME comment.
- Tests are added for three of the four fixed PRs mentioned below.
- `issue-121108.rs`'s output improved slightly, omitting a non-useful
  error message.

Fixes rust-lang#121451.
Fixes rust-lang#121477.
Fixes rust-lang#121504.
Fixes rust-lang#121508.
nnethercote added a commit to nnethercote/rust that referenced this issue Feb 27, 2024
Stashed errors used to be counted as errors, but could then be
cancelled, leading to `ErrorGuaranteed` soundness holes. rust-lang#120828 changed
that, closing the soundness hole. But it introduced other difficulties
because you sometimes have to account for pending stashed errors when
making decisions about whether errors have occured/will occur and it's
easy to overlook these.

This commit aims for a middle ground.
- Stashed errors (not warnings) are counted immediately as emitted
  errors, avoiding the possibility of forgetting to consider them.
- The ability to cancel (or downgrade) stashed errors is eliminated, by
  disallowing the use of `steal_diagnostic` with errors, and introducing
  the more restrictive methods `try_steal_{modify,replace}_and_emit_err`
  that can be used instead.

Other things:
- `DiagnosticBuilder::stash` and `DiagCtxt::stash_diagnostic` now both
  return `Option<ErrorGuaranteed>`, which enables the removal of two
  `delayed_bug` calls and one `Ty::new_error_with_message` call. This is
  possible because we store error guarantees in
  `DiagCtxt::stashed_diagnostics`.
- Storing the guarantees also saves us having to maintain a counter.
- Calls to the `stashed_err_count` method are no longer necessary
  alongside calls to `has_errors`, which is a nice simplification, and
  eliminates two more `span_delayed_bug` calls and one FIXME comment.
- Tests are added for three of the four fixed PRs mentioned below.
- `issue-121108.rs`'s output improved slightly, omitting a non-useful
  error message.

Fixes rust-lang#121451.
Fixes rust-lang#121477.
Fixes rust-lang#121504.
Fixes rust-lang#121508.
@bors bors closed this as completed in 260ae70 Feb 29, 2024
@fmease fmease removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 29, 2024
nnethercote added a commit to nnethercote/rust that referenced this issue Mar 1, 2024
Stashed errors used to be counted as errors, but could then be
cancelled, leading to `ErrorGuaranteed` soundness holes. rust-lang#120828 changed
that, closing the soundness hole. But it introduced other difficulties
because you sometimes have to account for pending stashed errors when
making decisions about whether errors have occured/will occur and it's
easy to overlook these.

This commit aims for a middle ground.
- Stashed errors (not warnings) are counted immediately as emitted
  errors, avoiding the possibility of forgetting to consider them.
- The ability to cancel (or downgrade) stashed errors is eliminated, by
  disallowing the use of `steal_diagnostic` with errors, and introducing
  the more restrictive methods `try_steal_{modify,replace}_and_emit_err`
  that can be used instead.

Other things:
- `DiagnosticBuilder::stash` and `DiagCtxt::stash_diagnostic` now both
  return `Option<ErrorGuaranteed>`, which enables the removal of two
  `delayed_bug` calls and one `Ty::new_error_with_message` call. This is
  possible because we store error guarantees in
  `DiagCtxt::stashed_diagnostics`.
- Storing the guarantees also saves us having to maintain a counter.
- Calls to the `stashed_err_count` method are no longer necessary
  alongside calls to `has_errors`, which is a nice simplification, and
  eliminates two more `span_delayed_bug` calls and one FIXME comment.
- Tests are added for three of the four fixed PRs mentioned below.
- `issue-121108.rs`'s output improved slightly, omitting a non-useful
  error message.

Fixes rust-lang#121451.
Fixes rust-lang#121477.
Fixes rust-lang#121504.
Fixes rust-lang#121508.
flip1995 pushed a commit to flip1995/rust that referenced this issue Mar 7, 2024
Stashed errors used to be counted as errors, but could then be
cancelled, leading to `ErrorGuaranteed` soundness holes. rust-lang#120828 changed
that, closing the soundness hole. But it introduced other difficulties
because you sometimes have to account for pending stashed errors when
making decisions about whether errors have occured/will occur and it's
easy to overlook these.

This commit aims for a middle ground.
- Stashed errors (not warnings) are counted immediately as emitted
  errors, avoiding the possibility of forgetting to consider them.
- The ability to cancel (or downgrade) stashed errors is eliminated, by
  disallowing the use of `steal_diagnostic` with errors, and introducing
  the more restrictive methods `try_steal_{modify,replace}_and_emit_err`
  that can be used instead.

Other things:
- `DiagnosticBuilder::stash` and `DiagCtxt::stash_diagnostic` now both
  return `Option<ErrorGuaranteed>`, which enables the removal of two
  `delayed_bug` calls and one `Ty::new_error_with_message` call. This is
  possible because we store error guarantees in
  `DiagCtxt::stashed_diagnostics`.
- Storing the guarantees also saves us having to maintain a counter.
- Calls to the `stashed_err_count` method are no longer necessary
  alongside calls to `has_errors`, which is a nice simplification, and
  eliminates two more `span_delayed_bug` calls and one FIXME comment.
- Tests are added for three of the four fixed PRs mentioned below.
- `issue-121108.rs`'s output improved slightly, omitting a non-useful
  error message.

Fixes rust-lang#121451.
Fixes rust-lang#121477.
Fixes rust-lang#121504.
Fixes rust-lang#121508.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants