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

panic on trait implementation selection when using adt_const_params #89690

Closed
superwhiskers opened this issue Oct 8, 2021 · 8 comments
Closed
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-adt_const_params `#![feature(adt_const_params)]` 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.

Comments

@superwhiskers
Copy link

superwhiskers commented Oct 8, 2021

code

#![allow(incomplete_features)]
#![feature(adt_const_params)]

#[derive(PartialEq, Eq)]
pub enum A {
    A,
    B,
}

pub trait B<const __: &'static A> {
    fn a(&self) {}
}

struct C;

impl B<{ &A::A }> for C {}

impl B<{ &A::B }> for C {}

fn ice() {
    B::<{ &A::A }>::a(&C);
}

meta

this is only possible on the nightly version, due to it using an unstable and incomplete feature (adt_const_params)

rustc --version --verbose:

rustc 1.57.0-nightly (485ced56b 2021-10-07) 

error

thread 'rustc' panicked at 'forcing query with already existing `DepNode`
- query-key: Canonical { max_universe: U0, variables: [], value: ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: UserFacing }, value: Binder(TraitPredicate(<C as B<{&_: &'static A}>>), []) } }
- dep-node: evaluate_obligation(bcbd867fecf3da2d-c598572d933665fd)', /rustc/485ced56b8753ec86936903f2a8c95e9be8996a1/compiler/rustc_query_system/src/dep_graph/graph.rs:247:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

note: 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: rustc 1.57.0-nightly (485ced56b 2021-10-07) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [evaluate_obligation] evaluating trait selection obligation `C: B<{&_: &'static A}>`
#1 [typeck] type-checking `test::ice`
end of query stack
error: could not compile `rust`

backtrace

thread 'rustc' panicked at 'forcing query with already existing `DepNode`
- query-key: Canonical { max_universe: U0, variables: [], value: ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: UserFacing }, value: Binder(TraitPredicate(<C as B<{&_: &'static A}>>), []) } }
- dep-node: evaluate_obligation(bcbd867fecf3da2d-c598572d933665fd)', /rustc/485ced56b8753ec86936903f2a8c95e9be8996a1/compiler/rustc_query_system/src/dep_graph/graph.rs:247:9
stack backtrace:
   0: rust_begin_unwind
             at /rustc/485ced56b8753ec86936903f2a8c95e9be8996a1/library/std/src/panicking.rs:517:5
   1: core::panicking::panic_fmt
             at /rustc/485ced56b8753ec86936903f2a8c95e9be8996a1/library/core/src/panicking.rs:100:14
   2: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
   3: rustc_data_structures::stack::ensure_sufficient_stack
   4: rustc_query_system::query::plumbing::get_query
   5: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::evaluate_obligation
   6: rustc_trait_selection::traits::fulfill::FulfillProcessor::progress_changed_obligations
   7: rustc_data_structures::obligation_forest::ObligationForest<O>::process_obligations
   8: <rustc_trait_selection::traits::fulfill::FulfillmentContext as rustc_infer::traits::engine::TraitEngine>::select_with_constness_where_possible
   9: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_argument_types
  10: rustc_typeck::check::callee::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_call
  11: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  12: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  13: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_stmt
  14: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_block_with_expected
  15: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  16: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_return_expr
  17: rustc_typeck::check::check::check_fn
  18: rustc_infer::infer::InferCtxtBuilder::enter
  19: rustc_typeck::check::typeck
  20: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  21: rustc_data_structures::stack::ensure_sufficient_stack
  22: rustc_query_system::query::plumbing::try_execute_query
  23: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck
  24: rustc_typeck::collect::type_of::opt_const_param_of
  25: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  26: rustc_data_structures::stack::ensure_sufficient_stack
  27: rustc_query_system::query::plumbing::try_execute_query
  28: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::opt_const_param_of
  29: rustc_typeck::check::typeck
  30: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  31: rustc_data_structures::stack::ensure_sufficient_stack
  32: rustc_query_system::query::plumbing::try_execute_query
  33: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck
  34: rustc_data_structures::sync::par_for_each_in
  35: rustc_typeck::check::typeck_item_bodies
  36: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  37: rustc_data_structures::stack::ensure_sufficient_stack
  38: rustc_query_system::query::plumbing::try_execute_query
  39: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck_item_bodies
  40: rustc_session::utils::<impl rustc_session::session::Session>::time
  41: rustc_typeck::check_crate
  42: rustc_interface::passes::analysis
  43: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  44: rustc_data_structures::stack::ensure_sufficient_stack
  45: rustc_query_system::query::plumbing::try_execute_query
  46: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
  47: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  48: rustc_span::with_source_map
  49: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: internal compiler error: unexpected panic

note: 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: rustc 1.57.0-nightly (485ced56b 2021-10-07) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [evaluate_obligation] evaluating trait selection obligation `C: B<{&_: &'static A}>`
#1 [typeck] type-checking `test::ice`
#2 [opt_const_param_of] computing the optional const parameter of `test::ice::{constant#0}`
#3 [typeck] type-checking `test::ice::{constant#0}`
#4 [typeck_item_bodies] type-checking all item bodies
#5 [analysis] running analysis passes on this crate
end of query stack
error: could not compile `rust`

details

this panic is not triggered if the source is compiled with rustc directly (assuming the ice function is renamed to main). this detail may or may not be useful, but i ran into this distinction trying to reproduce it.

the error returned instead is this:

error[E0277]: the trait bound `C: B<{&_: &'static A}>` is not satisfied
  --> lib.rs:22:23
   |
22 |     B::<{ &A::A }>::a(&C);
   |     ----------------- ^^ the trait `B<{&_: &'static A}>` is not implemented for `C`
   |     |
   |     required by a bound introduced by this call
   |
   = help: the following implementations were found:
             <C as B<{&_: &'static A}>>
             <C as B<{&_: &'static A}>>
note: required by `B::a`
  --> lib.rs:11:5
   |
11 |     fn a(&self) {}
   |     ^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
@superwhiskers superwhiskers added C-bug Category: This is a bug. 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. labels Oct 8, 2021
@BoxyUwU BoxyUwU added A-const-generics Area: const generics (parameters and arguments) F-adt_const_params `#![feature(adt_const_params)]` labels Oct 9, 2021
@barrowsys
Copy link

note that passing const parameter by value does not trigger ICE

#![allow(incomplete_features)]
#![feature(adt_const_params)]

#[derive(PartialEq, Eq)]
pub enum A {
    A,
    B,
}

pub trait B<const __: A> {
    fn a(&self) {}
}

struct C;

impl B<{ A::A }> for C {}

impl B<{ A::B }> for C {}

fn no_ice() {
    B::<{ A::A }>::a(&C);
}

@b-naber
Copy link
Contributor

b-naber commented Oct 28, 2021

This doesn't ICE anymore, now gives the following error, which looks correct to me since &A::A : 'static doesn't hold:

error[E0277]: the trait bound `C: B<{&_: &'static A}>` is not satisfied
  --> src/lib.rs:21:23
   |
21 |     B::<{ &A::A }>::a(&C);
   |     ----------------- ^^ the trait `B<{&_: &'static A}>` is not implemented for `C`
   |     |
   |     required by a bound introduced by this call
   |
   = help: the following implementations were found:
             <C as B<{&_: &'static A}>>
             <C as B<{&_: &'static A}>>
note: required by `B::a`
  --> src/lib.rs:11:5
   |
11 |     fn a(&self) {}
   |     ^^^^^^^^^^^

@superwhiskers
Copy link
Author

it doesn't appear to be in the latest nightly yet. i'll check it a little later

@superwhiskers
Copy link
Author

superwhiskers commented Oct 29, 2021

running it with cargo check still appears to fail (with the same kind of error)

thread 'rustc' panicked at 'forcing query with already existing `DepNode`
- query-key: Canonical { max_universe: U0, variables: [], value: ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: UserFacing }, value: Binder(TraitPredicate(<C as B<{&_: &'static A}>>, polarity:Positive), []) } }
- dep-node: evaluate_obligation(b655c273fc552c69-c4da40ff6c91c2de)', /rustc/c390d69a615f095208ac94841f3310268521b2ee/compiler/rustc_query_system/src/dep_graph/graph.rs:236:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

note: 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: rustc 1.58.0-nightly (c390d69a6 2021-10-28) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type lib

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [evaluate_obligation] evaluating trait selection obligation `C: B<{&_: &'static A}>`
#1 [typeck] type-checking `ice`
end of query stack
error: could not compile `rust`

@b-naber
Copy link
Contributor

b-naber commented Oct 29, 2021

@superwhiskers
Copy link
Author

i believe it didn't reproduce in the playground unless you did something that usually uses cargo (such as running tests). simply running a program uses rustc, iirc

@sffc
Copy link

sffc commented Jan 29, 2022

I'm getting this error sporadically. I can rebuild the exact same code, and this error shows up sometimes but not others. It seems the way to make it go away is to find the file causing the error, delete the problematic match statement, save, rebuild, add the statement back again, save, and rebuild one more time. Perhaps it's an issue with an incremental build?

@apiraino
Copy link
Contributor

Seems to be dupe of #83085. Closing in favor of that (which has a patch for fixing the issue in progress)

@apiraino apiraino closed this as not planned Won't fix, can't repro, duplicate, stale Dec 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-adt_const_params `#![feature(adt_const_params)]` 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.
Projects
None yet
Development

No branches or pull requests

6 participants