Open
Description
I tried this code:
#![feature(generic_const_exprs)]
#![feature(associated_const_equality)]
use std::marker::PhantomData;
trait Foo {
const ASSOC: usize;
}
struct Bar<const S: usize> {
a: PhantomData<[u8; S]>,
}
impl<const S: usize> Foo for Bar<S> {
const ASSOC: usize = S;
}
fn func<const S: usize>() -> impl Foo<ASSOC = {<Bar<S> as Foo>::ASSOC}> {
Bar::<S> { a: PhantomData }
}
I expected to see this happen: The opaque type to be coerced to the return type as the constants are equal
Instead, this happened: The compiler is saying that the types are not equal. If the associated const in the return type is removed, the code compiles without issue.
Meta
rustc --version --verbose
:
rustc 1.76.0-nightly (2c1b65ee1 2023-11-11)
binary: rustc
commit-hash: 2c1b65ee1431f8d3fe2142e821eb13c623bbf8a0
commit-date: 2023-11-11
host: aarch64-apple-darwin
release: 1.76.0-nightly
LLVM version: 17.0.4
Backtrace
wutter@Williams-MacBook-Pro src % RUST_BACKTRACE=1 RUSTC_LOG=log rustc +nightly main.rs -Z treat-err-as-bug
warning: some trace filter directives would enable traces that are disabled statically
note: `log=trace` would enable the TRACE level for the `log` target
note: the static max level is `info`
help: to enable DEBUG logging, remove the `max_level_info` feature from the `tracing` crate
warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
--> main.rs:1:12
|
1 | #![feature(generic_const_exprs)]
| ^^^^^^^^^^^^^^^^^^^
|
= note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
= note: `#[warn(incomplete_features)]` on by default
error[E0308]: mismatched types
--> main.rs:18:30
|
18 | fn func<const S: usize>() -> impl Foo<ASSOC = {<Bar<S> as Foo>::ASSOC}> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `<Bar<S> as Foo>::ASSOC`, found `{<Bar<S> as Foo>::ASSOC}`
|
= note: expected constant `<Bar<S> as Foo>::ASSOC`
found constant `{<Bar<S> as Foo>::ASSOC}`
thread 'rustc' panicked at compiler/rustc_errors/src/lib.rs:1738:30:
aborting due to `-Z treat-err-as-bug=1`
stack backtrace:
0: _rust_begin_unwind
1: core::panicking::panic_fmt
2: <rustc_errors::HandlerInner>::panic_if_treat_err_as_bug
3: <rustc_errors::HandlerInner>::emit_diagnostic::{closure#2}
4: rustc_interface::callbacks::track_diagnostic
5: <rustc_errors::HandlerInner>::emit_diagnostic
6: <rustc_errors::Handler>::emit_diagnostic
7: <rustc_span::ErrorGuaranteed as rustc_errors::diagnostic_builder::EmissionGuarantee>::diagnostic_builder_emit_producing_guarantee
8: <rustc_infer::infer::error_reporting::TypeErrCtxt as rustc_trait_selection::traits::error_reporting::type_err_ctxt_ext::InferCtxtPrivExt>::report_fulfillment_error
9: <rustc_infer::infer::error_reporting::TypeErrCtxt as rustc_trait_selection::traits::error_reporting::type_err_ctxt_ext::TypeErrCtxtExt>::report_fulfillment_errors
10: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_return_expr
11: rustc_hir_typeck::check::check_fn
12: rustc_hir_typeck::typeck
[... omitted 2 frames ...]
13: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>>>
14: rustc_hir_analysis::collect::type_of::opaque::find_opaque_ty_constraints_for_rpit
[... omitted 2 frames ...]
15: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::DefId, rustc_middle::query::erase::Erased<[u8; 8]>>>
16: rustc_hir_analysis::collect::type_of::type_of
[... omitted 2 frames ...]
17: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::DefId, rustc_middle::query::erase::Erased<[u8; 8]>>>
18: rustc_hir_analysis::check::check::check_item_type
19: rustc_hir_analysis::check::check::check_mod_item_types
[... omitted 2 frames ...]
20: <rustc_middle::hir::map::Map>::for_each_module::<rustc_hir_analysis::check_crate::{closure#5}::{closure#0}>
21: rustc_hir_analysis::check_crate
22: rustc_interface::passes::analysis
[... omitted 2 frames ...]
23: <rustc_middle::ty::context::GlobalCtxt>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}::{closure#6}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
24: <rustc_interface::interface::Compiler>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_span::ErrorGuaranteed>>
25: rustc_span::set_source_map::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
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 attach the file at `/Users/wutter/dev/c_test/src/rustc-ice-2023-11-15T01_14_45-74879.txt` to your bug report
note: compiler flags: -Z treat-err-as-bug
query stack during panic:
#0 [typeck] type-checking `func`
#1 [type_of_opaque] computing type of opaque `func::{opaque#0}`
#2 [type_of] computing type of `func::{opaque#0}`
#3 [check_mod_item_types] checking item types in top-level module
#4 [analysis] running analysis passes on this crate
end of query stack
error: internal compiler error: {OpaqueTypeKey { def_id: DefId(0:19 ~ main[2f94]::func::{opaque#0}), args: [S/#0: usize] }: OpaqueTypeDecl { hidden_type: OpaqueHiddenType { span: main.rs:18:30: 18:72 (#4), ty: ?0t } }}
thread 'rustc' panicked at compiler/rustc_errors/src/lib.rs:1746:25:
aborting after 2 errors due to `-Z treat-err-as-bug=1`
stack backtrace:
0: 0x103201314 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hb9ebedcbc23b10d0
1: 0x1032432d8 - core::fmt::write::he0b2e8e8c929d646
2: 0x1031f7a48 - std::io::Write::write_fmt::h0960618879d4216c
3: 0x103201150 - std::sys_common::backtrace::print::h68d22bbf1485ed7a
4: 0x103203b50 - std::panicking::default_hook::{{closure}}::h323a3c9be995dd8d
5: 0x103203898 - std::panicking::default_hook::h3178081fe3d6696e
6: 0x10c61fd50 - <alloc[3eec36f0695f91dd]::boxed::Box<rustc_driver_impl[b18e1ff6c233986d]::install_ice_hook::{closure#0}> as core[a3728727bc16c43f]::ops::function::Fn<(&dyn for<'a, 'b> core[a3728727bc16c43f]::ops::function::Fn<(&'a core[a3728727bc16c43f]::panic::panic_info::PanicInfo<'b>,), Output = ()> + core[a3728727bc16c43f]::marker::Sync + core[a3728727bc16c43f]::marker::Send, &core[a3728727bc16c43f]::panic::panic_info::PanicInfo)>>::call
7: 0x1032041c8 - std::panicking::rust_panic_with_hook::hb82fa29ca1cfd15b
8: 0x103203f90 - std::panicking::begin_panic_handler::{{closure}}::hba8a5811f2860467
9: 0x10320177c - std::sys_common::backtrace::__rust_end_short_backtrace::h8d6f5d4f0729b511
10: 0x103203d2c - _rust_begin_unwind
11: 0x10325d128 - core::panicking::panic_fmt::hec9d5dd17af33c2f
12: 0x10c6581ec - <rustc_errors[40606b26c3d6373]::HandlerInner>::panic_if_treat_err_as_bug
13: 0x10c657710 - <rustc_errors[40606b26c3d6373]::HandlerInner>::emit_diagnostic::{closure#2}
14: 0x10cd788ac - rustc_interface[cd87de0d474aaed5]::callbacks::track_diagnostic
15: 0x10c657174 - <rustc_errors[40606b26c3d6373]::HandlerInner>::emit_diagnostic
16: 0x10cc2e540 - <rustc_errors[40606b26c3d6373]::HandlerInner>::emit_diag_at_span::<rustc_span[27a5aeb524309f01]::span_encoding::Span>
17: 0x10cc2e714 - <rustc_errors[40606b26c3d6373]::HandlerInner>::span_bug::<rustc_span[27a5aeb524309f01]::span_encoding::Span, alloc[3eec36f0695f91dd]::string::String>
18: 0x10cc2d558 - <rustc_errors[40606b26c3d6373]::Handler>::delay_span_bug::<rustc_span[27a5aeb524309f01]::span_encoding::Span, alloc[3eec36f0695f91dd]::string::String>
19: 0x10ca8cbe8 - core[a3728727bc16c43f]::ptr::drop_in_place::<rustc_hir_typeck[fe10be7b174d6d2f]::inherited::Inherited>
20: 0x10ca98824 - rustc_hir_typeck[fe10be7b174d6d2f]::typeck
21: 0x10d825910 - rustc_query_impl[7f29d27b792675dd]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[7f29d27b792675dd]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b25dbacccc2b5bd2]::query::erase::Erased<[u8; 8usize]>>
22: 0x10d9226f4 - <rustc_query_impl[7f29d27b792675dd]::query_impl::typeck::dynamic_query::{closure#2} as core[a3728727bc16c43f]::ops::function::FnOnce<(rustc_middle[b25dbacccc2b5bd2]::ty::context::TyCtxt, rustc_span[27a5aeb524309f01]::def_id::LocalDefId)>>::call_once
23: 0x10d7daf74 - rustc_query_system[3f4e6b31e9532aea]::query::plumbing::try_execute_query::<rustc_query_impl[7f29d27b792675dd]::DynamicConfig<rustc_query_system[3f4e6b31e9532aea]::query::caches::VecCache<rustc_span[27a5aeb524309f01]::def_id::LocalDefId, rustc_middle[b25dbacccc2b5bd2]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[7f29d27b792675dd]::plumbing::QueryCtxt, false>
24: 0x10d9ea35c - rustc_query_impl[7f29d27b792675dd]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
25: 0x10c910594 - rustc_middle[b25dbacccc2b5bd2]::query::plumbing::query_get_at::<rustc_query_system[3f4e6b31e9532aea]::query::caches::VecCache<rustc_span[27a5aeb524309f01]::def_id::LocalDefId, rustc_middle[b25dbacccc2b5bd2]::query::erase::Erased<[u8; 8usize]>>>
26: 0x10c9231f8 - rustc_hir_analysis[2e3a0b5a7c9d3afd]::collect::type_of::opaque::find_opaque_ty_constraints_for_rpit
27: 0x10d820ed0 - rustc_query_impl[7f29d27b792675dd]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[7f29d27b792675dd]::query_impl::type_of_opaque::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b25dbacccc2b5bd2]::query::erase::Erased<[u8; 8usize]>>
28: 0x10d9f8fac - <rustc_query_impl[7f29d27b792675dd]::query_impl::type_of_opaque::dynamic_query::{closure#2} as core[a3728727bc16c43f]::ops::function::FnOnce<(rustc_middle[b25dbacccc2b5bd2]::ty::context::TyCtxt, rustc_span[27a5aeb524309f01]::def_id::DefId)>>::call_once
29: 0x10d78ed54 - rustc_query_system[3f4e6b31e9532aea]::query::plumbing::try_execute_query::<rustc_query_impl[7f29d27b792675dd]::DynamicConfig<rustc_query_system[3f4e6b31e9532aea]::query::caches::DefaultCache<rustc_span[27a5aeb524309f01]::def_id::DefId, rustc_middle[b25dbacccc2b5bd2]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[7f29d27b792675dd]::plumbing::QueryCtxt, false>
30: 0x10d923060 - rustc_query_impl[7f29d27b792675dd]::query_impl::type_of_opaque::get_query_non_incr::__rust_end_short_backtrace
31: 0x10c8abd80 - rustc_middle[b25dbacccc2b5bd2]::query::plumbing::query_get_at::<rustc_query_system[3f4e6b31e9532aea]::query::caches::DefaultCache<rustc_span[27a5aeb524309f01]::def_id::DefId, rustc_middle[b25dbacccc2b5bd2]::query::erase::Erased<[u8; 8usize]>>>
32: 0x10c8c4e70 - rustc_hir_analysis[2e3a0b5a7c9d3afd]::collect::type_of::type_of
33: 0x10d825984 - rustc_query_impl[7f29d27b792675dd]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[7f29d27b792675dd]::query_impl::type_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b25dbacccc2b5bd2]::query::erase::Erased<[u8; 8usize]>>
34: 0x10d9ff924 - <rustc_query_impl[7f29d27b792675dd]::query_impl::type_of::dynamic_query::{closure#2} as core[a3728727bc16c43f]::ops::function::FnOnce<(rustc_middle[b25dbacccc2b5bd2]::ty::context::TyCtxt, rustc_span[27a5aeb524309f01]::def_id::DefId)>>::call_once
35: 0x10d78ed54 - rustc_query_system[3f4e6b31e9532aea]::query::plumbing::try_execute_query::<rustc_query_impl[7f29d27b792675dd]::DynamicConfig<rustc_query_system[3f4e6b31e9532aea]::query::caches::DefaultCache<rustc_span[27a5aeb524309f01]::def_id::DefId, rustc_middle[b25dbacccc2b5bd2]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[7f29d27b792675dd]::plumbing::QueryCtxt, false>
36: 0x10da00930 - rustc_query_impl[7f29d27b792675dd]::query_impl::type_of::get_query_non_incr::__rust_end_short_backtrace
37: 0x10c8abd80 - rustc_middle[b25dbacccc2b5bd2]::query::plumbing::query_get_at::<rustc_query_system[3f4e6b31e9532aea]::query::caches::DefaultCache<rustc_span[27a5aeb524309f01]::def_id::DefId, rustc_middle[b25dbacccc2b5bd2]::query::erase::Erased<[u8; 8usize]>>>
38: 0x10c8bb5b4 - rustc_hir_analysis[2e3a0b5a7c9d3afd]::check::check::check_item_type
39: 0x10c8c1c5c - rustc_hir_analysis[2e3a0b5a7c9d3afd]::check::check::check_mod_item_types
40: 0x10d8230a0 - rustc_query_impl[7f29d27b792675dd]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[7f29d27b792675dd]::query_impl::check_mod_item_types::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b25dbacccc2b5bd2]::query::erase::Erased<[u8; 0usize]>>
41: 0x10d843538 - <rustc_query_impl[7f29d27b792675dd]::query_impl::check_mod_item_types::dynamic_query::{closure#2} as core[a3728727bc16c43f]::ops::function::FnOnce<(rustc_middle[b25dbacccc2b5bd2]::ty::context::TyCtxt, rustc_span[27a5aeb524309f01]::def_id::LocalModDefId)>>::call_once
42: 0x10d775aa4 - rustc_query_system[3f4e6b31e9532aea]::query::plumbing::try_execute_query::<rustc_query_impl[7f29d27b792675dd]::DynamicConfig<rustc_query_system[3f4e6b31e9532aea]::query::caches::DefaultCache<rustc_span[27a5aeb524309f01]::def_id::LocalModDefId, rustc_middle[b25dbacccc2b5bd2]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[7f29d27b792675dd]::plumbing::QueryCtxt, false>
43: 0x10da0444c - rustc_query_impl[7f29d27b792675dd]::query_impl::check_mod_item_types::get_query_non_incr::__rust_end_short_backtrace
44: 0x10c959404 - <rustc_middle[b25dbacccc2b5bd2]::hir::map::Map>::for_each_module::<rustc_hir_analysis[2e3a0b5a7c9d3afd]::check_crate::{closure#5}::{closure#0}>
45: 0x10c8e31d4 - rustc_hir_analysis[2e3a0b5a7c9d3afd]::check_crate
46: 0x10cd95d78 - rustc_interface[cd87de0d474aaed5]::passes::analysis
47: 0x10d8259ac - rustc_query_impl[7f29d27b792675dd]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[7f29d27b792675dd]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b25dbacccc2b5bd2]::query::erase::Erased<[u8; 1usize]>>
48: 0x10d8eab98 - <rustc_query_impl[7f29d27b792675dd]::query_impl::analysis::dynamic_query::{closure#2} as core[a3728727bc16c43f]::ops::function::FnOnce<(rustc_middle[b25dbacccc2b5bd2]::ty::context::TyCtxt, ())>>::call_once
49: 0x10d73e9f8 - rustc_query_system[3f4e6b31e9532aea]::query::plumbing::try_execute_query::<rustc_query_impl[7f29d27b792675dd]::DynamicConfig<rustc_query_system[3f4e6b31e9532aea]::query::caches::SingleCache<rustc_middle[b25dbacccc2b5bd2]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[7f29d27b792675dd]::plumbing::QueryCtxt, false>
50: 0x10d8eb660 - rustc_query_impl[7f29d27b792675dd]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
51: 0x10c5d5dec - <rustc_middle[b25dbacccc2b5bd2]::ty::context::GlobalCtxt>::enter::<rustc_driver_impl[b18e1ff6c233986d]::run_compiler::{closure#1}::{closure#2}::{closure#6}, core[a3728727bc16c43f]::result::Result<(), rustc_span[27a5aeb524309f01]::ErrorGuaranteed>>
52: 0x10c5941b0 - <rustc_interface[cd87de0d474aaed5]::interface::Compiler>::enter::<rustc_driver_impl[b18e1ff6c233986d]::run_compiler::{closure#1}::{closure#2}, core[a3728727bc16c43f]::result::Result<core[a3728727bc16c43f]::option::Option<rustc_interface[cd87de0d474aaed5]::queries::Linker>, rustc_span[27a5aeb524309f01]::ErrorGuaranteed>>
53: 0x10c5d41b0 - rustc_span[27a5aeb524309f01]::set_source_map::<core[a3728727bc16c43f]::result::Result<(), rustc_span[27a5aeb524309f01]::ErrorGuaranteed>, rustc_interface[cd87de0d474aaed5]::interface::run_compiler<core[a3728727bc16c43f]::result::Result<(), rustc_span[27a5aeb524309f01]::ErrorGuaranteed>, rustc_driver_impl[b18e1ff6c233986d]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
54: 0x10c5dc92c - std[f3dc86d6d90ad197]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[cd87de0d474aaed5]::util::run_in_thread_with_globals<rustc_interface[cd87de0d474aaed5]::util::run_in_thread_pool_with_globals<rustc_interface[cd87de0d474aaed5]::interface::run_compiler<core[a3728727bc16c43f]::result::Result<(), rustc_span[27a5aeb524309f01]::ErrorGuaranteed>, rustc_driver_impl[b18e1ff6c233986d]::run_compiler::{closure#1}>::{closure#0}, core[a3728727bc16c43f]::result::Result<(), rustc_span[27a5aeb524309f01]::ErrorGuaranteed>>::{closure#0}, core[a3728727bc16c43f]::result::Result<(), rustc_span[27a5aeb524309f01]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[a3728727bc16c43f]::result::Result<(), rustc_span[27a5aeb524309f01]::ErrorGuaranteed>>
55: 0x10c60eae8 - <<std[f3dc86d6d90ad197]::thread::Builder>::spawn_unchecked_<rustc_interface[cd87de0d474aaed5]::util::run_in_thread_with_globals<rustc_interface[cd87de0d474aaed5]::util::run_in_thread_pool_with_globals<rustc_interface[cd87de0d474aaed5]::interface::run_compiler<core[a3728727bc16c43f]::result::Result<(), rustc_span[27a5aeb524309f01]::ErrorGuaranteed>, rustc_driver_impl[b18e1ff6c233986d]::run_compiler::{closure#1}>::{closure#0}, core[a3728727bc16c43f]::result::Result<(), rustc_span[27a5aeb524309f01]::ErrorGuaranteed>>::{closure#0}, core[a3728727bc16c43f]::result::Result<(), rustc_span[27a5aeb524309f01]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[a3728727bc16c43f]::result::Result<(), rustc_span[27a5aeb524309f01]::ErrorGuaranteed>>::{closure#1} as core[a3728727bc16c43f]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
56: 0x10320c3c4 - std::sys::unix::thread::Thread::new::thread_start::hbf1197f3e522c03d
57: 0x1b468206c - __pthread_deallocate
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 attach the file at `/Users/wutter/dev/c_test/src/rustc-ice-2023-11-15T01_14_45-74879.txt` to your bug report
note: compiler flags: -Z treat-err-as-bug
query stack during panic:
#0 [typeck] type-checking `func`
#1 [type_of_opaque] computing type of opaque `func::{opaque#0}`
#2 [type_of] computing type of `func::{opaque#0}`
#3 [check_mod_item_types] checking item types in top-level module
#4 [analysis] running analysis passes on this crate
end of query stack
thread 'rustc' panicked at library/core/src/panicking.rs:144:5:
panic in a destructor during cleanup
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
To Do