rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.55k stars 12.74k forks source link

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

Closed Naserume closed 3 months ago

Naserume commented 4 months ago

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 stack backtrace: 0: 0x10f6f6373 - ::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::>::{closure#0} 6: 0x10f6f9a09 - std::panicking::rust_panic_with_hook::h206b639ed4704bb1 7: 0x118af0bb7 - std[8bfe66706d3bd117]::panicking::begin_panic::::{closure#0} 8: 0x118adc9f9 - std[8bfe66706d3bd117]::sys::backtrace::__rust_end_short_backtrace::::{closure#0}, !> 9: 0x11d557469 - std[8bfe66706d3bd117]::panicking::begin_panic:: 10: 0x118b02c06 - ::emit_producing_guarantee 11: 0x1197c8b45 - rustc_middle[66eaac359ba8a608]::util::bug::opt_span_bug_fmt::::{closure#0} 12: 0x11977f0b7 - rustc_middle[66eaac359ba8a608]::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0} 13: 0x11977ebf5 - rustc_middle[66eaac359ba8a608]::ty::context::tls::with_context_opt::::{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 - ::commit_if_ok:: 17: 0x11a72a112 - ::process_projection_obligation 18: 0x11a7c016f - ::process_obligation 19: 0x118ed2759 - >::process_obligations:: 20: 0x118fcb9b2 - as rustc_infer[3da7f7f7e3fca22e]::traits::engine::TraitEngine>::select_where_possible 21: 0x11912a8c2 - ::resolve_vars_with_obligations 22: 0x119133aa2 - ::try_structurally_resolve_type 23: 0x119022626 - ::coerce 24: 0x11910c014 - >::coerce_inner::<>::coerce::{closure#0}> 25: 0x119040d9a - ::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::> 29: 0x119fe3fae - rustc_query_system[55587a8be6cb95b6]::query::plumbing::try_execute_query::>, 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::>> 32: 0x118e25646 - rustc_hir_analysis[c06ca58d4f3a4935]::collect::type_of::type_of_opaque 33: 0x11a160c1c - rustc_query_impl[ab99e8e391ad42b2]::plumbing::__rust_begin_short_backtrace::> 34: 0x119f3390f - rustc_query_system[55587a8be6cb95b6]::query::plumbing::try_execute_query::>, 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::>> 37: 0x118e246f7 - rustc_hir_analysis[c06ca58d4f3a4935]::collect::type_of::type_of 38: 0x11a1666e8 - rustc_query_impl[ab99e8e391ad42b2]::plumbing::__rust_begin_short_backtrace::> 39: 0x119f3390f - rustc_query_system[55587a8be6cb95b6]::query::plumbing::try_execute_query::>, 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::>> 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::> 45: 0x119ff02df - rustc_query_system[55587a8be6cb95b6]::query::plumbing::try_execute_query::>, 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::>, ()> 48: 0x118dcbd51 - rustc_hir_analysis[c06ca58d4f3a4935]::check::wfcheck::check_mod_type_wf 49: 0x11a1620ac - rustc_query_impl[ab99e8e391ad42b2]::plumbing::__rust_begin_short_backtrace::> 50: 0x119f8d589 - rustc_query_system[55587a8be6cb95b6]::query::plumbing::try_execute_query::>, 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::> 56: 0x119f3ebfe - rustc_query_system[55587a8be6cb95b6]::query::plumbing::try_execute_query::>, 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 - >::enter::, rustc_driver_impl[d8a49a9463f03e6]::run_compiler::{closure#0}::{closure#1}::{closure#5}> 59: 0x118a84c1b - rustc_interface[f3798eed8f7e14ff]::interface::run_compiler::, rustc_driver_impl[d8a49a9463f03e6]::run_compiler::{closure#0}>::{closure#1} 60: 0x118a6ffc1 - std[8bfe66706d3bd117]::sys::backtrace::__rust_begin_short_backtrace::, 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 - <::spawn_unchecked_, 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 https://github.com/rust-lang/rust/blob/fcaa6fdfbee1316184e7ad98c53241d52cd30a5f/compiler/rustc_trait_selection/src/traits/project.rs#L1122-L1207

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

theemathas commented 4 months ago

Minimized:

#![feature(auto_traits)]

auto trait Trait {
    type Output;
}

fn f() {
    let _: <i32 as Trait>::Output = 1_i64;
}
Error output ``` Compiling playground v0.0.1 (/playground) error[E0380]: auto traits cannot have associated items --> src/lib.rs:4:10 | 3 | auto trait Trait { | ----- auto traits cannot have associated items 4 | type Output; | -----^^^^^^- help: remove these associated items error: internal compiler error: compiler/rustc_trait_selection/src/traits/project.rs:1206:21: unexpected builtin trait with associated type: thread 'rustc' panicked at compiler/rustc_trait_selection/src/traits/project.rs:1206:21: Box stack backtrace: 0: 0x7fd2c0a22ab5 - std::backtrace_rs::backtrace::libunwind::trace::h90ef53671b8f35e2 at /rustc/c6727fc9b5c64cefa7263486497ee95e529bd0f8/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5 1: 0x7fd2c0a22ab5 - std::backtrace_rs::backtrace::trace_unsynchronized::h4f56cd06e6931e36 at /rustc/c6727fc9b5c64cefa7263486497ee95e529bd0f8/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x7fd2c0a22ab5 - std::sys::backtrace::_print_fmt::hc7ca1bfe672db1b4 at /rustc/c6727fc9b5c64cefa7263486497ee95e529bd0f8/library/std/src/sys/backtrace.rs:68:5 3: 0x7fd2c0a22ab5 - ::fmt::h103b2337102fecbf at /rustc/c6727fc9b5c64cefa7263486497ee95e529bd0f8/library/std/src/sys/backtrace.rs:44:22 4: 0x7fd2c0a7250b - core::fmt::rt::Argument::fmt::h1c3f905c574b7e34 at /rustc/c6727fc9b5c64cefa7263486497ee95e529bd0f8/library/core/src/fmt/rt.rs:173:76 5: 0x7fd2c0a7250b - core::fmt::write::h7386266427c35607 at /rustc/c6727fc9b5c64cefa7263486497ee95e529bd0f8/library/core/src/fmt/mod.rs:1182:21 6: 0x7fd2c0a173ef - std::io::Write::write_fmt::h6342dfcd770ba156 at /rustc/c6727fc9b5c64cefa7263486497ee95e529bd0f8/library/std/src/io/mod.rs:1835:15 7: 0x7fd2c0a2288e - std::sys::backtrace::_print::h4286525352765247 at /rustc/c6727fc9b5c64cefa7263486497ee95e529bd0f8/library/std/src/sys/backtrace.rs:47:5 8: 0x7fd2c0a2288e - std::sys::backtrace::print::hc98e431c340084b2 at /rustc/c6727fc9b5c64cefa7263486497ee95e529bd0f8/library/std/src/sys/backtrace.rs:34:9 9: 0x7fd2c0a251d9 - std::panicking::default_hook::{{closure}}::h2ab543053f1e54a6 10: 0x7fd2c0a24f7c - std::panicking::default_hook::ha284c4ce18b0445e at /rustc/c6727fc9b5c64cefa7263486497ee95e529bd0f8/library/std/src/panicking.rs:292:9 11: 0x7fd2c3ea21fa - std[85c3ca4c170da0bb]::panicking::update_hook::>::{closure#0} 12: 0x7fd2c0a25aff - as core::ops::function::Fn>::call::hbe29137bf798c82c at /rustc/c6727fc9b5c64cefa7263486497ee95e529bd0f8/library/alloc/src/boxed.rs:2078:9 13: 0x7fd2c0a25aff - std::panicking::rust_panic_with_hook::h869b30cecbb157c4 at /rustc/c6727fc9b5c64cefa7263486497ee95e529bd0f8/library/std/src/panicking.rs:804:13 14: 0x7fd2c3edd151 - std[85c3ca4c170da0bb]::panicking::begin_panic::::{closure#0} 15: 0x7fd2c3ed0106 - std[85c3ca4c170da0bb]::sys::backtrace::__rust_end_short_backtrace::::{closure#0}, !> 16: 0x7fd2c3ed00b6 - std[85c3ca4c170da0bb]::panicking::begin_panic:: 17: 0x7fd2c3ee6391 - ::emit_producing_guarantee 18: 0x7fd2c44f3664 - rustc_middle[aeeec62211ae3a75]::util::bug::opt_span_bug_fmt::::{closure#0} 19: 0x7fd2c44d9eda - rustc_middle[aeeec62211ae3a75]::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0} 20: 0x7fd2c44d9d5b - rustc_middle[aeeec62211ae3a75]::ty::context::tls::with_context_opt::::{closure#0}, !>::{closure#0}, !> 21: 0x7fd2c1e89d50 - rustc_middle[aeeec62211ae3a75]::util::bug::bug_fmt 22: 0x7fd2c5cdfe22 - rustc_trait_selection[32a10b8e227ae023]::traits::project::opt_normalize_projection_term 23: 0x7fd2c5ccbc0d - >::fold_ty 24: 0x7fd2c5d252fb - ::normalize:: 25: 0x7fd2c5d2628b - ::lower_ty_common::{closure#0} 26: 0x7fd2c5d455c4 - ::declare 27: 0x7fd2c2daa1a2 - ::visit_expr 28: 0x7fd2c57fe56d - rustc_hir_typeck[4115a8e785646128]::check::check_fn 29: 0x7fd2c5e6ee07 - rustc_hir_typeck[4115a8e785646128]::typeck 30: 0x7fd2c5e6e79d - rustc_query_impl[1a70eeac4d27cd99]::plumbing::__rust_begin_short_backtrace::> 31: 0x7fd2c5820073 - rustc_query_system[a1535082eb398a6e]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[1a70eeac4d27cd99]::plumbing::QueryCtxt, false> 32: 0x7fd2c581f24d - rustc_query_impl[1a70eeac4d27cd99]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace 33: 0x7fd2c581ee44 - ::par_body_owners::::{closure#0} 34: 0x7fd2c581cc7c - rustc_hir_analysis[45c875b93a141787]::check_crate 35: 0x7fd2c5813355 - rustc_interface[a6452cf60fc426fe]::passes::analysis 36: 0x7fd2c5812f07 - rustc_query_impl[1a70eeac4d27cd99]::plumbing::__rust_begin_short_backtrace::> 37: 0x7fd2c6389665 - rustc_query_system[a1535082eb398a6e]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[1a70eeac4d27cd99]::plumbing::QueryCtxt, false> 38: 0x7fd2c63893cf - rustc_query_impl[1a70eeac4d27cd99]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace 39: 0x7fd2c6259745 - rustc_interface[a6452cf60fc426fe]::interface::run_compiler::, rustc_driver_impl[dc4b00a9cfefcaac]::run_compiler::{closure#0}>::{closure#1} 40: 0x7fd2c6226589 - std[85c3ca4c170da0bb]::sys::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[dc4b00a9cfefcaac]::run_compiler::{closure#0}>::{closure#1}, core[2213ecb858fb81d5]::result::Result<(), rustc_span[67819806738ee56d]::ErrorGuaranteed>>::{closure#0}, core[2213ecb858fb81d5]::result::Result<(), rustc_span[67819806738ee56d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[2213ecb858fb81d5]::result::Result<(), rustc_span[67819806738ee56d]::ErrorGuaranteed>> 41: 0x7fd2c622633a - <::spawn_unchecked_, rustc_driver_impl[dc4b00a9cfefcaac]::run_compiler::{closure#0}>::{closure#1}, core[2213ecb858fb81d5]::result::Result<(), rustc_span[67819806738ee56d]::ErrorGuaranteed>>::{closure#0}, core[2213ecb858fb81d5]::result::Result<(), rustc_span[67819806738ee56d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[2213ecb858fb81d5]::result::Result<(), rustc_span[67819806738ee56d]::ErrorGuaranteed>>::{closure#2} as core[2213ecb858fb81d5]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 42: 0x7fd2c0a2f95b - as core::ops::function::FnOnce>::call_once::h7aa527871fe5008e at /rustc/c6727fc9b5c64cefa7263486497ee95e529bd0f8/library/alloc/src/boxed.rs:2064:9 43: 0x7fd2c0a2f95b - as core::ops::function::FnOnce>::call_once::h661f413d6ffad84b at /rustc/c6727fc9b5c64cefa7263486497ee95e529bd0f8/library/alloc/src/boxed.rs:2064:9 44: 0x7fd2c0a2f95b - std::sys::pal::unix::thread::Thread::new::thread_start::h77623da8b368e6ce at /rustc/c6727fc9b5c64cefa7263486497ee95e529bd0f8/library/std/src/sys/pal/unix/thread.rs:108:17 45: 0x7fd2c0939609 - start_thread 46: 0x7fd2c085c353 - clone 47: 0x0 - 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 `/playground/rustc-ice-2024-07-15T03_34_45-244.txt` to your bug report note: compiler flags: --crate-type lib -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 note: some of the compiler flags provided by cargo are hidden query stack during panic: #0 [typeck] type-checking `f` #1 [analysis] running analysis passes on this crate end of query stack For more information about this error, try `rustc --explain E0380`. error: could not compile `playground` (lib) due to 1 previous error ```

@rustbot label -F-unboxed_closures +F-auto_traits

GrigorenkoPV commented 4 months ago
#![feature(auto_traits)]
#![feature(unboxed_closures)]

trait T {}

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

auto trait Fn {
    type Output;
}

fn main() {}

Regression in nightly-2024-01-11 (190f4c96116a3b59b7de4881cfec544be0246d84...a2d9d73e608f1b24eba840c4fd2d68dbe3b65e01)

Minimized:

#![feature(auto_traits)]

auto trait Trait {
    type Output;
}

fn f() {
    let _: <i32 as Trait>::Output = 1_i64;
}

Regression in nightly-2023-06-18 (6bba061467f7c2cab04b262b95eb67bf89265587...3b2073f0762cff4d3d625bb10017e0ce4e7abe50)

matthiaskrgr commented 4 months ago

probably just another duplicate of https://github.com/rust-lang/rust/issues/117829