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

Trait with a lifetime parameter, associated constant, and an associated type can trigger an ICE #84659

Closed
FrederikTheDane opened this issue Apr 28, 2021 · 10 comments · Fixed by #88602
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. 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

@FrederikTheDane
Copy link

The code below will trigger an ICE on the latest nightly build
This is as small as i could make it while still triggering the error

Code

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

trait Bar<const N: usize> {}

trait Foo<'a> {
    const N: usize;
    type Baz: Bar<{ Self::N }>;
}

Meta

rustc --version --verbose:

rustc 1.53.0-nightly (42816d61e 2021-04-24)
binary: rustc
commit-hash: 42816d61ead7e46d462df997958ccfd514f8c21c
commit-date: 2021-04-24
host: x86_64-unknown-linux-gnu
release: 1.53.0-nightly
LLVM version: 12.0.0

Error output

error: internal compiler error: compiler/rustc_infer/src/infer/region_constraints/mod.rs:546:17: cannot relate bound region: ReLateBound(DebruijnIndex(1), BoundRegion { var: 0, kind: BrAnon(0) }) <= ReErased
Backtrace

thread 'rustc' panicked at 'Box<Any>', /rustc/42816d61ead7e46d462df997958ccfd514f8c21c/library/std/src/panic.rs:59:5
stack backtrace:
   0: std::panicking::begin_panic
   1: std::panic::panic_any
   2: rustc_errors::HandlerInner::span_bug
   3: rustc_errors::Handler::span_bug
   4: rustc_middle::ty::context::tls::with_opt
   5: rustc_middle::util::bug::opt_span_bug_fmt
   6: rustc_middle::util::bug::span_bug_fmt
   7: rustc_infer::infer::region_constraints::RegionConstraintCollector::make_subregion
   8: rustc_infer::infer::region_constraints::RegionConstraintCollector::make_eqregion
   9: <rustc_infer::infer::equate::Equate as rustc_middle::ty::relate::TypeRelation>::regions
  10: <rustc_middle::ty::subst::GenericArg as rustc_middle::ty::relate::Relate>::relate
  11: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &mut F>::call_once
  12: <core::result::Result<T,E> as rustc_middle::ty::context::InternIteratorElement<T,R>>::intern_with
  13: rustc_infer::infer::InferCtxt::commit_if_ok
  14: rustc_infer::infer::InferCtxt::commit_if_ok
  15: rustc_infer::infer::InferCtxt::probe
  16: rustc_trait_selection::traits::select::candidate_assembly::<impl rustc_trait_selection::traits::select::SelectionContext>::assemble_candidates
  17: rustc_trait_selection::traits::select::candidate_assembly::<impl rustc_trait_selection::traits::select::SelectionContext>::candidate_from_obligation_no_cache
  18: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  19: rustc_query_system::dep_graph::graph::DepGraph<K>::with_anon_task
  20: rustc_trait_selection::traits::select::candidate_assembly::<impl rustc_trait_selection::traits::select::SelectionContext>::candidate_from_obligation
  21: rustc_trait_selection::traits::select::SelectionContext::select
  22: rustc_infer::infer::InferCtxtBuilder::enter
  23: rustc_trait_selection::traits::codegen::codegen_fulfill_obligation
  24: rustc_query_impl::<impl rustc_query_system::query::config::QueryAccessors<rustc_query_impl::plumbing::QueryCtxt> for rustc_query_impl::queries::codegen_fulfill_obligation>::compute
  25: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  26: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  27: rustc_data_structures::stack::ensure_sufficient_stack
  28: rustc_query_system::query::plumbing::force_query_with_job
  29: rustc_query_system::query::plumbing::get_query_impl
  30: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::codegen_fulfill_obligation
  31: rustc_ty_utils::instance::inner_resolve_instance
  32: rustc_ty_utils::instance::resolve_instance
  33: rustc_query_impl::<impl rustc_query_system::query::config::QueryAccessors<rustc_query_impl::plumbing::QueryCtxt> for rustc_query_impl::queries::resolve_instance>::compute
  34: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  35: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  36: rustc_data_structures::stack::ensure_sufficient_stack
  37: rustc_query_system::query::plumbing::force_query_with_job
  38: rustc_query_system::query::plumbing::get_query_impl
  39: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::resolve_instance
  40: rustc_middle::ty::instance::Instance::resolve_opt_const_arg
  41: rustc_middle::mir::interpret::queries::<impl rustc_middle::ty::context::TyCtxt>::const_eval_resolve
  42: <rustc_trait_selection::traits::query::normalize::QueryNormalizer as rustc_middle::ty::fold::TypeFolder>::fold_const
  43: <rustc_trait_selection::traits::query::normalize::QueryNormalizer as rustc_middle::ty::fold::TypeFolder>::fold_mir_const
  44: <rustc_infer::infer::at::At as rustc_trait_selection::traits::query::normalize::AtExt>::normalize
  45: rustc_infer::infer::InferCtxtBuilder::enter
  46: core::ops::function::FnOnce::call_once
  47: rustc_query_impl::<impl rustc_query_system::query::config::QueryAccessors<rustc_query_impl::plumbing::QueryCtxt> for rustc_query_impl::queries::normalize_mir_const_after_erasing_regions>::compute
  48: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  49: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  50: rustc_data_structures::stack::ensure_sufficient_stack
  51: rustc_query_system::query::plumbing::force_query_with_job
  52: rustc_query_system::query::plumbing::get_query_impl
  53: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::normalize_mir_const_after_erasing_regions
  54: rustc_middle::ty::normalize_erasing_regions::<impl rustc_middle::ty::context::TyCtxt>::normalize_erasing_regions
  55: rustc_mir::interpret::eval_context::InterpCx<M>::push_stack_frame
  56: rustc_mir::const_eval::eval_queries::eval_to_allocation_raw_provider
  57: rustc_query_impl::<impl rustc_query_system::query::config::QueryAccessors<rustc_query_impl::plumbing::QueryCtxt> for rustc_query_impl::queries::eval_to_allocation_raw>::compute
  58: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  59: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  60: rustc_data_structures::stack::ensure_sufficient_stack
  61: rustc_query_system::query::plumbing::force_query_with_job
  62: rustc_query_system::query::plumbing::get_query_impl
  63: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::eval_to_allocation_raw
  64: rustc_mir::const_eval::eval_queries::eval_to_const_value_raw_provider
  65: rustc_query_impl::<impl rustc_query_system::query::config::QueryAccessors<rustc_query_impl::plumbing::QueryCtxt> for rustc_query_impl::queries::eval_to_const_value_raw>::compute
  66: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  67: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  68: rustc_data_structures::stack::ensure_sufficient_stack
  69: rustc_query_system::query::plumbing::force_query_with_job
  70: rustc_query_system::query::plumbing::get_query_impl
  71: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::eval_to_const_value_raw
  72: rustc_middle::mir::interpret::queries::<impl rustc_middle::ty::context::TyCtxt>::const_eval_global_id
  73: rustc_middle::mir::interpret::queries::<impl rustc_middle::ty::context::TyCtxt>::const_eval_resolve
  74: rustc_infer::infer::InferCtxt::const_eval_resolve
  75: rustc_trait_selection::traits::const_evaluatable::is_const_evaluatable
  76: rustc_trait_selection::traits::fulfill::FulfillProcessor::progress_changed_obligations
  77: rustc_data_structures::obligation_forest::ObligationForest<O>::process_obligations
  78: <rustc_trait_selection::traits::fulfill::FulfillmentContext as rustc_infer::traits::engine::TraitEngine>::select_where_possible
  79: <rustc_trait_selection::traits::fulfill::FulfillmentContext as rustc_infer::traits::engine::TraitEngine>::select_all_or_error
  80: rustc_typeck::check::fn_ctxt::_impl::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::select_all_obligations_or_error
  81: rustc_infer::infer::InferCtxtBuilder::enter
  82: rustc_typeck::check::wfcheck::check_associated_item
  83: rustc_typeck::check::wfcheck::check_trait_item
  84: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  85: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  86: rustc_query_system::query::plumbing::force_query_with_job
  87: rustc_query_system::query::plumbing::get_query_impl
  88: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::check_trait_item_well_formed
  89: <rustc_typeck::check::wfcheck::CheckTypeWellFormedVisitor as rustc_hir::intravisit::Visitor>::visit_trait_item
  90: rustc_data_structures::sync::par_for_each_in
  91: rustc_hir::hir::Crate::par_visit_all_item_likes
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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.53.0-nightly (42816d61e 2021-04-24) 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 [codegen_fulfill_obligation] checking if `Foo` fulfills its obligations
#1 [resolve_instance] resolving instance `<Self as Foo>::N`
#2 [normalize_mir_const_after_erasing_regions] normalizing `<Self as Foo>::N`
#3 [eval_to_allocation_raw] const-evaluating + checking `Foo::Baz::{constant#0}`
#4 [eval_to_const_value_raw] simplifying constant for the type system `Foo::Baz::{constant#0}`
#5 [check_trait_item_well_formed] checking that `Foo::Baz` is well-formed
#6 [analysis] running analysis passes on this crate
end of query stack

