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

function with const generic and impl trait parameter causes ICE #60953

Closed
carado opened this issue May 19, 2019 · 2 comments · Fixed by #61333
Closed

function with const generic and impl trait parameter causes ICE #60953

carado opened this issue May 19, 2019 · 2 comments · Fixed by #61333
Assignees
Labels
A-const-generics Area: const generics (parameters and arguments) 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.

Comments

@carado
Copy link

carado commented May 19, 2019

Hello !

A blank rust project with just this main.rs:

#![feature(const_generics)]

trait Trait {}

fn f<const N: usize>(_: impl Trait) {}

fn main() {}

causes:

$ rustc --version
rustc 1.36.0-nightly (963184bbb 2019-05-18)
$ RUST_BACKTRACE=1 cargo check
    Checking test-rust v0.1.0 (/home/carado/tmp/test-rust)
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
 --> src/main.rs:1:12
  |
1 | #![feature(const_generics)]
  |            ^^^^^^^^^^^^^^

error: internal compiler error: src/librustc/ty/subst.rs:555: expected type for `impl Trait/#0` (impl Trait/0) but found Const(Const { ty: [type error], val: Scalar(Bits { size: 0, bits: 0 }) }) when substituting (root type=Some(impl Trait)) substs=[Const { ty: [type error], val: Scalar(Bits { size: 0, bits: 0 }) }, [type error]]

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:572: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::span_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::span_bug_fmt
  14: <rustc::ty::subst::SubstFolder as rustc::ty::fold::TypeFolder>::fold_ty
  15: rustc::ty::fold::TypeFoldable::fold_with
  16: <smallvec::SmallVec<A> as core::iter::traits::collect::FromIterator<<A as smallvec::Array>::Item>>::from_iter
  17: rustc::ty::fold::TypeFoldable::fold_with
  18: rustc::ty::subst::Subst::subst
  19: <core::iter::adapters::Map<I,F> as core::iter::traits::iterator::Iterator>::next
  20: rustc_typeck::check::wfcheck::check_where_clauses
  21: rustc_typeck::check::wfcheck::check_fn_or_method
  22: rustc::ty::context::GlobalCtxt::enter_local
  23: rustc_typeck::check::wfcheck::check_item_well_formed
  24: rustc::ty::query::__query_compute::check_item_well_formed
  25: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::check_item_well_formed>::compute
  26: rustc::dep_graph::graph::DepGraph::with_task_impl
  27: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  28: <rustc_typeck::check::wfcheck::CheckTypeWellFormedVisitor as rustc::hir::itemlikevisit::ParItemLikeVisitor>::visit_item
  29: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:85
  30: rustc_data_structures::sync::par_for_each_in
  31: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:85
  32: rustc::hir::Crate::par_visit_all_item_likes
  33: rustc::util::common::time
  34: rustc_typeck::check_crate
  35: rustc_interface::passes::analysis
  36: rustc::ty::query::__query_compute::analysis
  37: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::analysis>::compute
  38: rustc::dep_graph::graph::DepGraph::with_task_impl
  39: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  40: rustc::ty::context::tls::enter_global
  41: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
  42: rustc_interface::passes::create_global_ctxt::{{closure}}
  43: rustc_interface::interface::run_compiler_in_existing_thread_pool
  44: std::thread::local::LocalKey<T>::with
  45: scoped_tls::ScopedKey<T>::set
  46: syntax::with_globals
query stack during panic:
#0 [check_item_well_formed] processing `f`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error


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.36.0-nightly (963184bbb 2019-05-18) 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

error: Could not compile `test-rust`.

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

And while I'm here, thanks in general for implementing const generics ! They're gonna be a huge help.
Have a nice day !

@csmoe csmoe added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label May 19, 2019
@jonas-schievink jonas-schievink added A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 19, 2019
@varkor
Copy link
Member

varkor commented May 29, 2019

This has something to do with APIT adding a type parameter at the end of the list of generics, rather than before any consts. If the const parameters are forced to go at the end, then the ICE is resolved. However, generics shouldn't depend on their order at all, so I'm not sure doing this is the correct fix.

@varkor
Copy link
Member

varkor commented May 29, 2019

I have a fix in #61333, but have also opened a more general issue for these sorts of problems here: #61334.

Centril added a commit to Centril/rust that referenced this issue May 30, 2019
…bank

Fix ICE with APIT in a function with a const parameter

Fixes rust-lang#60953.
Centril added a commit to Centril/rust that referenced this issue May 30, 2019
…bank

Fix ICE with APIT in a function with a const parameter

Fixes rust-lang#60953.
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. 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.

4 participants