Skip to content

Uninferred types/regions ICE for array impl with const generics #60744

New issue

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

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

Already on GitHub? # to your account

Closed
varkor opened this issue May 11, 2019 · 3 comments · Fixed by #60742
Closed

Uninferred types/regions ICE for array impl with const generics #60744

varkor opened this issue May 11, 2019 · 3 comments · Fixed by #60742
Labels
A-const-generics Area: const generics (parameters and arguments) 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

@varkor
Copy link
Member

varkor commented May 11, 2019

After #60742 is merged, the following produces:

#![feature(const_generics)]

use std::fmt;

struct Array<T, const N: usize>([T; N]);

impl<T: fmt::Debug, const N: usize> fmt::Debug for Array<T, {N}> {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.debug_list().entries(self.0.iter()).finish()
    }
}

fn main() {
    println!("{:?}", Array([1, 2, 3]));
}

results in:

error: internal compiler error: src/librustc/traits/codegen/mod.rs:160: Uninferred types/regions in `VtableImplData(impl_def_id=DefId(0:19 ~ bug[317d]::{{impl}}[0]), substs=[i32, Const { ty: usize, val: Infer(Var(_#0c)) }], nested=[(), ()])`

(Before #60742, this resulted in a different ICE.)

@varkor varkor added A-const-generics Area: const generics (parameters and arguments) 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 May 11, 2019
@varkor
Copy link
Member Author

varkor commented May 11, 2019

#![feature(const_generics)]

use std::fmt;

struct Array<T>(T);

impl<T: fmt::Debug, const N: usize> fmt::Debug for Array<[T; N]> {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.debug_list().entries((&self.0 as &[T]).iter()).finish()
    }
}

fn main() {
    println!("{:?}", Array([1, 2, 3]));
}

produces the same error, but used to produce a different one from the other snippet, so it's also worth including as a test case.

@Aloso
Copy link
Contributor

Aloso commented May 22, 2019

This isn't specific to arrays. Here's another example:

struct Foo<const X: u8>(u32);

impl<const X: u8> Clone for Foo<{X}> {
    fn clone(&self) -> Self {
        Foo(self.0)
    }
}

#[test]
fn test_foo() {
    let foo: Foo<4> = Foo(1);
    foo.clone();
}
Compiler output:
error: internal compiler error: src/librustc/traits/codegen/mod.rs:160: Uninferred types/regions in `VtableImplData(impl_def_id=DefId(0:16 ~ fixpt[712f]::{{impl}}[0]), substs=[Const { ty: u8, val: Infer(Var(_#0c)) }], nested=[])`

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:637:9
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
   1: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at src/libstd/sys_common/backtrace.rs:59
             at src/libstd/panicking.rs:197
   3: std::panicking::default_hook
             at src/libstd/panicking.rs:211
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:478
   6: std::panicking::begin_panic
   7: rustc_errors::Handler::bug
   8: rustc::util::bug::opt_span_bug_fmt::{{closure}}
   9: rustc::ty::context::tls::with_opt::{{closure}}
  10: rustc::ty::context::tls::with_context_opt
  11: rustc::ty::context::tls::with_opt
  12: rustc::util::bug::opt_span_bug_fmt
  13: rustc::util::bug::bug_fmt
  14: rustc::traits::codegen::<impl rustc::infer::InferCtxt>::drain_fulfillment_cx_or_panic
  15: rustc::ty::context::GlobalCtxt::enter_local
  16: rustc::traits::codegen::codegen_fulfill_obligation
  17: rustc::ty::query::__query_compute::codegen_fulfill_obligation
  18: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::codegen_fulfill_obligation>::compute
  19: rustc::dep_graph::graph::DepGraph::with_task_impl
  20: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  21: rustc::ty::instance::Instance::resolve
  22: rustc_mir::lints::check
  23: rustc::ty::context::GlobalCtxt::enter_local
  24: rustc_mir::build::mir_build
  25: rustc_mir::transform::mir_built
  26: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::mir_built>::compute
  27: rustc::dep_graph::graph::DepGraph::with_task_impl
  28: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::force_query
  29: rustc::ty::query::plumbing::force_from_dep_node
  30: rustc::dep_graph::graph::DepGraph::try_mark_previous_green
  31: rustc::dep_graph::graph::DepGraph::try_mark_previous_green
  32: rustc::dep_graph::graph::DepGraph::try_mark_green
  33: rustc::dep_graph::graph::DepGraph::try_mark_green_and_read
  34: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  35: rustc_mir::transform::mir_validated
  36: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::mir_validated>::compute
  37: rustc::dep_graph::graph::DepGraph::with_task_impl
  38: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::force_query
  39: rustc::ty::query::plumbing::force_from_dep_node
  40: rustc::dep_graph::graph::DepGraph::try_mark_previous_green
  41: rustc::dep_graph::graph::DepGraph::try_mark_green
  42: rustc::dep_graph::graph::DepGraph::try_mark_green_and_read
  43: rustc::ty::<impl rustc::ty::context::TyCtxt>::par_body_owners
  44: rustc::util::common::time
  45: rustc_interface::passes::analysis
  46: rustc::ty::query::__query_compute::analysis
  47: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::analysis>::compute
  48: rustc::dep_graph::graph::DepGraph::with_task_impl
  49: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  50: rustc::ty::context::tls::enter_global
  51: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
  52: rustc_interface::passes::create_global_ctxt::{{closure}}
  53: rustc_interface::interface::run_compiler_in_existing_thread_pool
  54: std::thread::local::LocalKey<T>::with
  55: scoped_tls::ScopedKey<T>::set
  56: syntax::with_globals
query stack during panic:
#0 [codegen_fulfill_obligation] checking if `std::clone::Clone` fulfills its obligations
#1 [mir_built] processing `test_foo`
#2 [mir_const] processing `test_foo`
#3 [mir_validated] processing `test_foo`
#4 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error

I noticed that it works correctly if I replace

impl<const X: u8> Clone for Foo<{X}>
// with
impl Clone for Foo<4>

rustc 1.36.0-nightly (50a0def 2019-05-21) running on x86_64-unknown-linux-gnu

@varkor
Copy link
Member Author

varkor commented May 22, 2019

I've added a few test cases in #60742, so this should be fixed after that's merged.

Centril added a commit to Centril/rust that referenced this issue May 28, 2019
…eddyb

Allow const parameters in array sizes to be unified

Fixes rust-lang#60632.
Fixes rust-lang#60744.
Fixes rust-lang#60923.
(The last commit should probably be viewed in isolation, as it just renames things from `type` to `kind`.)

r? @eddyb
Centril added a commit to Centril/rust that referenced this issue May 28, 2019
…eddyb

Allow const parameters in array sizes to be unified

Fixes rust-lang#60632.
Fixes rust-lang#60744.
Fixes rust-lang#60923.
(The last commit should probably be viewed in isolation, as it just renames things from `type` to `kind`.)

r? @eddyb
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-const-generics Area: const generics (parameters and arguments) 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

Successfully merging a pull request may close this issue.

2 participants