Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE: min_specialization: "When translating substitutions for specialization, the expected specialization failed to hold" #108781

Closed
matthiaskrgr opened this issue Mar 5, 2023 · 3 comments · Fixed by #108947
Assignees
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

Code

#![crate_type = "lib"]
#![feature(min_specialization)]

#[derive(Copy)]
struct S<const N: [f32; N]>([f32; f32N]);

#[derive(Copy)]
struct S<const N: usize>([f32; N]);

Meta

rustc --version --verbose:

rustc 1.70.0-nightly (f15f0ea73 2023-03-04)
binary: rustc
commit-hash: f15f0ea73972786e426732c5b92ba9a904b866c4
commit-date: 2023-03-04
host: x86_64-unknown-linux-gnu
release: 1.70.0-nightly
LLVM version: 15.0.7

Error output

error[E0428]: the name `S` is defined multiple times
 --> b61f5be57812969e152a6c4cfc3e11c8e716c601.rs:8:1
  |
5 | struct S<const N: [f32; N]>([f32; f32N]);
  | ----------------------------------------- previous definition of the type `S` here
...
8 | struct S<const N: usize>([f32; N]);
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `S` redefined here
  |
  = note: `S` must be defined only once in the type namespace of this module

error[E0770]: the type of const parameters must not depend on other generic parameters
 --> b61f5be57812969e152a6c4cfc3e11c8e716c601.rs:5:25
  |
5 | struct S<const N: [f32; N]>([f32; f32N]);
  |                         ^ the type must not depend on the parameter `N`

error[E0425]: cannot find value `f32N` in this scope
 --> b61f5be57812969e152a6c4cfc3e11c8e716c601.rs:5:35
  |
5 | struct S<const N: [f32; N]>([f32; f32N]);
  |                                   ^^^^ not found in this scope
Backtrace

