Change:
<!-- [31mICE[0m: Rustc '--crate-type=lib -ooutputfile -Zdump-mir-dir=dir' 'thread 'rustc' panicked at 'mirconstqualif: MIR had errors'', 'thread 'rustc' panicked at 'mirconstqualif: MIR had errors'' File: --auto-reduced (treereduce-rust): use std::mem; macrorules! definereifyfunctions { ($( fn (<param:ident),)? for abi:tt)? fn(arg:ident: retty:ty; )+) ={ name< ($param,))? F: Fn(argty),) -$retty + Copy (f: F) -abi)? fn(argty),) -$retty { assert!(mem::sizeof::<F() == 0, ); abi)? fn wrapper< ($param,))? F: Fn(argty),) -$retty + Copy (arg: retty { let f = unsafe { mem::MaybeUninit::<F::uninit().assumeinit() }; f(arg),) } let fproof = f; wrapper::< ($param,))? F } } definereifyfunctions! { fn reifytoexterncfnunary<A, Rfor extern "C" fn(arg: A) -R; fn reifytoexterncfnhrtbridge<Rfor extern "C" fn(bridge: super::BridgeConfig<') -R; } rust //! Abstraction for creating pointers from any callable that effectively //! has the equivalent of implementing , even if the compiler neither //! provides nor allows reifying closures (i.e. creating pointers) //! other than those with absolutely no captures. //! //! More specifically, for a closure-like type to be "effectively ": //! it must be a ZST (zero-sized type): no information contained within, so //! that 's return value (if it were implemented) is unambiguous //! it must be : 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 , 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 + //! this requirement is the only reason an abstraction limited to a specific //! usecase is required: ZST + can be checked with at worst a panic //! at the "attempted 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 + 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 //! -generic parameters can have type parameters in their types: //! //! use std::mem; // FIXME(eddyb) this could be impls except for the requirement. macrorules! definereifyfunctions { ($( fn (&lt;param:ident),)? for abi:tt)? fn(arg:ident: retty:ty; )+) ={ name&lt; ($param,))? F: Fn(argty),) -$retty + Copy (f: F) -abi)? fn(argty),) -$retty { // FIXME(eddyb) describe the type (e.g. via ) once panic // formatting becomes possible in . assert!(mem::sizeof::&lt;F() == 0, "selflessreify: closure must be zero-sized"); abi)? fn wrapper&lt; ($param,))? F: Fn(argty),) -$retty + Copy (arg: retty { let f = unsafe { // SAFETY: satisfies all criteria for "out of thin air" // reconstructability (see module-level doc comment). mem::MaybeUninit::&lt;F::uninit().assumeinit() }; f(arg),) } let fproof = f; wrapper::&lt; ($param,))? F } } definereifyfunctions! { fn reifytoexterncfnunary&lt;A, Rfor extern "C" fn(arg: A) -R; // HACK(eddyb) this abstraction is used withfor<'afn(BridgeConfig<'a) // -Treifytoexterncfnunary// because of the pointer type being "higher-ranked" (i.e. the // binder). // FIXME(eddyb) try to remove the lifetime from , that'd help. fn reifytoexterncfnhrtbridge&lt;Rfor extern "C" fn(bridge: super::BridgeConfig&lt;') -R; } rustc 1.78.0-nightly ( 2024-02-14) binary: rustc commit-hash: commit-date: 2024-02-14 host: x8664-unknown-linux-gnu release: 1.78.0-nightly LLVM version: 18.1.0 thread 'rustc' panicked at mirconstqualif: MIR had errors stack backtrace: 0: 0x7f406118ce46 - std::backtracers::backtrace::libunwind::trace::h741b35e6ebf0ea82 at 1: 0x7f406118ce46 - std::backtracers::backtrace::traceunsynchronized::hf3b09a36cbdb818e at 2: 0x7f406118ce46 - std::syscommon::backtrace::printfmt::hd9ddcb56e855ae1f at 3: 0x7f406118ce46 - <std::syscommon::backtrace::print::DisplayBacktrace as core::fmt::Display::fmt::h1d659f3f1b376713 at 4: 0x7f40611dd46c - core::fmt::rt::Argument::fmt::h268aa39b6fb00372 at 5: 0x7f40611dd46c - core::fmt::write::h3ca4c8a121ee4a21 at 6: 0x7f406118087f - std::io::Write::writefmt::hbae5643614f30ef5 at 7: 0x7f406118cbf4 - std::syscommon::backtrace::print::h46251963e880a6db at 8: 0x7f406118cbf4 - std::syscommon::backtrace::print::hf7d8eafd5758e700 at 9: 0x7f406118f93b - std::panicking::defaulthook::{{closure}}::h762f7d01310422ff 10: 0x7f406118f689 - std::panicking::defaulthook::h6bf045830ee7f539 at 11: 0x7f4063ff2bac - std[]::panicking::updatehook::<alloc[]::boxed::Box<rustcdriverimpl[]::installicehook::{closure}::{closure} 12: 0x7f40611900a0 - <alloc::boxed::Box<F,Aas core::ops::function::Fn<Args::call::h183d4d6c4a9f8452 at 13: 0x7f40611900a0 - std::panicking::rustpanicwithhook::hf47919d70d1ff480 at 14: 0x7f406118fda9 - std::panicking::beginpanichandler::{{closure}}::h5fbc7433175e9186 at 15: 0x7f406118d326 - std::syscommon::backtrace::rustendshortbacktrace::h2b0c01029bb6a245 at 16: 0x7f406118fb14 - rustbeginunwind at 17: 0x7f40611d9975 - core::panicking::panicfmt::h213e6f8381440dd9 at 18: 0x7f4065528ff1 - rustcmirtransform[]::mirconstqualif 19: 0x7f4065528d21 - rustcqueryimpl[]::plumbing::rustbeginshortbacktrace::<rustcqueryimpl[]::queryimpl::mirconstqualif::dynamicquery::{closure}::{closure}, rustcmiddle[]::query::erase::Erased<[u8; 4usize]20: 0x7f406552804b - rustcquerysystem[]::query::plumbing::tryexecutequery::<rustcqueryimpl[]::DynamicConfig<rustcquerysystem[]::query::caches::DefIdCache<rustcmiddle[]::query::erase::Erased<[u8; 4usize], false, false, false, rustcqueryimpl[]::plumbing::QueryCtxt, false21: 0x7f4065527dc9 - rustcqueryimpl[]::queryimpl::mirconstqualif::getquerynonincr::rustendshortbacktrace 22: 0x7f4065527bfe - rustcmiddle[]::query::plumbing::querygetat::<rustcquerysystem[]::query::caches::DefIdCache<rustcmiddle[]::query::erase::Erased<[u8; 4usize]23: 0x7f406358f097 - rustcmirtransform[]::mirpromoted 24: 0x7f40657fb812 - rustcqueryimpl[]::plumbing::rustbeginshortbacktrace::<rustcqueryimpl[]::queryimpl::mirpromoted::dynamicquery::{closure}::{closure}, rustcmiddle[]::query::erase::Erased<[u8; 16usize]25: 0x7f40657fbabb - rustcquerysystem[]::query::plumbing::tryexecutequery::<rustcqueryimpl[]::DynamicConfig<rustcquerysystem[]::query::caches::VecCache<rustcspan[]::defid::LocalDefId, rustcmiddle[]::query::erase::Erased<[u8; 16usize], false, false, false, rustcqueryimpl[]::plumbing::QueryCtxt, false26: 0x7f40660a745d - rustcqueryimpl[]::queryimpl::mirpromoted::getquerynonincr::rustendshortbacktrace 27: 0x7f40660a756e - rustcborrowck[]::mirborrowck 28: 0x7f40660a74a1 - rustcqueryimpl[]::plumbing::rustbeginshortbacktrace::<rustcqueryimpl[]::queryimpl::mirborrowck::dynamicquery::{closure}::{closure}, rustcmiddle[]::query::erase::Erased<[u8; 8usize]29: 0x7f40653858f0 - rustcquerysystem[]::query::plumbing::tryexecutequery::<rustcqueryimpl[]::DynamicConfig<rustcquerysystem[]::query::caches::VecCache<rustcspan[]::defid::LocalDefId, rustcmiddle[]::query::erase::Erased<[u8; 8usize], false, false, false, rustcqueryimpl[]::plumbing::QueryCtxt, false30: 0x7f406538540c - rustcqueryimpl[]::queryimpl::mirborrowck::getquerynonincr::rustendshortbacktrace 31: 0x7f4065c136f0 - rustcinterface[]::passes::analysis 32: 0x7f4065c131e9 - rustcqueryimpl[]::plumbing::rustbeginshortbacktrace::<rustcqueryimpl[]::queryimpl::analysis::dynamicquery::{closure}::{closure}, rustcmiddle[]::query::erase::Erased<[u8; 1usize]33: 0x7f40661b0025 - rustcquerysystem[]::query::plumbing::tryexecutequery::<rustcqueryimpl[]::DynamicConfig<rustcquerysystem[]::query::caches::SingleCache<rustcmiddle[]::query::erase::Erased<[u8; 1usize], false, false, false, rustcqueryimpl[]::plumbing::QueryCtxt, false34: 0x7f40661afd89 - rustcqueryimpl[]::queryimpl::analysis::getquerynonincr::rustendshortbacktrace 35: 0x7f406602e055 - rustcinterface[]::interface::runcompiler::<core[]::result::Result<(), rustcspan[]::ErrorGuaranteed, rustcdriverimpl[]::runcompiler::{closure}::{closure} 36: 0x7f40661c7b58 - std[]::syscommon::backtrace::rustbeginshortbacktrace::<rustcinterface[]::util::runinthreadwithglobals<rustcinterface[]::util::runinthreadpoolwithglobals<rustcinterface[]::interface::runcompiler<core[]::result::Result<(), rustcspan[]::ErrorGuaranteed, rustcdriverimpl[]::runcompiler::{closure}::{closure}, core[]::result::Result<(), rustcspan[]::ErrorGuaranteed::{closure}, core[]::result::Result<(), rustcspan[]::ErrorGuaranteed::{closure}::{closure}, core[]::result::Result<(), rustcspan[]::ErrorGuaranteed37: 0x7f40661c7984 - <<std[]::thread::Builder::spawnunchecked<rustcinterface[]::util::runinthreadwithglobals<rustcinterface[]::util::runinthreadpoolwithglobals<rustcinterface[]::interface::runcompiler<core[]::result::Result<(), rustcspan[]::ErrorGuaranteed, rustcdriverimpl[]::runcompiler::{closure}::{closure}, core[]::result::Result<(), rustcspan[]::ErrorGuaranteed::{closure}, core[]::result::Result<(), rustcspan[]::ErrorGuaranteed::{closure}::{closure}, core[]::result::Result<(), rustcspan[]::ErrorGuaranteed::{closure} as core[]::ops::function::FnOnce<()::callonce::{shim:vtable} 38: 0x7f40611991e5 - <alloc::boxed::Box<F,Aas core::ops::function::FnOnce<Args::callonce::h1516af221a452bc1 at 39: 0x7f40611991e5 - <alloc::boxed::Box<F,Aas core::ops::function::FnOnce<Args::callonce::hff2a9d52ad89d581 at 40: 0x7f40611991e5 - std::sys::pal::unix::thread::Thread::new::threadstart::hf359248e8c5b2b25 at 41: 0x7f4060f4a9eb - <unknown42: 0x7f4060fce7cc - <unknown43: 0x0 - <unknownerror: the compiler unexpectedly panicked. this is a bug. note: we would appreciate a bug report: note: rustc 1.78.0-nightly ( 2024-02-14) running on x8664-unknown-linux-gnu note: compiler flags: --crate-type lib -Z dump-mir-dir=dir query stack during panic: [mirconstqualif] const checking [mirpromoted] promoting constants in MIR for [mirborrowck] borrow-checking [analysis] running analysis passes on this crate end of query stack error[E0433]: failed to resolve: there are too many leading keywords -- | 53 | fn reifytoexterncfnhrtbridge<Rfor extern "C" fn(bridge: super::BridgeConfig<') -R; | ^^^^^ there are too many leading keywords error: aborting due to 1 previous error For more information about this error, try . </p</details<!-- query stack: [mirconstqualif] const checking [mirpromoted] promoting constants in MIR for [mirborrowck] borrow-checking [analysis] running analysis passes on this crate --
Test is from originally cleaned up a bit
Regression in cc
Another smaller example :3
label +A-mir -needs-triage

Discussion:
) } ExprKind::Yield(opt_expr) => self.lower_expr_yield(e.span, opt_expr.as_deref()), <del> ExprKind::Err => hir::ExprKind::Err(self.dcx().has_errors().unwrap()), </del> <ins> ExprKind::Err => { hir::ExprKind::Err(self.dcx().span_delayed_bug(e.span, "lowered ExprKind::Err")) } </ins> ExprKind::Try(sub_expr) => self.lower_expr_try(e.span, sub_expr), ExprKind::Paren(_) | ExprKind::ForLoop { .. } => {

let body = &tcx.mir_const(def).borrow(); if body.return_ty().references_error() { <del> assert!(tcx.dcx().has_errors().is_some(), "mir_const_qualif: MIR had errors"); </del> <ins> // It's possible to reach here without an error being emitted (#121103). tcx.dcx().span_delayed_bug(body.span, "mir_const_qualif: MIR had errors"); </ins> return Default::default(); }

<ins> #![derive(Clone, Copy)] //~ ERROR `derive` attribute cannot be used at crate level use std::ptr::addr_of; const UNINHABITED_VARIANT: () = unsafe { let v = *addr_of!(data).cast(); //~ ERROR cannot determine resolution for the macro `addr_of` }; fn main() {} </ins>

<ins> error: `derive` attribute cannot be used at crate level --> $DIR/issue-121108.rs:1:1 | LL | #![derive(Clone, Copy)] | ^^^^^^^^^^^^^^^^^^^^^^^ LL | LL | use std::ptr::addr_of; |               ------- the inner attribute doesn't annotate this `use` import | help: perhaps you meant to use an outer attribute | LL - #![derive(Clone, Copy)] LL + #[derive(Clone, Copy)] | error: cannot determine resolution for the macro `addr_of` --> $DIR/issue-121108.rs:6:14 | LL |     let v = *addr_of!(data).cast(); |              ^^^^^^^ | = note: import resolution is stuck, try simplifying macro imports error: aborting due to 2 previous errors </ins>

<ins> fn main(_: <lib2::GenericType<42> as lib2::TypeFn>::Output) {} //~^ ERROR failed to resolve: use of undeclared crate or module `lib2` //~| ERROR failed to resolve: use of undeclared crate or module `lib2` </ins>

<ins> error[E0433]: failed to resolve: use of undeclared crate or module `lib2` --> $DIR/issue-121103.rs:1:38 | LL | fn main(_: <lib2::GenericType<42> as lib2::TypeFn>::Output) {} |                                      ^^^^ use of undeclared crate or module `lib2` error[E0433]: failed to resolve: use of undeclared crate or module `lib2` --> $DIR/issue-121103.rs:1:13 | LL | fn main(_: <lib2::GenericType<42> as lib2::TypeFn>::Output) {} |             ^^^^ use of undeclared crate or module `lib2` error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0433`. </ins>