Skip to content

[ICE]: entered unreachable code: OpaqueTy(OpaqueTy #161062

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

fn foo2fn() -> i32(_: impl fn() -> i32) {}


original:

fn foo(_: impl fn() -> i32) {}
//~^ ERROR expected identifier, found keyword `fn`

fn foo2fn() -> i32(_: impl fn() -> i32) {}
//~^ ERROR expected identifier, found keyword `fn`

fn main() {
    foo(|| ());
    //~^ ERROR mismatched types
    foo2(|_: ()| {});
    fn foo(_: impl fn() -> i32) {}~^ ERROR type mismatch in closure arguments
}

Version information

rustc 1.99.0-nightly (ba28ff76f 2026-08-13)
binary: rustc
commit-hash: ba28ff76f353a722f31c4f3dd2ac4e437d36411b
commit-date: 2026-08-13
host: x86_64-unknown-linux-gnu
release: 1.99.0-nightly
LLVM version: 23.1.0

Possibly related line of code:

}
let node = tcx.hir_node_by_def_id(def_id);
res.and(match node {
hir::Node::Crate(_) => bug!("check_well_formed cannot be applied to the crate root"),
hir::Node::Item(item) => wfcheck::check_item(tcx, item),
hir::Node::ForeignItem(item) => wfcheck::check_foreign_item(tcx, item),
_ => unreachable!("{node:?}"),
})
}
pub(super) fn check_specialization_validity<'tcx>(
tcx: TyCtxt<'tcx>,
trait_def: &ty::TraitDef,

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

error: expected identifier, found keyword `fn`
 --> /tmp/icemaker_global_tempdir.bWHsSRJyuzGt/rustc_testrunner_tmpdir_reporting.fclAtjhYDFoT/mvce.rs:4:28
  |
4 | fn foo2fn() -> i32(_: impl fn() -> i32) {}
  |                            ^^
  |
help: use `Fn` to refer to the trait (notice the capitalization)
  |
4 - fn foo2fn() -> i32(_: impl fn() -> i32) {}
4 + fn foo2fn() -> i32(_: impl Fn() -> i32) {}
  |

error[E0658]: named parameters in parenthesized generic argument lists are experimental
 --> /tmp/icemaker_global_tempdir.bWHsSRJyuzGt/rustc_testrunner_tmpdir_reporting.fclAtjhYDFoT/mvce.rs:4:20
  |
4 | fn foo2fn() -> i32(_: impl fn() -> i32) {}
  |                    ^
  |
  = note: see issue #158499 <https://github.com/rust-lang/rust/issues/158499> for more information
  = help: add `#![feature(named_fn_trait_parameters)]` to the crate attributes to enable
  = note: this compiler was built on 2026-08-13; consider upgrading it if it is out of date

error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
 --> /tmp/icemaker_global_tempdir.bWHsSRJyuzGt/rustc_testrunner_tmpdir_reporting.fclAtjhYDFoT/mvce.rs:4:16
  |
4 | fn foo2fn() -> i32(_: impl fn() -> i32) {}
  |                ^^^^^^^^^^^^^^^^^^^^^^^^ only `Fn` traits may use parentheses
  |
help: use angle brackets instead
  |
4 - fn foo2fn() -> i32(_: impl fn() -> i32) {}
4 + fn foo2fn() -> i32<_: impl fn() -> i32> {}
  |

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.bWHsSRJyuzGt/rustc_testrunner_tmpdir_reporting.fclAtjhYDFoT/mvce.rs:4:43
  |
