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: cannot relate bound region: ReLateBound #77357

Open
DutchGhost opened this issue Sep 30, 2020 · 8 comments · Fixed by #96603
Open

ICE: cannot relate bound region: ReLateBound #77357

DutchGhost opened this issue Sep 30, 2020 · 8 comments · Fixed by #96603
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. 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

@DutchGhost
Copy link
Contributor

Code

trait MyTrait<T> {}

fn bug<'a, T>() -> &'static dyn MyTrait<[(); { |x: &'a u32| { x }; 4 }]> {
    todo!()
}

Meta

rustc --version --verbose:

rustc 1.46.0 (04488afe3 2020-08-24)
rustc 1.47.0-beta.5 (9f0e6fa94 2020-09-29)
rustc 1.48.0-nightly (381b445ff 2020-09-29)

Error output

error: internal compiler error: compiler/rustc_infer/src/infer/region_constraints/mod.rs:576:17: cannot relate bound region: ReLateBound(DebruijnIndex(1), BrNamed(DefId(0:6 ~ playground[efd4]::bug::'a), 'a)) <= '_#1r
Backtrace

thread 'rustc' panicked at 'Box<Any>', /rustc/381b445ff5751f9f39ec672b623372dff09c276e/compiler/rustc_errors/src/lib.rs:891:9
stack backtrace:
   0: std::panicking::begin_panic
   1: rustc_errors::HandlerInner::span_bug
   2: rustc_errors::Handler::span_bug
   3: rustc_middle::util::bug::opt_span_bug_fmt::{{closure}}
   4: rustc_middle::ty::context::tls::with_opt::{{closure}}
   5: rustc_middle::ty::context::tls::with_opt
   6: rustc_middle::util::bug::opt_span_bug_fmt
   7: rustc_middle::util::bug::span_bug_fmt
   8: rustc_infer::infer::region_constraints::RegionConstraintCollector::make_subregion
   9: rustc_infer::infer::region_constraints::RegionConstraintCollector::make_eqregion
  10: <rustc_infer::infer::equate::Equate as rustc_middle::ty::relate::TypeRelation>::regions
  11: rustc_middle::ty::relate::super_relate_tys
  12: rustc_infer::infer::combine::<impl rustc_infer::infer::InferCtxt>::super_combine_tys
  13: <rustc_infer::infer::equate::Equate as rustc_middle::ty::relate::TypeRelation>::tys
  14: <rustc_middle::ty::subst::GenericArg as rustc_middle::ty::relate::Relate>::relate
  15: <core::result::Result<T,E> as rustc_middle::ty::context::InternIteratorElement<T,R>>::intern_with
  16: <rustc_middle::ty::sty::TraitRef as rustc_middle::ty::relate::Relate>::relate
  17: rustc_infer::infer::InferCtxt::commit_if_ok
  18: rustc_trait_selection::traits::select::SelectionContext::match_impl
  19: rustc_infer::infer::InferCtxt::probe
  20: rustc_middle::ty::trait_def::<impl rustc_middle::ty::context::TyCtxt>::for_each_relevant_impl
  21: rustc_trait_selection::traits::select::candidate_assembly::<impl rustc_trait_selection::traits::select::SelectionContext>::assemble_candidates_from_impls
  22: rustc_trait_selection::traits::select::candidate_assembly::<impl rustc_trait_selection::traits::select::SelectionContext>::assemble_candidates
  23: rustc_trait_selection::traits::select::SelectionContext::candidate_from_obligation_no_cache
  24: rustc_query_system::dep_graph::graph::DepGraph<K>::with_anon_task
  25: rustc_trait_selection::traits::select::candidate_assembly::<impl rustc_trait_selection::traits::select::SelectionContext>::candidate_from_obligation
  26: rustc_trait_selection::traits::select::SelectionContext::select
  27: rustc_typeck::check::coercion::Coerce::coerce
  28: rustc_infer::infer::InferCtxt::commit_if_ok
  29: rustc_typeck::check::coercion::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::try_coerce
  30: rustc_typeck::check::coercion::CoerceMany<E>::coerce_inner
  31: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_return_expr
  32: rustc_typeck::check::check::check_fn
  33: rustc_typeck::check::closure::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_closure
  34: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  35: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  36: rustc_typeck::check::fn_ctxt::FnCtxt::check_stmt
  37: rustc_typeck::check::fn_ctxt::FnCtxt::check_block_with_expected
  38: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  39: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  40: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_coercable_to_type
  41: rustc_infer::infer::InferCtxtBuilder::enter
  42: rustc_typeck::check::typeck
  43: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  44: rustc_data_structures::stack::ensure_sufficient_stack
  45: rustc_query_system::query::plumbing::get_query_impl
  46: rustc_middle::ty::context::TyCtxt::typeck_opt_const_arg
  47: rustc_mir::const_eval::eval_queries::eval_to_allocation_raw_provider
  48: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::eval_to_allocation_raw>::compute
  49: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  50: rustc_middle::ty::query::plumbing::<impl rustc_query_system::query::QueryContext for rustc_middle::ty::context::TyCtxt>::start_query::{{closure}}::{{closure}}::{{closure}}
  51: rustc_query_system::query::plumbing::get_query_impl
  52: rustc_mir::const_eval::eval_queries::eval_to_const_value_raw_provider
  53: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::eval_to_const_value_raw>::compute
  54: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  55: rustc_middle::ty::query::plumbing::<impl rustc_query_system::query::QueryContext for rustc_middle::ty::context::TyCtxt>::start_query::{{closure}}::{{closure}}::{{closure}}
  56: rustc_query_system::query::plumbing::get_query_impl
  57: rustc_mir::const_eval::eval_queries::eval_to_const_value_raw_provider
  58: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::eval_to_const_value_raw>::compute
  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::get_query_impl
  62: rustc_middle::mir::interpret::queries::<impl rustc_middle::ty::context::TyCtxt>::const_eval_global_id
  63: rustc_middle::mir::interpret::queries::<impl rustc_middle::ty::context::TyCtxt>::const_eval_resolve
  64: <rustc_trait_selection::traits::project::AssocTypeNormalizer as rustc_middle::ty::fold::TypeFolder>::fold_const
  65: rustc_middle::ty::structural_impls::<impl rustc_middle::ty::fold::TypeFoldable for &rustc_middle::ty::TyS>::super_fold_with
  66: <rustc_trait_selection::traits::project::AssocTypeNormalizer as rustc_middle::ty::fold::TypeFolder>::fold_ty
  67: rustc_middle::ty::fold::TypeFoldable::fold_with
  68: rustc_middle::ty::structural_impls::fold_list
  69: rustc_middle::ty::structural_impls::<impl rustc_middle::ty::fold::TypeFoldable for &rustc_middle::ty::TyS>::super_fold_with
  70: <rustc_trait_selection::traits::project::AssocTypeNormalizer as rustc_middle::ty::fold::TypeFolder>::fold_ty
  71: rustc_middle::ty::structural_impls::<impl rustc_middle::ty::fold::TypeFoldable for &rustc_middle::ty::TyS>::super_fold_with
  72: <rustc_trait_selection::traits::project::AssocTypeNormalizer as rustc_middle::ty::fold::TypeFolder>::fold_ty
  73: rustc_middle::ty::structural_impls::fold_list
  74: rustc_trait_selection::traits::project::AssocTypeNormalizer::fold
  75: rustc_trait_selection::traits::project::normalize
  76: <rustc_infer::infer::InferCtxt as rustc_trait_selection::infer::InferCtxtExt>::partially_normalize_associated_types_in
  77: rustc_typeck::check::inherited::Inherited::normalize_associated_types_in
  78: rustc_infer::infer::InferCtxtBuilder::enter
  79: rustc_typeck::check::wfcheck::check_item_well_formed
  80: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::check_item_well_formed>::compute
  81: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  82: rustc_data_structures::stack::ensure_sufficient_stack
  83: rustc_query_system::query::plumbing::get_query_impl
  84: rustc_query_system::query::plumbing::ensure_query_impl
  85: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  86: rustc_hir::hir::Crate::par_visit_all_item_likes
  87: rustc_session::session::Session::track_errors
  88: rustc_typeck::check_crate
  89: rustc_interface::passes::analysis
  90: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  91: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
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.48.0-nightly (381b445ff 2020-09-29) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -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 [typeck] type-checking `bug::{constant#0}`
#1 [eval_to_allocation_raw] const-evaluating + checking `bug::{constant#0}`
#2 [eval_to_const_value_raw] simplifying constant for the type system `bug::{constant#0}`
#3 [eval_to_const_value_raw] simplifying constant for the type system `bug::{constant#0}`
#4 [check_item_well_formed] checking that `bug` is well-formed
#5 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error

error: could not compile `playground`

Maybe related to #73375 , #75883 and #66152 ? Feel free to close if so :)

@DutchGhost DutchGhost 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 Sep 30, 2020
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Sep 30, 2020
@matthiaskrgr
Copy link
Member

This ICEs since 1.33
@rustbot modify labels: +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. labels Dec 20, 2020
@camelid camelid added the A-const-generics Area: const generics (parameters and arguments) label Dec 20, 2020
@camelid
Copy link
Member

camelid commented Dec 20, 2020

Is this a const generics issue? I can't tell.

@camelid camelid added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Dec 20, 2020
@camelid
Copy link
Member

camelid commented Dec 20, 2020

On Zulip:

lcnr: and [is] a const generics issue

@camelid
Copy link
Member

camelid commented Dec 20, 2020

Assigning P-medium and removing I-prioritize as discussed in the prioritization working group.

@lcnr
Copy link
Contributor

lcnr commented Dec 20, 2020

expect this to get fixed by #79298 once that lands

@Alexendoo
Copy link
Member

Since min_const_generics stabilisation this now requires #![feature(const_generics)]

#![feature(const_generics)]

trait MyTrait<T> {}

fn bug<'a, T>() -> &'static dyn MyTrait<[(); { |x: &'a u32| { x }; 4 }]> {
    todo!()
}

@lcnr lcnr added 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 Feb 12, 2021
@bors bors closed this as completed in 1318d94 May 5, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue May 9, 2023
…ently, r=cjgillot

Various changes to name resolution of anon consts

Sorry this PR is kind of all over the place ^^'

Fixes rust-lang#111012

- Rewrites anon const nameres to all go through `fn resolve_anon_const` explicitly instead of `visit_anon_const` to ensure that we do not accidentally resolve anon consts as if they are allowed to use generics when they aren't. Also means that we dont have bits of code for resolving anon consts that will get out of sync (i.e. legacy const generics and resolving path consts that were parsed as type arguments)
- Renames two of the `LifetimeRibKind`, `AnonConst -> ConcreteAnonConst` and `ConstGeneric -> ConstParamTy`
- Noticed while doing this that under `generic_const_exprs` all lifetimes currently get resolved to errors without any error being emitted which was causing a bunch of tests to pass without their bugs having been fixed, incidentally fixed that in this PR and marked those tests as `// known-bug:`. I'm fine to break those since `generic_const_exprs` is a very unstable incomplete feature and this PR _does_ make generic_const_exprs "less broken" as a whole, also I can't be assed to figure out what the underlying causes of all of them are. This PR reopens rust-lang#77357 rust-lang#83993
- Changed `generics_of` to stop providing generics and predicates to enum variant discriminant anon consts since those are not allowed to use generic parameters
- Updated the error for non 'static lifetime in const arguments and the error for non 'static lifetime in const param tys to use `derive(Diagnostic)`

I have a vague idea why const-arg-in-const-arg.rs, in-closure.rs and simple.rs have started failing which is unfortunate since these were deliberately made to work, I think lifetime resolution being broken just means this regressed at some point and nobody noticed because the tests were not testing anything :( I'm fine breaking these too for the same reason as the tests for rust-lang#77357 rust-lang#83993. I couldn't get `// known-bug` to work for these ICEs and just kept getting different stderr between CI and local `--bless` so I just removed them and will create an issue to track re-adding (and fixing) the bugs if this PR lands.

r? `@cjgillot` cc `@compiler-errors`
@BoxyUwU
Copy link
Member

BoxyUwU commented May 10, 2023

reopening after #111215

@compiler-errors
Copy link
Member

for the record: no longer ICEs after #115486

@compiler-errors compiler-errors removed the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Sep 23, 2023
@lcnr lcnr 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 25, 2023
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. 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

Successfully merging a pull request may close this issue.

9 participants