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

const generic ICE on *stable* #69239

Closed
DutchGhost opened this issue Feb 17, 2020 · 8 comments
Closed

const generic ICE on *stable* #69239

DutchGhost opened this issue Feb 17, 2020 · 8 comments
Assignees
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. const-generics-fixed-by-const_generics A bug that has been fixed once `const_generics` is enabled. 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) ❄️ P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@DutchGhost
Copy link
Contributor

DutchGhost commented Feb 17, 2020

I tried this code on stable:

trait Trait<const S: &'static str> {}

struct Bug<T>
where
    T: Trait<{std::intrinsics::type_name::<T>()}>
{
    t: T
}

I expected to see this happen: For one, report an error that Im using const generics without a feature flag. For two, report an error Im uising an intrinsic without a feature flag.

Instead, this happened: The above code crashed the compiler.

Meta

rustc --version --verbose:

1.41.0

A quick check in godbolt gives that the ICE's started in 1.35 and onwards. This also includes the current nightly and beta.

Backtrace

 Compiling playground v0.0.1 (/playground)
error[E0658]: const generics are unstable
 --> src/lib.rs:1:19
  |
1 | trait Trait<const S: &'static str> {}
  |                   ^
  |
  = note: for more information, see https://github.com/rust-lang/rust/issues/44580

error[E0658]: use of unstable library feature 'core_intrinsics': intrinsics are unlikely to ever be stabilized, instead they should be used through stabilized interfaces in the rest of the standard library
 --> src/lib.rs:5:15
  |
5 |     T: Trait<{std::intrinsics::type_name::<T>()}>
  |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: internal compiler error: src/librustc/ty/subst.rs:610: type parameter `T/#0` (T/0) out of range when substituting (root type=Some(extern "rust-intrinsic" fn() -> &'static str {std::intrinsics::type_name::<T>})) substs=[]

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:864: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:84
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:61
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1025
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1426
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:65
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:50
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:193
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:210
  10: rustc_driver::report_ice
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:475
  12: std::panicking::begin_panic
  13: rustc_errors::HandlerInner::span_bug
  14: rustc_errors::Handler::span_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::span_bug_fmt
  20: <rustc::ty::subst::SubstFolder as rustc::ty::fold::TypeFolder>::fold_ty
  21: rustc::ty::fold::TypeFoldable::fold_with
  22: rustc::ty::structural_impls::<impl rustc::ty::fold::TypeFoldable for &rustc::ty::TyS>::super_fold_with
  23: <rustc::ty::subst::SubstFolder as rustc::ty::fold::TypeFolder>::fold_ty
  24: rustc::ty::structural_impls::<impl rustc::ty::fold::TypeFoldable for &rustc::ty::sty::Const>::super_fold_with
  25: <rustc::ty::subst::SubstFolder as rustc::ty::fold::TypeFolder>::fold_const
  26: rustc::traits::codegen::<impl rustc::ty::context::TyCtxt>::subst_and_normalize_erasing_regions
  27: rustc_mir::interpret::operand::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::eval_operand
  28: rustc_mir::interpret::step::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::step
  29: rustc_mir::const_eval::const_eval_raw_provider
  30: rustc::ty::query::__query_compute::const_eval_raw
  31: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::const_eval_raw>::compute
  32: rustc::dep_graph::graph::DepGraph::with_task_impl
  33: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  34: rustc_mir::const_eval::const_eval_provider
  35: rustc::ty::query::__query_compute::const_eval
  36: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::const_eval>::compute
  37: rustc::dep_graph::graph::DepGraph::with_task_impl
  38: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  39: rustc_mir::const_eval::const_eval_provider
  40: rustc::ty::query::__query_compute::const_eval
  41: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::const_eval>::compute
  42: rustc::dep_graph::graph::DepGraph::with_task_impl
  43: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  44: rustc::ty::sty::Const::eval::{{closure}}
  45: rustc::ty::sty::Const::eval
  46: rustc::ty::fold::TypeFoldable::fold_with
  47: rustc::ty::fold::TypeFoldable::fold_with
  48: rustc::ty::fold::TypeFoldable::fold_with
  49: rustc::traits::project::normalize
  50: rustc::traits::fully_normalize
  51: rustc::ty::context::tls::with_context::{{closure}}
  52: rustc::ty::context::GlobalCtxt::enter_local
  53: rustc::traits::do_normalize_predicates
  54: rustc::traits::normalize_param_env_or_error
  55: rustc::ty::param_env
  56: rustc::ty::query::__query_compute::param_env
  57: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::param_env>::compute
  58: rustc::dep_graph::graph::DepGraph::with_task_impl
  59: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  60: rustc_typeck::check::wfcheck::check_item_well_formed
  61: rustc::ty::query::__query_compute::check_item_well_formed
  62: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::check_item_well_formed>::compute
  63: rustc::dep_graph::graph::DepGraph::with_task_impl
  64: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  65: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::ensure_query
  66: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:78
  67: rustc_data_structures::sync::par_for_each_in
  68: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:78
  69: rustc::hir::Crate::par_visit_all_item_likes
  70: rustc::util::common::time
  71: rustc_typeck::check_crate
  72: rustc_interface::passes::analysis
  73: rustc::ty::query::__query_compute::analysis
  74: rustc::dep_graph::graph::DepGraph::with_task_impl
  75: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  76: rustc::ty::context::tls::enter_global
  77: rustc_interface::interface::run_compiler_in_existing_thread_pool
  78: std::thread::local::LocalKey<T>::with
  79: scoped_tls::ScopedKey<T>::set
  80: syntax::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.41.0 (5e1a79984 2020-01-27) running on x86_64-unknown-linux-gnu

note: compiler flags: -C codegen-units=1 -C debuginfo=2 --crate-type lib

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

query stack during panic:
#0 [const_eval_raw] const-evaluating `Bug::{{constant}}#0`
#1 [const_eval] const-evaluating + checking `Bug::{{constant}}#0`
#2 [const_eval] const-evaluating + checking `Bug::{{constant}}#0`
#3 [param_env] processing `Bug`
#4 [check_item_well_formed] processing `Bug`
#5 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0658`.
error: could not compile `playground`.

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

@DutchGhost DutchGhost added the C-bug Category: This is a bug. label Feb 17, 2020
@jonas-schievink jonas-schievink added A-const-generics Area: const generics (parameters and arguments) F-const_generics `#![feature(const_generics)]` I-nominated T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 17, 2020
@chrissimpkins
Copy link
Member

chrissimpkins commented Feb 18, 2020

Source: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=357ac33432915dc13f0339771b264fe7

cargo-bisect-rustc indicates a regression in nightly-2019-03-08 with tests that use a rustc shell script. I ran into a cargo bisect-rustc error and couldn't bisect at the commit level because there is a missing git commit sha hash for nightly-2019-03-07. It looks like commit 88f755f appeared around this time with this block that seems to be the site of the ICE error string.

@jonas-schievink jonas-schievink added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Feb 18, 2020
@pnkfelix
Copy link
Member

pnkfelix commented Feb 20, 2020

@jonas-schievink : I was under impression that the F-* flags were reserved for bugs that required (in actuality, not solely according to our current specification/desired behavior) the feature flag to occur? I.e. ones that hypothetically could be deprioritized on that basis?

Do I have an incorrect impression?

@jonas-schievink
Copy link
Contributor

Hmm, to my knowledge we've usually applied them whenever the feature in question was involved. For things that only occur on nightly, we have the additional requires-nightly label.

@pnkfelix
Copy link
Member

Oh, wait, it does print:

error[E0658]: const generics are unstable
 --> src/lib.rs:1:19
  |
1 | trait Trait<const S: &'static str> {}
  |                   ^
  |
  = note: for more information, see https://github.com/rust-lang/rust/issues/44580

in the first diagnostic it prints.

@DutchGhost we don't print anything about #!feature(flag) on the stable or beta channels. That suggestion is only emitted on nightly channel.

@pnkfelix
Copy link
Member

Hmm, to my knowledge we've usually applied them whenever the feature in question was involved. For things that only occur on nightly, we have the additional requires-nightly label.

okay thanks; I indeed had the wrong impression.

@pnkfelix
Copy link
Member

triage: P-medium, removing nomination label. Assigning to self. (Since this is leveraging a nightly-only feature, and we do emit the diagnostic saying so, this gets relatively lower priority.)

@pnkfelix pnkfelix added P-medium Medium priority and removed I-nominated labels Feb 20, 2020
@pnkfelix pnkfelix self-assigned this Feb 20, 2020
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Feb 21, 2020
@yodaldevoid
Copy link
Contributor

Digging into this, this ICE seems to come about because the const argument does not inherit the substs of the item it is contained within when in the where clause or generic parameter list.

@varkor varkor added the const-generics-fixed-by-const_generics A bug that has been fixed once `const_generics` is enabled. label Sep 13, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Oct 5, 2020
…lcnr,estebank

Fix missing diagnostic span for `impl Trait` with const generics, and add various tests for `min_const_generics` and `const_generics`

Closes rust-lang#61410.

Adds `min_const_generics` tests for:
- rust-lang#73727
- rust-lang#72293
- rust-lang#67375
- rust-lang#75153
- rust-lang#71922
- rust-lang#69913
- rust-lang#67945
- rust-lang#69239

Adds `const_generics` tests for:
- rust-lang#67375
- rust-lang#75153
- rust-lang#71922
- rust-lang#69913
- rust-lang#67945
- rust-lang#69239

(I only added separate `min_const_generics` and `const_generics` tests if they were handled differently by the two features.)

We need to figure out how to deduplicate when `const_generics` is stabilised, but we can discuss that later. For now, we should be checking neither feature breaks, so require regression tests for both. I've given them identical names when I've added both, which should make it easier to spot them later.

r? @lcnr
@Alexendoo
Copy link
Member

No longer ICEs since #78809

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. const-generics-fixed-by-const_generics A bug that has been fixed once `const_generics` is enabled. 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) ❄️ P-medium Medium priority 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

8 participants