4 | fn foo2fn() -> i32(_: impl fn() -> i32) {}
  |                                           ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.bWHsSRJyuzGt/rustc_testrunner_tmpdir_reporting.fclAtjhYDFoT/mvce.rs`

error[E0109]: type arguments are not allowed on builtin type `i32`
 --> /tmp/icemaker_global_tempdir.bWHsSRJyuzGt/rustc_testrunner_tmpdir_reporting.fclAtjhYDFoT/mvce.rs:4:23
  |
4 | fn foo2fn() -> i32(_: impl fn() -> i32) {}
  |                ---    ^^^^^^^^^^^^^^^^ type argument not allowed
  |                |
  |                not allowed on builtin type `i32`
  |
help: primitive type `i32` doesn't have generic parameters
  |
4 - fn foo2fn() -> i32(_: impl fn() -> i32) {}
4 + fn foo2fn() -> i32 {}
  |


thread 'rustc' (1644188) panicked at /rustc-dev/ba28ff76f353a722f31c4f3dd2ac4e437d36411b/compiler/rustc_hir_analysis/src/check/check.rs:1187:14:
internal error: entered unreachable code: OpaqueTy(OpaqueTy { hir_id: HirId(DefId(0:3 ~ mvce[4f71]::foo2fn).4), def_id: DefId(0:4 ~ mvce[4f71]::foo2fn::impl Fn() -> i32), bounds: [Trait(PolyTraitRef { bound_generic_params: [], modifiers: TraitBoundModifiers { constness: Never, polarity: Positive }, trait_ref: TraitRef { path: Path { span: /tmp/icemaker_global_tempdir.bWHsSRJyuzGt/rustc_testrunner_tmpdir_reporting.fclAtjhYDFoT/mvce.rs:4:28: 4:39 (#0), res: Def(Trait, DefId(2:4644 ~ core[0f90]::ops::function::Fn)), segments: [PathSegment { ident: Fn#0, hir_id: HirId(DefId(0:3 ~ mvce[4f71]::foo2fn).9), res: Def(Trait, DefId(2:4644 ~ core[0f90]::ops::function::Fn)), args: Some(GenericArgs { args: [Type(Ty { hir_id: HirId(DefId(0:3 ~ mvce[4f71]::foo2fn).7), span: /tmp/icemaker_global_tempdir.bWHsSRJyuzGt/rustc_testrunner_tmpdir_reporting.fclAtjhYDFoT/mvce.rs:4:30: 4:36 (#0), kind: Tup([]) })], constraints: [AssocItemConstraint { hir_id: HirId(DefId(0:3 ~ mvce[4f71]::foo2fn).8), ident: Output#0, gen_args: GenericArgs { args: [], constraints: [], parenthesized: No, span_ext: no-location (#0) }, kind: Equality { term: Ty(Ty { hir_id: HirId(DefId(0:3 ~ mvce[4f71]::foo2fn).5), span: /tmp/icemaker_global_tempdir.bWHsSRJyuzGt/rustc_testrunner_tmpdir_reporting.fclAtjhYDFoT/mvce.rs:4:36: 4:39 (#0), kind: Path(Resolved(None, Path { span: /tmp/icemaker_global_tempdir.bWHsSRJyuzGt/rustc_testrunner_tmpdir_reporting.fclAtjhYDFoT/mvce.rs:4:36: 4:39 (#0), res: PrimTy(Int(i32)), segments: [PathSegment { ident: i32#0, hir_id: HirId(DefId(0:3 ~ mvce[4f71]::foo2fn).6), res: PrimTy(Int(i32)), args: None, infer_args: false, delegation_child_segment: false }] })) }) }, span: /tmp/icemaker_global_tempdir.bWHsSRJyuzGt/rustc_testrunner_tmpdir_reporting.fclAtjhYDFoT/mvce.rs:4:36: 4:39 (#0) }], parenthesized: ParenSugar, span_ext: /tmp/icemaker_global_tempdir.bWHsSRJyuzGt/rustc_testrunner_tmpdir_reporting.fclAtjhYDFoT/mvce.rs:4:30: 4:36 (#0) }), infer_args: false, delegation_child_segment: false }] }, hir_ref_id: HirId(DefId(0:3 ~ mvce[4f71]::foo2fn).10) }, span: /tmp/icemaker_global_tempdir.bWHsSRJyuzGt/rustc_testrunner_tmpdir_reporting.fclAtjhYDFoT/mvce.rs:4:28: 4:39 (#0) })], origin: FnReturn { parent: DefId(0:3 ~ mvce[4f71]::foo2fn), in_trait_or_impl: None }, span: /tmp/icemaker_global_tempdir.bWHsSRJyuzGt/rustc_testrunner_tmpdir_reporting.fclAtjhYDFoT/mvce.rs:4:23: 4:39 (#4) })
stack backtrace:
   0:     0x7f98b388be26 - <<std[289e6463c60644ad]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[f901dee16a3582b]::fmt::Display>::fmt
   1:     0x7f98b3e0aca3 - core[f901dee16a3582b]::fmt::write
   2:     0x7f98b38a0d4c - <std[289e6463c60644ad]::sys::stdio::unix::Stderr as core[f901dee16a3582b]::io::write::Write>::write_fmt
   3:     0x7f98b385ed0a - std[289e6463c60644ad]::panicking::default_hook::{closure#0}
   4:     0x7f98b387fb73 - std[289e6463c60644ad]::panicking::default_hook
   5:     0x7f98b280231a - std[289e6463c60644ad]::panicking::update_hook::<alloc[814a39858e1dc4e6]::boxed::Box<rustc_driver_impl[160c2797120cde36]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f98b3880012 - std[289e6463c60644ad]::panicking::panic_with_hook
   7:     0x7f98b385edc2 - std[289e6463c60644ad]::panicking::panic_handler::{closure#0}
   8:     0x7f98b3855ca9 - std[289e6463c60644ad]::sys::backtrace::__rust_end_short_backtrace::<std[289e6463c60644ad]::panicking::panic_handler::{closure#0}, !>
   9:     0x7f98b38607cd - __rustc[5f650fa12cddb854]::rust_begin_unwind
  10:     0x7f98b052c89c - core[f901dee16a3582b]::panicking::panic_fmt
  11:     0x7f98b4e12788 - rustc_hir_analysis[1bbb3e33fdb64ea4]::check::check::check_item_type
  12:     0x7f98b4dfd1a6 - rustc_hir_analysis[1bbb3e33fdb64ea4]::check::wfcheck::check_well_formed
  13:     0x7f98b4dfd187 - rustc_query_impl[ddce33df208e4a95]::query_vtables::check_well_formed::invoke_provider_fn::__rust_begin_short_backtrace
  14:     0x7f98b4dfc7df - rustc_query_impl[ddce33df208e4a95]::execution::try_execute_query::<rustc_data_structures[388b831103d760e6]::vec_cache::VecCache<rustc_span[f21334faa4d3ef5e]::def_id::LocalDefId, rustc_middle[f60c2851550a9b]::query::erase::ErasedData<[u8; 1usize]>, rustc_middle[f60c2851550a9b]::dep_graph::graph::DepNodeIndex>, false>
  15:     0x7f98b4dfc571 - rustc_query_impl[ddce33df208e4a95]::query_vtables::check_well_formed::execute_query_non_incr::__rust_end_short_backtrace
  16:     0x7f98b4df759a - <rustc_middle[f60c2851550a9b]::hir::ModuleItems>::par_opaques::<rustc_hir_analysis[1bbb3e33fdb64ea4]::check::wfcheck::check_type_wf::{closure#5}>
  17:     0x7f98b4df9ee6 - rustc_hir_analysis[1bbb3e33fdb64ea4]::check::wfcheck::check_type_wf
  18:     0x7f98b4df9a8f - rustc_query_impl[ddce33df208e4a95]::query_vtables::check_type_wf::invoke_provider_fn::__rust_begin_short_backtrace
  19:     0x7f98b4fb8649 - rustc_query_impl[ddce33df208e4a95]::execution::try_execute_query::<rustc_middle[f60c2851550a9b]::query::caches::SingleCache<rustc_middle[f60c2851550a9b]::query::erase::ErasedData<[u8; 1usize]>>, false>
  20:     0x7f98b4fb842d - rustc_query_impl[ddce33df208e4a95]::query_vtables::check_type_wf::execute_query_non_incr::__rust_end_short_backtrace
  21:     0x7f98b4597164 - rustc_hir_analysis[1bbb3e33fdb64ea4]::check_crate
  22:     0x7f98b4a9943a - rustc_interface[63b4b6cc7c31abc0]::passes::analysis
  23:     0x7f98b4fb9eca - rustc_query_impl[ddce33df208e4a95]::execution::try_execute_query::<rustc_middle[f60c2851550a9b]::query::caches::SingleCache<rustc_middle[f60c2851550a9b]::query::erase::ErasedData<[u8; 0usize]>>, false>
  24:     0x7f98b4fb9c53 - rustc_query_impl[ddce33df208e4a95]::query_vtables::analysis::execute_query_non_incr::__rust_end_short_backtrace
  25:     0x7f98b50784b5 - rustc_interface[63b4b6cc7c31abc0]::interface::run_compiler::<(), rustc_driver_impl[160c2797120cde36]::run_compiler::{closure#0}>::{closure#2}
  26:     0x7f98b50aa1a4 - std[289e6463c60644ad]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[63b4b6cc7c31abc0]::util::run_in_thread_with_globals<rustc_interface[63b4b6cc7c31abc0]::util::run_in_thread_pool_with_globals<rustc_interface[63b4b6cc7c31abc0]::interface::run_compiler<(), rustc_driver_impl[160c2797120cde36]::run_compiler::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  27:     0x7f98b50a9f6d - <std[289e6463c60644ad]::thread::lifecycle::spawn_unchecked<rustc_interface[63b4b6cc7c31abc0]::util::run_in_thread_with_globals<rustc_interface[63b4b6cc7c31abc0]::util::run_in_thread_pool_with_globals<rustc_interface[63b4b6cc7c31abc0]::interface::run_compiler<(), rustc_driver_impl[160c2797120cde36]::run_compiler::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[f901dee16a3582b]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  28:     0x7f98b4db6782 - <std[289e6463c60644ad]::sys::thread::unix::Thread>::new::thread_start
  29:     0x7f98ae697739 - <unknown>
  30:     0x7f98ae71bedc - <unknown>
  31:                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.99.0-nightly (ba28ff76f 2026-08-13) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [check_well_formed] checking that `foo2fn::impl Fn() -> i32` is well-formed
#1 [check_type_wf] checking that types are well-formed
#2 [analysis] running analysis passes on crate `mvce`
end of query stack
error: aborting due to 5 previous errors

Some errors have detailed explanations: E0109, E0214, E0601, E0658.
For more information about an error, try `rustc --explain E0109`.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-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