Skip to content

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

Description

@ffrejaa

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

Activity

  1. added
    C-bugCategory: This is a bug.
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Apr 28, 2021
  2. added
    A-const-genericsArea: const generics (parameters and arguments)
    requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.
    on Apr 28, 2021
  3. hellow554 commented on Apr 29, 2021

    @hellow554
    Contributor

    Also occurs on stable! Regression from 1.50 to 1.51

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

  4. added
    regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    and removed
    requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.
    on Apr 29, 2021
  5. hameerabbasi commented on Apr 29, 2021

    @hameerabbasi
    Contributor

    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.

  6. hameerabbasi commented on Apr 29, 2021

    @hameerabbasi
    Contributor

    @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)

  7. hellow554 commented on Apr 29, 2021

    @hellow554
    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.

  8. apiraino commented on Apr 29, 2021

    @apiraino
    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

  9. added
    requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.
    and removed
    regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.
    on Apr 29, 2021
  10. removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Apr 29, 2021
  11. hellow554 commented on Apr 29, 2021

    @hellow554
    Contributor

    @apiraino sure enough ;)

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

  12. jackh726 commented on Apr 30, 2021

    @jackh726
    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.

  13. apiraino commented on Apr 30, 2021

    @apiraino
    Contributor

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

    @rustbot modify labels: -requires-nightly

  14. removed
    requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.
    on Apr 30, 2021
  15. added a commit that references this issue on Apr 30, 2021
  16. BoxyUwU commented on May 24, 2021

    @BoxyUwU
    Member

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

  17. Alexendoo commented on Sep 1, 2021

    @Alexendoo
    Member

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

  18. added
    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.
    on Sep 1, 2021
  19. added a commit that references this issue on Sep 6, 2021
    dcd0e1d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)C-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.F-const_generics`#![feature(const_generics)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions