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 when type parameter and const generic are in wrong order #68868

Closed
is8ac opened this issue Feb 5, 2020 · 2 comments
Closed

ICE when type parameter and const generic are in wrong order #68868

is8ac opened this issue Feb 5, 2020 · 2 comments
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` glacier ICE tracked in rust-lang/glacier. 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

@is8ac
Copy link

is8ac commented Feb 5, 2020

error: internal compiler error: src/librustc/traits/codegen/mod.rs:50: Encountered ambiguity selecting `Binder(<u8 as Foo<u16, Scalar(<ZST>): [type error]>>)` during codegen, presuming due to overflow

When a const generic not in curly braces appears before a type parameter, rustc panics.

Code

#![feature(const_generics)]

pub trait Foo<T, const X: usize> {
    fn foo(&self);
}

pub trait Bar<T, const X: usize> {
    fn bar(&self);
}

impl<const X: usize> Bar<u32, X> for u32
where
    u8: Foo<X, u16>,
    //u8: Foo<u32, X>,
    //u8: Foo<{ X }, u16>,
{
    fn bar(&self) {
        0u8.foo();
    }
}

fn main() {}

Replacing u8: Foo<X, u16> with u8: Foo<u32, X> fixes the problem.
Replacing it with u8: Foo<{ X }, u16> produces an informative error message.
Commenting out 0u8.foo(); also prevents the ICE.

This is not urgent, it is merely a matter of uninformative compiler errors.

Full Logs

error: internal compiler error: src/librustc/traits/codegen/mod.rs:50: Encountered ambiguity selecting `Binder(<u8 as Foo<u16, Scalar(<ZST>): [type error]>>)` during codegen, presuming due to overflow

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:883:9
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/git.luolix.top-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/git.luolix.top-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:77
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1052
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1428
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:204
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:224
  10: rustc_driver::report_ice
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:474
  12: std::panicking::begin_panic
  13: rustc_errors::HandlerInner::bug
  14: rustc_errors::Handler::bug
  15: rustc::util::bug::opt_span_bug_fmt::{{closure}}
  16: rustc::ty::context::tls::with_opt::{{closure}}
  17: rustc::ty::context::tls::with_opt
  18: rustc::util::bug::opt_span_bug_fmt
  19: rustc::util::bug::bug_fmt
  20: rustc::ty::context::GlobalCtxt::enter_local
  21: rustc::traits::codegen::codegen_fulfill_obligation
  22: rustc::ty::query::__query_compute::codegen_fulfill_obligation
  23: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::codegen_fulfill_obligation>::compute
  24: rustc::dep_graph::graph::DepGraph::with_task_impl
  25: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  26: rustc::ty::instance::Instance::resolve
  27: rustc_mir_build::lints::check
  28: rustc::ty::context::GlobalCtxt::enter_local
  29: rustc_mir_build::build::mir_built
  30: rustc::ty::query::__query_compute::mir_built
  31: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  32: rustc_mir::transform::check_unsafety::unsafety_check_result
  33: rustc::ty::query::__query_compute::unsafety_check_result
  34: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  35: rustc_mir::transform::mir_const
  36: rustc::ty::query::__query_compute::mir_const
  37: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  38: rustc_mir::transform::mir_validated
  39: rustc::ty::query::__query_compute::mir_validated
  40: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  41: rustc_mir::borrow_check::mir_borrowck
  42: rustc::ty::query::__query_compute::mir_borrowck
  43: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::mir_borrowck>::compute
  44: rustc::dep_graph::graph::DepGraph::with_task_impl
  45: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  46: rustc::ty::<impl rustc::ty::context::TyCtxt>::par_body_owners
  47: rustc_session::utils::<impl rustc_session::session::Session>::time
  48: rustc_interface::passes::analysis
  49: rustc::ty::query::__query_compute::analysis
  50: rustc::dep_graph::graph::DepGraph::with_task_impl
  51: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  52: rustc::ty::context::tls::enter_global
  53: rustc_interface::interface::run_compiler_in_existing_thread_pool
  54: scoped_tls::ScopedKey<T>::set
  55: syntax::attr::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.43.0-nightly (c9290dcee 2020-02-04) running on x86_64-unknown-linux-gnu

note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin

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

query stack during panic:
#0 [codegen_fulfill_obligation] checking if `Foo` fulfills its obligations
#1 [mir_built] processing `<u32 as Bar<u32, X>>::bar`
#2 [unsafety_check_result] processing `<u32 as Bar<u32, X>>::bar`
#3 [mir_const] processing `<u32 as Bar<u32, X>>::bar`
#4 [mir_validated] processing `<u32 as Bar<u32, X>>::bar`
#5 [mir_borrowck] processing `<u32 as Bar<u32, X>>::bar`
#6 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error

error: could not compile `bitnn`.

To learn more, run the command again with --verbose.

Meta

rustc --version --verbose
rustc 1.43.0-nightly (c9290dcee 2020-02-04)
binary: rustc
commit-hash: c9290dceee2cb6b882b26ec6e294560e51ef0853
commit-date: 2020-02-04
host: x86_64-unknown-linux-gnu
release: 1.43.0-nightly
LLVM version: 9.0
@estebank estebank added A-const-generics Area: const generics (parameters and arguments) F-const_generics `#![feature(const_generics)]` 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. labels Feb 5, 2020
@JohnTitor JohnTitor added the C-bug Category: This is a bug. label Feb 6, 2020
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Feb 7, 2020
@varkor
Copy link
Member

varkor commented Feb 9, 2020

I think this should be fixed by #68434.

@JohnTitor
Copy link
Member

Fixed by #68434 as varkor said, closing.

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-const_generics `#![feature(const_generics)]` glacier ICE tracked in rust-lang/glacier. 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

No branches or pull requests

5 participants