@FrederikTheDane FrederikTheDane 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 Apr 28, 2021
@jonas-schievink jonas-schievink added A-const-generics Area: const generics (parameters and arguments) F-const_generics `#![feature(const_generics)]` requires-nightly This issue requires a nightly compiler in some way. labels Apr 28, 2021
@hellow554
Copy link
Contributor

Also occurs on stable! Regression from 1.50 to 1.51

@rustbot modify labels: -requires-nightly +regression-from-stable-to-stable

@rustbot rustbot added regression-from-stable-to-stable Performance or correctness regression from one stable version to another. I-prioritize Issue: Indicates that prioritization has been requested for this issue. and removed requires-nightly This issue requires a nightly compiler in some way. labels Apr 29, 2021
@hameerabbasi
Copy link
Contributor

hameerabbasi commented Apr 29, 2021

Bisected:

searched nightlies: from nightly-2020-01-01 to nightly-2021-04-29
regressed nightly: nightly-2021-01-18
searched commits: from 8a65184 to 4253153
regressed commit: 4253153

bisected with cargo-bisect-rustc v0.6.0

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --test-dir=. --start=2020-01-01 --regress=ice

Regressed PR is #80679, cc @lcnr @jackh726.

@hameerabbasi
Copy link
Contributor

hameerabbasi commented Apr 29, 2021

@hellow554 Would you mind expanding on how to reproduce it on stable, because it seems feature gated to me. See #84659 (comment) and #84659 (comment)

@hellow554
Copy link
Contributor

@hameerabbasi just because something is gated doesn't mean it can't crash on stable ;)
Use the above code and try to build it on the playground or compile it with a stable compiler, it will ICE.

@apiraino
Copy link
Contributor

We briefly discussed this on Zulip.

@hellow554 I'd revert some labels here because we think this is a nightly-only issue due to the unstable const_generics feature. The fact that it compiles and reproduces on stable is kind of misleading because it's the incomplete_features that allows that. Makes sense?

@rustbot modify labels: +requires-nightly -regression-from-stable-to-stable +P-medium

@rustbot rustbot added P-medium Medium priority requires-nightly This issue requires a nightly compiler in some way. and removed regression-from-stable-to-stable Performance or correctness regression from one stable version to another. labels Apr 29, 2021
@hameerabbasi hameerabbasi removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Apr 29, 2021
@hellow554
Copy link
Contributor

@apiraino sure enough ;)

but just to be clear, even without #![allow(incomplete_features)] this results in an ICE on stable

@jackh726
Copy link
Member

Okay so this is a bit complicated. Because while this does has feature(const_generics), is still ICEs on stable. That said, not including the feature gate doesn't ICE.

Given that, I think the current labels are appropriate, except maybe requires-nightly. It is technically a stable to stable regression, but it requires a feature to ICE, and I'm not sure that's the spirit of what that label is intended to track.

@apiraino
Copy link
Contributor

@jackh726 agreed on the labels, I've got the context partially wrong here.

@rustbot modify labels: -requires-nightly

@rustbot rustbot removed the requires-nightly This issue requires a nightly compiler in some way. label Apr 30, 2021
fanninpm added a commit to fanninpm/glacier that referenced this issue Apr 30, 2021
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Apr 30, 2021
@BoxyUwU
Copy link
Member

BoxyUwU commented May 24, 2021

With #![feature(const_evaluatable_checked)] this also doesn't ICE

@Alexendoo
Copy link
Member

No longer ICEs since #88369 as far as I could tell with various combinations of the new feature gates

@Alexendoo Alexendoo added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Sep 1, 2021
@bors bors closed this as completed in dcd0e1d Sep 6, 2021
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. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. 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

Successfully merging a pull request may close this issue.

10 participants