error: internal compiler error: compiler/rustc_trait_selection/src/traits/specialize/mod.rs:103:21: When translating substitutions for specialization, the expected specialization failed to hold

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/f15f0ea73972786e426732c5b92ba9a904b866c4/compiler/rustc_errors/src/lib.rs:1644:9
stack backtrace:
   0:     0x7f1a1fd6731a - std::backtrace_rs::backtrace::libunwind::trace::h4383e0c48d800fd4
                               at /rustc/f15f0ea73972786e426732c5b92ba9a904b866c4/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f1a1fd6731a - std::backtrace_rs::backtrace::trace_unsynchronized::h6816d26f08117b4d
                               at /rustc/f15f0ea73972786e426732c5b92ba9a904b866c4/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f1a1fd6731a - std::sys_common::backtrace::_print_fmt::hfa640639b16271d1
                               at /rustc/f15f0ea73972786e426732c5b92ba9a904b866c4/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7f1a1fd6731a - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h4c6c2e6def629543
                               at /rustc/f15f0ea73972786e426732c5b92ba9a904b866c4/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f1a1fdcab6e - core::fmt::write::h2c9efad132a334c1
                               at /rustc/f15f0ea73972786e426732c5b92ba9a904b866c4/library/core/src/fmt/mod.rs:1232:17
   5:     0x7f1a1fd5a1c5 - std::io::Write::write_fmt::h814bf5ade5b0eb41
                               at /rustc/f15f0ea73972786e426732c5b92ba9a904b866c4/library/std/src/io/mod.rs:1684:15
   6:     0x7f1a1fd670e5 - std::sys_common::backtrace::_print::h4c645f879d3eaa7a
                               at /rustc/f15f0ea73972786e426732c5b92ba9a904b866c4/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x7f1a1fd670e5 - std::sys_common::backtrace::print::h3e307a47c9a19510
                               at /rustc/f15f0ea73972786e426732c5b92ba9a904b866c4/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x7f1a1fd69e5f - std::panicking::default_hook::{{closure}}::h3c9ff47c1a2169d5
                               at /rustc/f15f0ea73972786e426732c5b92ba9a904b866c4/library/std/src/panicking.rs:271:22
   9:     0x7f1a1fd69b9b - std::panicking::default_hook::hce8f146ffdc07b27
                               at /rustc/f15f0ea73972786e426732c5b92ba9a904b866c4/library/std/src/panicking.rs:290:9
  10:     0x7f1a22fca2c5 - <rustc_driver_impl[e33d8e87dcf28fa7]::DEFAULT_HOOK::{closure#0}::{closure#0} as core[c90df6780de66b4]::ops::function::FnOnce<(&core[c90df6780de66b4]::panic::panic_info::PanicInfo,)>>::call_once::{shim:vtable#0}
  11:     0x7f1a1fd6a69d - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hbd4f97d1b3fd7f45
                               at /rustc/f15f0ea73972786e426732c5b92ba9a904b866c4/library/alloc/src/boxed.rs:2001:9
  12:     0x7f1a1fd6a69d - std::panicking::rust_panic_with_hook::h0f93e1b62c36cd62
                               at /rustc/f15f0ea73972786e426732c5b92ba9a904b866c4/library/std/src/panicking.rs:696:13
  13:     0x7f1a23526d01 - std[9d05f37f2a0d456e]::panicking::begin_panic::<rustc_errors[30477a6b69c2e257]::ExplicitBug>::{closure#0}
  14:     0x7f1a2351f386 - std[9d05f37f2a0d456e]::sys_common::backtrace::__rust_end_short_backtrace::<std[9d05f37f2a0d456e]::panicking::begin_panic<rustc_errors[30477a6b69c2e257]::ExplicitBug>::{closure#0}, !>
  15:     0x7f1a23594d66 - std[9d05f37f2a0d456e]::panicking::begin_panic::<rustc_errors[30477a6b69c2e257]::ExplicitBug>
  16:     0x7f1a23572c06 - std[9d05f37f2a0d456e]::panic::panic_any::<rustc_errors[30477a6b69c2e257]::ExplicitBug>
  17:     0x7f1a2356e666 - <rustc_errors[30477a6b69c2e257]::HandlerInner>::bug::<&alloc[7c217260d604da75]::string::String>
  18:     0x7f1a2356e330 - <rustc_errors[30477a6b69c2e257]::Handler>::bug::<&alloc[7c217260d604da75]::string::String>
  19:     0x7f1a235654db - rustc_middle[cce008c1292a9385]::util::bug::opt_span_bug_fmt::<rustc_span[9d8165e91f6b103d]::span_encoding::Span>::{closure#0}
  20:     0x7f1a23563e2a - rustc_middle[cce008c1292a9385]::ty::context::tls::with_opt::<rustc_middle[cce008c1292a9385]::util::bug::opt_span_bug_fmt<rustc_span[9d8165e91f6b103d]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0x7f1a23563df6 - rustc_middle[cce008c1292a9385]::ty::context::tls::with_context_opt::<rustc_middle[cce008c1292a9385]::ty::context::tls::with_opt<rustc_middle[cce008c1292a9385]::util::bug::opt_span_bug_fmt<rustc_span[9d8165e91f6b103d]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0x7f1a23565426 - rustc_middle[cce008c1292a9385]::util::bug::opt_span_bug_fmt::<rustc_span[9d8165e91f6b103d]::span_encoding::Span>
  23:     0x7f1a216deb73 - rustc_middle[cce008c1292a9385]::util::bug::bug_fmt
  24:     0x7f1a21605896 - rustc_trait_selection[6c766aae540ef51f]::traits::specialize::translate_substs
  25:     0x7f1a22355b69 - rustc_hir_analysis[e0a40ec4e05edc38]::impl_wf_check::check_mod_impl_wf
  26:     0x7f1a22651841 - rustc_query_system[637feee9637b99c]::query::plumbing::try_execute_query::<rustc_query_impl[2e65c241cbff84cd]::queries::check_mod_impl_wf, rustc_query_impl[2e65c241cbff84cd]::plumbing::QueryCtxt>
  27:     0x7f1a226513ea - <rustc_query_impl[2e65c241cbff84cd]::Queries as rustc_middle[cce008c1292a9385]::ty::query::QueryEngine>::check_mod_impl_wf
  28:     0x7f1a212e871f - <rustc_middle[cce008c1292a9385]::hir::map::Map>::for_each_module::<rustc_hir_analysis[e0a40ec4e05edc38]::check_crate::{closure#2}::{closure#0}::{closure#0}>
  29:     0x7f1a212e8218 - <rustc_session[1facd9ff6612a9d8]::session::Session>::track_errors::<rustc_hir_analysis[e0a40ec4e05edc38]::check_crate::{closure#2}, ()>
  30:     0x7f1a212e5673 - rustc_hir_analysis[e0a40ec4e05edc38]::check_crate
  31:     0x7f1a212d9a22 - rustc_interface[6a01411731a6f2f2]::passes::analysis
  32:     0x7f1a228291fd - rustc_query_system[637feee9637b99c]::query::plumbing::try_execute_query::<rustc_query_impl[2e65c241cbff84cd]::queries::analysis, rustc_query_impl[2e65c241cbff84cd]::plumbing::QueryCtxt>
  33:     0x7f1a22828eff - <rustc_query_impl[2e65c241cbff84cd]::Queries as rustc_middle[cce008c1292a9385]::ty::query::QueryEngine>::analysis
  34:     0x7f1a226539d6 - <rustc_middle[cce008c1292a9385]::ty::context::GlobalCtxt>::enter::<rustc_driver_impl[e33d8e87dcf28fa7]::run_compiler::{closure#1}::{closure#2}::{closure#4}, core[c90df6780de66b4]::result::Result<(), rustc_span[9d8165e91f6b103d]::ErrorGuaranteed>>
  35:     0x7f1a22229238 - rustc_span[9d8165e91f6b103d]::with_source_map::<core[c90df6780de66b4]::result::Result<(), rustc_span[9d8165e91f6b103d]::ErrorGuaranteed>, rustc_interface[6a01411731a6f2f2]::interface::run_compiler<core[c90df6780de66b4]::result::Result<(), rustc_span[9d8165e91f6b103d]::ErrorGuaranteed>, rustc_driver_impl[e33d8e87dcf28fa7]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  36:     0x7f1a222208bc - std[9d05f37f2a0d456e]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[6a01411731a6f2f2]::util::run_in_thread_pool_with_globals<rustc_interface[6a01411731a6f2f2]::interface::run_compiler<core[c90df6780de66b4]::result::Result<(), rustc_span[9d8165e91f6b103d]::ErrorGuaranteed>, rustc_driver_impl[e33d8e87dcf28fa7]::run_compiler::{closure#1}>::{closure#0}, core[c90df6780de66b4]::result::Result<(), rustc_span[9d8165e91f6b103d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[c90df6780de66b4]::result::Result<(), rustc_span[9d8165e91f6b103d]::ErrorGuaranteed>>
  37:     0x7f1a222202ea - <<std[9d05f37f2a0d456e]::thread::Builder>::spawn_unchecked_<rustc_interface[6a01411731a6f2f2]::util::run_in_thread_pool_with_globals<rustc_interface[6a01411731a6f2f2]::interface::run_compiler<core[c90df6780de66b4]::result::Result<(), rustc_span[9d8165e91f6b103d]::ErrorGuaranteed>, rustc_driver_impl[e33d8e87dcf28fa7]::run_compiler::{closure#1}>::{closure#0}, core[c90df6780de66b4]::result::Result<(), rustc_span[9d8165e91f6b103d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[c90df6780de66b4]::result::Result<(), rustc_span[9d8165e91f6b103d]::ErrorGuaranteed>>::{closure#1} as core[c90df6780de66b4]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  38:     0x7f1a1fd74593 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h437f2034e21e0804
                               at /rustc/f15f0ea73972786e426732c5b92ba9a904b866c4/library/alloc/src/boxed.rs:1987:9
  39:     0x7f1a1fd74593 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h9ba15d2eeb7a9119
                               at /rustc/f15f0ea73972786e426732c5b92ba9a904b866c4/library/alloc/src/boxed.rs:1987:9
  40:     0x7f1a1fd74593 - std::sys::unix::thread::Thread::new::thread_start::h41ec441a67c2e320
                               at /rustc/f15f0ea73972786e426732c5b92ba9a904b866c4/library/std/src/sys/unix/thread.rs:108:17
  41:     0x7f1a1fb06bb5 - <unknown>
  42:     0x7f1a1fb88d90 - <unknown>
  43:                0x0 - <unknown>

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: rustc 1.70.0-nightly (f15f0ea73 2023-03-04) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [check_mod_impl_wf] checking that impls are well-formed in top-level module
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 4 previous errors

Some errors have detailed explanations: E0425, E0428, E0770.
For more information about an error, try `rustc --explain E0425`.

@matthiaskrgr matthiaskrgr added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. requires-nightly This issue requires a nightly compiler in some way. labels Mar 5, 2023
@compiler-errors
Copy link
Member

Minimal:

#![feature(min_specialization)]

struct S<const N: usize>;
impl<const N: i32> Copy for S<N> {}
impl<const N: usize> Copy for S<N> {}

@compiler-errors compiler-errors self-assigned this Mar 5, 2023
@compiler-errors
Copy link
Member

compiler-errors commented Mar 8, 2023

This regressed in #107965, cc @BoxyUwU.

I'll take a look at this -- I think it has something to do with the overlap check failing (succeeding? failing to detect overlap) because of the new ConstArgHasType obligations needed for S to be WF.

@compiler-errors
Copy link
Member

Lol, yeah, the specialization graph considers impl<const N: i32> Copy for S<N> {} to specialize impl<const N: usize> Copy for S<N> {} because the trait refs unify (lol) and the first impl has obligations that are not satisfied by the second, but not vice versa (lol).

I think I'm just gonna delay a bug here, though it may be entertaining to consider returning a real type error when trying to unify two consts with differing types...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants