Skip to content

ICE: unexpected builtin trait with associated type: <{closure@./... } as Fn> #127746

Closed
@Naserume

Description

@Naserume

Code

#![feature(auto_traits)]
#![feature(unboxed_closures)]

trait T {}

fn f() -> impl Fn(T) {
    let p = ();
    |_| p
}

auto trait Fn {
    type Output;
}

fn main() {}

Meta

rustc --version --verbose:

rustc 1.81.0-nightly (fcaa6fdfb 2024-07-13)
binary: rustc
commit-hash: fcaa6fdfbee1316184e7ad98c53241d52cd30a5f
commit-date: 2024-07-13
host: x86_64-apple-darwin
release: 1.81.0-nightly
LLVM version: 18.1.7

Error output

error[E0380]: auto traits cannot have associated items
  --> ./6A4A7.rs:12:10
   |
11 | auto trait Fn {
   |            -- auto traits cannot have associated items
12 |     type Output; //~ ERROR E0380
   |     -----^^^^^^- help: remove these associated items

error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied
  --> ./6A4A7.rs:6:16
   |
6  | fn f() -> impl Fn(T) {
   |                ^^--- help: remove these parenthetical generics
   |                |
   |                expected 0 generic arguments
   |
note: trait defined here, with 0 generic parameters
  --> ./6A4A7.rs:11:12
   |
11 | auto trait Fn {
   |            ^^

Backtrace

error: internal compiler error: compiler/rustc_trait_selection/src/traits/project.rs:1206:21: unexpected builtin trait with associated type: <{closure@./6A4A7.rs:8:5: 8:8} as Fn>

thread 'rustc' panicked at compiler/rustc_trait_selection/src/traits/project.rs:1206:21:
Box<dyn Any>
stack backtrace:
   0:        0x10f6f6373 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h605d51fc858e32d3
   1:        0x10f7412fb - core::fmt::write::he70b1f5b242a09e4
   2:        0x10f6ec0be - std::io::Write::write_fmt::hbfde528b9dfff91a
   3:        0x10f6f8c1a - std::panicking::default_hook::{{closure}}::hfdc91bfcaaf40c09
   4:        0x10f6f88ca - std::panicking::default_hook::h8673ceadddb8316e
   5:        0x118a7d8dc - std[8bfe66706d3bd117]::panicking::update_hook::<alloc[ea04c33bd6f71985]::boxed::Box<rustc_driver_impl[d8a49a9463f03e6]::install_ice_hook::{closure#0}>>::{closure#0}
   6:        0x10f6f9a09 - std::panicking::rust_panic_with_hook::h206b639ed4704bb1
   7:        0x118af0bb7 - std[8bfe66706d3bd117]::panicking::begin_panic::<rustc_errors[7f155011d809a3bf]::ExplicitBug>::{closure#0}
   8:        0x118adc9f9 - std[8bfe66706d3bd117]::sys::backtrace::__rust_end_short_backtrace::<std[8bfe66706d3bd117]::panicking::begin_panic<rustc_errors[7f155011d809a3bf]::ExplicitBug>::{closure#0}, !>
   9:        0x11d557469 - std[8bfe66706d3bd117]::panicking::begin_panic::<rustc_errors[7f155011d809a3bf]::ExplicitBug>
  10:        0x118b02c06 - <rustc_errors[7f155011d809a3bf]::diagnostic::BugAbort as rustc_errors[7f155011d809a3bf]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  11:        0x1197c8b45 - rustc_middle[66eaac359ba8a608]::util::bug::opt_span_bug_fmt::<rustc_span[9df13b32b3ae4eb2]::span_encoding::Span>::{closure#0}
  12:        0x11977f0b7 - rustc_middle[66eaac359ba8a608]::ty::context::tls::with_opt::<rustc_middle[66eaac359ba8a608]::util::bug::opt_span_bug_fmt<rustc_span[9df13b32b3ae4eb2]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  13:        0x11977ebf5 - rustc_middle[66eaac359ba8a608]::ty::context::tls::with_context_opt::<rustc_middle[66eaac359ba8a608]::ty::context::tls::with_opt<rustc_middle[66eaac359ba8a608]::util::bug::opt_span_bug_fmt<rustc_span[9df13b32b3ae4eb2]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  14:        0x11d61ff9b - rustc_middle[66eaac359ba8a608]::util::bug::bug_fmt
  15:        0x11a7ce9a0 - rustc_trait_selection[bf739c384407ce51]::traits::project::opt_normalize_projection_term
  16:        0x11a5db9be - <rustc_infer[3da7f7f7e3fca22e]::infer::InferCtxt>::commit_if_ok::<rustc_trait_selection[bf739c384407ce51]::traits::project::ProjectAndUnifyResult, rustc_infer[3da7f7f7e3fca22e]::traits::project::MismatchedProjectionTypes, rustc_trait_selection[bf739c384407ce51]::traits::project::poly_project_and_unify_term::{closure#0}>
  17:        0x11a72a112 - <rustc_trait_selection[bf739c384407ce51]::traits::fulfill::FulfillProcessor>::process_projection_obligation
  18:        0x11a7c016f - <rustc_trait_selection[bf739c384407ce51]::traits::fulfill::FulfillProcessor as rustc_data_structures[1d3e240332809550]::obligation_forest::ObligationProcessor>::process_obligation
  19:        0x118ed2759 - <rustc_data_structures[1d3e240332809550]::obligation_forest::ObligationForest<rustc_trait_selection[bf739c384407ce51]::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection[bf739c384407ce51]::traits::fulfill::FulfillProcessor>
  20:        0x118fcb9b2 - <rustc_trait_selection[bf739c384407ce51]::traits::fulfill::FulfillmentContext<rustc_trait_selection[bf739c384407ce51]::traits::FulfillmentError> as rustc_infer[3da7f7f7e3fca22e]::traits::engine::TraitEngine<rustc_trait_selection[bf739c384407ce51]::traits::FulfillmentError>>::select_where_possible
  21:        0x11912a8c2 - <rustc_hir_typeck[a7633e0d641b9efc]::fn_ctxt::FnCtxt>::resolve_vars_with_obligations
  22:        0x119133aa2 - <rustc_hir_typeck[a7633e0d641b9efc]::fn_ctxt::FnCtxt>::try_structurally_resolve_type
  23:        0x119022626 - <rustc_hir_typeck[a7633e0d641b9efc]::fn_ctxt::FnCtxt>::coerce
  24:        0x11910c014 - <rustc_hir_typeck[a7633e0d641b9efc]::coercion::CoerceMany<&rustc_hir[d0540023df9f77a9]::hir::Expr>>::coerce_inner::<<rustc_hir_typeck[a7633e0d641b9efc]::coercion::CoerceMany<&rustc_hir[d0540023df9f77a9]::hir::Expr>>::coerce::{closure#0}>
  25:        0x119040d9a - <rustc_hir_typeck[a7633e0d641b9efc]::fn_ctxt::FnCtxt>::check_return_expr
  26:        0x119101e36 - rustc_hir_typeck[a7633e0d641b9efc]::check::check_fn
  27:        0x1190fd551 - rustc_hir_typeck[a7633e0d641b9efc]::typeck
  28:        0x11a16666c - rustc_query_impl[ab99e8e391ad42b2]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ab99e8e391ad42b2]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[66eaac359ba8a608]::query::erase::Erased<[u8; 8usize]>>
  29:        0x119fe3fae - rustc_query_system[55587a8be6cb95b6]::query::plumbing::try_execute_query::<rustc_query_impl[ab99e8e391ad42b2]::DynamicConfig<rustc_query_system[55587a8be6cb95b6]::query::caches::VecCache<rustc_span[9df13b32b3ae4eb2]::def_id::LocalDefId, rustc_middle[66eaac359ba8a608]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[ab99e8e391ad42b2]::plumbing::QueryCtxt, false>
  30:        0x11a189dab - rustc_query_impl[ab99e8e391ad42b2]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  31:        0x118cb1923 - rustc_middle[66eaac359ba8a608]::query::plumbing::query_get_at::<rustc_query_system[55587a8be6cb95b6]::query::caches::VecCache<rustc_span[9df13b32b3ae4eb2]::def_id::LocalDefId, rustc_middle[66eaac359ba8a608]::query::erase::Erased<[u8; 8usize]>>>
  32:        0x118e25646 - rustc_hir_analysis[c06ca58d4f3a4935]::collect::type_of::type_of_opaque
  33:        0x11a160c1c - rustc_query_impl[ab99e8e391ad42b2]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ab99e8e391ad42b2]::query_impl::type_of_opaque::dynamic_query::{closure#2}::{closure#0}, rustc_middle[66eaac359ba8a608]::query::erase::Erased<[u8; 8usize]>>
  34:        0x119f3390f - rustc_query_system[55587a8be6cb95b6]::query::plumbing::try_execute_query::<rustc_query_impl[ab99e8e391ad42b2]::DynamicConfig<rustc_query_system[55587a8be6cb95b6]::query::caches::DefIdCache<rustc_middle[66eaac359ba8a608]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[ab99e8e391ad42b2]::plumbing::QueryCtxt, false>
  35:        0x11a16fad9 - rustc_query_impl[ab99e8e391ad42b2]::query_impl::type_of_opaque::get_query_non_incr::__rust_end_short_backtrace
  36:        0x118cb0cde - rustc_middle[66eaac359ba8a608]::query::plumbing::query_get_at::<rustc_query_system[55587a8be6cb95b6]::query::caches::DefIdCache<rustc_middle[66eaac359ba8a608]::query::erase::Erased<[u8; 8usize]>>>
  37:        0x118e246f7 - rustc_hir_analysis[c06ca58d4f3a4935]::collect::type_of::type_of
  38:        0x11a1666e8 - rustc_query_impl[ab99e8e391ad42b2]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ab99e8e391ad42b2]::query_impl::type_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[66eaac359ba8a608]::query::erase::Erased<[u8; 8usize]>>
  39:        0x119f3390f - rustc_query_system[55587a8be6cb95b6]::query::plumbing::try_execute_query::<rustc_query_impl[ab99e8e391ad42b2]::DynamicConfig<rustc_query_system[55587a8be6cb95b6]::query::caches::DefIdCache<rustc_middle[66eaac359ba8a608]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[ab99e8e391ad42b2]::plumbing::QueryCtxt, false>
  40:        0x11a16f729 - rustc_query_impl[ab99e8e391ad42b2]::query_impl::type_of::get_query_non_incr::__rust_end_short_backtrace
  41:        0x118cb0cde - rustc_middle[66eaac359ba8a608]::query::plumbing::query_get_at::<rustc_query_system[55587a8be6cb95b6]::query::caches::DefIdCache<rustc_middle[66eaac359ba8a608]::query::erase::Erased<[u8; 8usize]>>>
  42:        0x118d87ec5 - rustc_hir_analysis[c06ca58d4f3a4935]::check::check::check_item_type
  43:        0x118dbd0f1 - rustc_hir_analysis[c06ca58d4f3a4935]::check::wfcheck::check_well_formed
  44:        0x11a1620dc - rustc_query_impl[ab99e8e391ad42b2]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ab99e8e391ad42b2]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[66eaac359ba8a608]::query::erase::Erased<[u8; 1usize]>>
  45:        0x119ff02df - rustc_query_system[55587a8be6cb95b6]::query::plumbing::try_execute_query::<rustc_query_impl[ab99e8e391ad42b2]::DynamicConfig<rustc_query_system[55587a8be6cb95b6]::query::caches::VecCache<rustc_hir[d0540023df9f77a9]::hir_id::OwnerId, rustc_middle[66eaac359ba8a608]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[ab99e8e391ad42b2]::plumbing::QueryCtxt, false>
  46:        0x11a1ac7d0 - rustc_query_impl[ab99e8e391ad42b2]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  47:        0x118cb1d22 - rustc_middle[66eaac359ba8a608]::query::plumbing::query_ensure_error_guaranteed::<rustc_query_system[55587a8be6cb95b6]::query::caches::VecCache<rustc_hir[d0540023df9f77a9]::hir_id::OwnerId, rustc_middle[66eaac359ba8a608]::query::erase::Erased<[u8; 1usize]>>, ()>
  48:        0x118dcbd51 - rustc_hir_analysis[c06ca58d4f3a4935]::check::wfcheck::check_mod_type_wf
  49:        0x11a1620ac - rustc_query_impl[ab99e8e391ad42b2]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ab99e8e391ad42b2]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[66eaac359ba8a608]::query::erase::Erased<[u8; 1usize]>>
  50:        0x119f8d589 - rustc_query_system[55587a8be6cb95b6]::query::plumbing::try_execute_query::<rustc_query_impl[ab99e8e391ad42b2]::DynamicConfig<rustc_query_system[55587a8be6cb95b6]::query::caches::DefaultCache<rustc_span[9df13b32b3ae4eb2]::def_id::LocalModDefId, rustc_middle[66eaac359ba8a608]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[ab99e8e391ad42b2]::plumbing::QueryCtxt, false>
  51:        0x11a189200 - rustc_query_impl[ab99e8e391ad42b2]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  52:        0x118e4c0bc - rustc_hir_analysis[c06ca58d4f3a4935]::check_crate
  53:        0x11940ce37 - rustc_interface[f3798eed8f7e14ff]::passes::run_required_analyses
  54:        0x11940f2d3 - rustc_interface[f3798eed8f7e14ff]::passes::analysis
  55:        0x11a16671c - rustc_query_impl[ab99e8e391ad42b2]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ab99e8e391ad42b2]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[66eaac359ba8a608]::query::erase::Erased<[u8; 1usize]>>
  56:        0x119f3ebfe - rustc_query_system[55587a8be6cb95b6]::query::plumbing::try_execute_query::<rustc_query_impl[ab99e8e391ad42b2]::DynamicConfig<rustc_query_system[55587a8be6cb95b6]::query::caches::SingleCache<rustc_middle[66eaac359ba8a608]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[ab99e8e391ad42b2]::plumbing::QueryCtxt, false>
  57:        0x11a170c77 - rustc_query_impl[ab99e8e391ad42b2]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  58:        0x118a23537 - <rustc_interface[f3798eed8f7e14ff]::queries::QueryResult<&rustc_middle[66eaac359ba8a608]::ty::context::GlobalCtxt>>::enter::<core[84f3396b7379d157]::result::Result<(), rustc_span[9df13b32b3ae4eb2]::ErrorGuaranteed>, rustc_driver_impl[d8a49a9463f03e6]::run_compiler::{closure#0}::{closure#1}::{closure#5}>
  59:        0x118a84c1b - rustc_interface[f3798eed8f7e14ff]::interface::run_compiler::<core[84f3396b7379d157]::result::Result<(), rustc_span[9df13b32b3ae4eb2]::ErrorGuaranteed>, rustc_driver_impl[d8a49a9463f03e6]::run_compiler::{closure#0}>::{closure#1}
  60:        0x118a6ffc1 - std[8bfe66706d3bd117]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[f3798eed8f7e14ff]::util::run_in_thread_with_globals<rustc_interface[f3798eed8f7e14ff]::util::run_in_thread_pool_with_globals<rustc_interface[f3798eed8f7e14ff]::interface::run_compiler<core[84f3396b7379d157]::result::Result<(), rustc_span[9df13b32b3ae4eb2]::ErrorGuaranteed>, rustc_driver_impl[d8a49a9463f03e6]::run_compiler::{closure#0}>::{closure#1}, core[84f3396b7379d157]::result::Result<(), rustc_span[9df13b32b3ae4eb2]::ErrorGuaranteed>>::{closure#0}, core[84f3396b7379d157]::result::Result<(), rustc_span[9df13b32b3ae4eb2]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[84f3396b7379d157]::result::Result<(), rustc_span[9df13b32b3ae4eb2]::ErrorGuaranteed>>
  61:        0x118a8b5e6 - <<std[8bfe66706d3bd117]::thread::Builder>::spawn_unchecked_<rustc_interface[f3798eed8f7e14ff]::util::run_in_thread_with_globals<rustc_interface[f3798eed8f7e14ff]::util::run_in_thread_pool_with_globals<rustc_interface[f3798eed8f7e14ff]::interface::run_compiler<core[84f3396b7379d157]::result::Result<(), rustc_span[9df13b32b3ae4eb2]::ErrorGuaranteed>, rustc_driver_impl[d8a49a9463f03e6]::run_compiler::{closure#0}>::{closure#1}, core[84f3396b7379d157]::result::Result<(), rustc_span[9df13b32b3ae4eb2]::ErrorGuaranteed>>::{closure#0}, core[84f3396b7379d157]::result::Result<(), rustc_span[9df13b32b3ae4eb2]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[84f3396b7379d157]::result::Result<(), rustc_span[9df13b32b3ae4eb2]::ErrorGuaranteed>>::{closure#2} as core[84f3396b7379d157]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  62:        0x10f7029bb - std::sys::pal::unix::thread::Thread::new::thread_start::hff8a09cc296b9c2d
  63:     0x7ff801f5318b - __pthread_start

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: please attach the file at `/Users/sal/Documents/240714/rustc-ice-2024-07-15T02_02_55-63072.txt` to your bug report

query stack during panic:
#0 [typeck] type-checking `f`
#1 [type_of_opaque] computing type of opaque `f::{opaque#0}`
end of query stack
error: aborting due to 3 previous errors

Some errors have detailed explanations: E0107, E0380.
For more information about an error, try `rustc --explain E0107`.

Note

ICE location

} else if tcx.is_lang_item(trait_ref.def_id, LangItem::PointeeTrait) {
let tail = selcx.tcx().struct_tail_with_normalize(
self_ty,
|ty| {
// We throw away any obligations we get from this, since we normalize
// and confirm these obligations once again during confirmation
normalize_with_depth(
selcx,
obligation.param_env,
obligation.cause.clone(),
obligation.recursion_depth + 1,
ty,
)
.value
},
|| {},
);
match tail.kind() {
ty::Bool
| ty::Char
| ty::Int(_)
| ty::Uint(_)
| ty::Float(_)
| ty::Str
| ty::Array(..)
| ty::Pat(..)
| ty::Slice(_)
| ty::RawPtr(..)
| ty::Ref(..)
| ty::FnDef(..)
| ty::FnPtr(..)
| ty::Dynamic(..)
| ty::Closure(..)
| ty::CoroutineClosure(..)
| ty::Coroutine(..)
| ty::CoroutineWitness(..)
| ty::Never
// Extern types have unit metadata, according to RFC 2850
| ty::Foreign(_)
// If returned by `struct_tail_without_normalization` this is a unit struct
// without any fields, or not a struct, and therefore is Sized.
| ty::Adt(..)
// If returned by `struct_tail_without_normalization` this is the empty tuple.
| ty::Tuple(..)
// Integers and floats are always Sized, and so have unit type metadata.
| ty::Infer(ty::InferTy::IntVar(_) | ty::InferTy::FloatVar(..)) => true,
// We normalize from `Wrapper<Tail>::Metadata` to `Tail::Metadata` if able.
// Otherwise, type parameters, opaques, and unnormalized projections have
// unit metadata if they're known (e.g. by the param_env) to be sized.
ty::Param(_) | ty::Alias(..)
if self_ty != tail
|| selcx.infcx.predicate_must_hold_modulo_regions(
&obligation.with(
selcx.tcx(),
ty::TraitRef::new(
selcx.tcx(),
selcx.tcx().require_lang_item(
LangItem::Sized,
Some(obligation.cause.span()),
),
[self_ty],
),
),
) =>
{
true
}
// FIXME(compiler-errors): are Bound and Placeholder types ever known sized?
ty::Param(_)
| ty::Alias(..)
| ty::Bound(..)
| ty::Placeholder(..)
| ty::Infer(..)
| ty::Error(_) => {
if tail.has_infer_types() {
candidate_set.mark_ambiguous();
}
false
}
}
} else {
bug!("unexpected builtin trait with associated type: {trait_ref:?}")
}

@rustbot label +A-auto-traits +F-unboxed_closures

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-auto-traitsArea: auto traits (e.g., `auto trait Send {}`)C-bugCategory: This is a bug.F-auto_traits`#![feature(auto_traits)]`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