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

error: internal compiler error: compiler/rustc_middle/src/middle/region.rs:377:32: no enclosing scope for id 6 #92893

Closed
DutchGhost opened this issue Jan 14, 2022 · 6 comments · Fixed by #94849
Assignees
Labels
A-const-eval Area: Constant evaluation (MIR interpretation) A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. 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

@DutchGhost
Copy link
Contributor

DutchGhost commented Jan 14, 2022

Code

struct Bug<A = [(); (let a = (), 1).1]> {
    a: A   
}

fn main() {
    
}

Meta

rustc --version --verbose:

rustc 1.58.0 (02072b482 2022-01-11)
rustc 1.59.0-beta.1 (7c0b25092 2022-01-13)
rustc 1.60.0-nightly (22e491ac7 2022-01-13)

Error output

error: internal compiler error: compiler/rustc_middle/src/middle/region.rs:377:32: no enclosing scope for id 6
Backtrace

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1169:9
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: std::panic::panic_any::<rustc_errors::ExplicitBug>
   2: <rustc_errors::HandlerInner>::bug
   3: <rustc_errors::Handler>::bug
   4: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, ()>
   5: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>
   6: rustc_middle::util::bug::bug_fmt
   7: <rustc_middle::middle::region::ScopeTree>::var_scope
   8: <rustc_mir_build::build::Builder>::bind_and_guard_matched_candidate
   9: <rustc_mir_build::build::Builder>::bind_pattern
  10: <rustc_mir_build::build::Builder>::lower_let_expr
  11: <rustc_mir_build::build::Builder>::in_if_then_scope::<<rustc_mir_build::build::Builder>::expr_into_dest::{closure#1}>
  12: <rustc_mir_build::build::Builder>::expr_into_dest
  13: <rustc_mir_build::build::Builder>::as_temp_inner
  14: <rustc_mir_build::build::Builder>::as_operand
  15: <rustc_mir_build::build::Builder>::as_operand
  16: <alloc::vec::Vec<rustc_middle::mir::Operand> as alloc::vec::spec_from_iter::SpecFromIter<rustc_middle::mir::Operand, core::iter::adapters::map::Map<core::iter::adapters::copied::Copied<core::slice::iter::Iter<rustc_middle::thir::ExprId>>, <rustc_mir_build::build::Builder>::as_rvalue::{closure#2}>>>::from_iter
  17: <rustc_mir_build::build::Builder>::as_rvalue
  18: <rustc_mir_build::build::Builder>::expr_into_dest
  19: <rustc_mir_build::build::Builder>::as_temp_inner
  20: <rustc_mir_build::build::Builder>::expr_as_place
  21: <rustc_mir_build::build::Builder>::expr_as_place
  22: <rustc_mir_build::build::Builder>::expr_as_place
  23: <rustc_mir_build::build::Builder>::expr_into_dest
  24: <rustc_mir_build::build::Builder>::in_scope::<<rustc_mir_build::build::Builder>::expr_into_dest::{closure#0}::{closure#0}, ()>
  25: <rustc_mir_build::build::Builder>::expr_into_dest
  26: <rustc_mir_build::build::Builder>::in_scope::<<rustc_mir_build::build::Builder>::expr_into_dest::{closure#0}::{closure#0}, ()>
  27: <rustc_mir_build::build::Builder>::expr_into_dest
  28: rustc_mir_build::build::construct_const
  29: <rustc_infer::infer::InferCtxtBuilder>::enter::<rustc_middle::mir::Body, rustc_mir_build::build::mir_build::{closure#1}>
  30: rustc_mir_build::build::mir_built
  31: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_middle::ty::WithOptConstParam<rustc_span::def_id::LocalDefId>, &rustc_data_structures::steal::Steal<rustc_middle::mir::Body>>>
  32: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_built
  33: rustc_mir_transform::check_unsafety::unsafety_check_result
  34: <rustc_mir_transform::check_unsafety::provide::{closure#0} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_span::def_id::LocalDefId)>>::call_once
  35: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalDefId, &rustc_middle::mir::query::UnsafetyCheckResult>>
  36: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::unsafety_check_result
  37: rustc_mir_transform::mir_const
  38: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_middle::ty::WithOptConstParam<rustc_span::def_id::LocalDefId>, &rustc_data_structures::steal::Steal<rustc_middle::mir::Body>>>
  39: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_const
  40: rustc_mir_transform::mir_const_qualif
  41: <rustc_mir_transform::provide::{closure#0} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_span::def_id::DefId)>>::call_once
  42: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::DefId, rustc_middle::mir::query::ConstQualifs>>
  43: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::mir_const_qualif, rustc_query_impl::plumbing::QueryCtxt>
  44: rustc_const_eval::const_eval::eval_queries::eval_to_allocation_raw_provider
  45: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::eval_to_allocation_raw, rustc_query_impl::plumbing::QueryCtxt>
  46: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::eval_to_allocation_raw
  47: rustc_const_eval::const_eval::eval_queries::eval_to_const_value_raw_provider
  48: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_middle::ty::ParamEnvAnd<rustc_middle::mir::interpret::GlobalId>, core::result::Result<rustc_middle::mir::interpret::value::ConstValue, rustc_middle::mir::interpret::error::ErrorHandled>>>
  49: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::eval_to_const_value_raw
  50: rustc_const_eval::const_eval::eval_queries::eval_to_const_value_raw_provider
  51: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_middle::ty::ParamEnvAnd<rustc_middle::mir::interpret::GlobalId>, core::result::Result<rustc_middle::mir::interpret::value::ConstValue, rustc_middle::mir::interpret::error::ErrorHandled>>>
  52: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::eval_to_const_value_raw
  53: <rustc_middle::ty::context::TyCtxt>::const_eval_global_id
  54: <rustc_middle::ty::context::TyCtxt>::const_eval_resolve
  55: <rustc_trait_selection::traits::project::AssocTypeNormalizer as rustc_middle::ty::fold::TypeFolder>::fold_const
  56: <&rustc_middle::ty::TyS as rustc_middle::ty::fold::TypeFoldable>::super_fold_with::<rustc_trait_selection::traits::project::AssocTypeNormalizer>
  57: <rustc_trait_selection::traits::project::AssocTypeNormalizer as rustc_middle::ty::fold::TypeFolder>::fold_ty
  58: <&rustc_middle::ty::list::List<rustc_middle::ty::subst::GenericArg> as rustc_middle::ty::fold::TypeFoldable>::fold_with::<rustc_trait_selection::traits::project::AssocTypeNormalizer>
  59: <rustc_middle::ty::PredicateKind as rustc_middle::ty::fold::TypeFoldable>::fold_with::<rustc_trait_selection::traits::project::AssocTypeNormalizer>
  60: <rustc_trait_selection::traits::project::AssocTypeNormalizer>::fold::<rustc_middle::ty::Predicate>
  61: rustc_trait_selection::traits::project::normalize::<rustc_middle::ty::Predicate>
  62: <rustc_infer::infer::InferCtxt as rustc_trait_selection::infer::InferCtxtExt>::partially_normalize_associated_types_in::<rustc_middle::ty::Predicate>
  63: rustc_typeck::check::wfcheck::check_where_clauses
  64: <rustc_infer::infer::InferCtxtBuilder>::enter::<(), <rustc_typeck::check::inherited::InheritedBuilder>::enter<<rustc_typeck::check::wfcheck::CheckWfFcxBuilder>::with_fcx<rustc_typeck::check::wfcheck::check_type_defn<rustc_typeck::check::wfcheck::check_item_well_formed::{closure#2}>::{closure#0}>::{closure#0}, ()>::{closure#0}>
  65: rustc_typeck::check::wfcheck::check_item_well_formed
  66: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalDefId, ()>>
  67: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::check_item_well_formed
  68: <core::panic::unwind_safe::AssertUnwindSafe<rustc_data_structures::sync::par_for_each_in<&alloc::vec::Vec<core::option::Option<rustc_hir::hir::OwnerInfo>>, <rustc_middle::hir::map::Map>::par_visit_all_item_likes<rustc_typeck::check::wfcheck::CheckTypeWellFormedVisitor>::{closure#0}>::{closure#0}::{closure#0}> as core::ops::function::FnOnce<()>>::call_once
  69: rustc_data_structures::sync::par_for_each_in::<&alloc::vec::Vec<core::option::Option<rustc_hir::hir::OwnerInfo>>, <rustc_middle::hir::map::Map>::par_visit_all_item_likes<rustc_typeck::check::wfcheck::CheckTypeWellFormedVisitor>::{closure#0}>
  70: <rustc_session::session::Session>::track_errors::<rustc_typeck::check_crate::{closure#5}, ()>
  71: rustc_typeck::check_crate
  72: rustc_interface::passes::analysis
  73: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<(), core::result::Result<(), rustc_errors::ErrorReported>>>
  74: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
  75: <rustc_interface::passes::QueryContext>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}::{closure#3}, core::result::Result<(), rustc_errors::ErrorReported>>
  76: <rustc_interface::interface::Compiler>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_errors::ErrorReported>>
  77: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#1}>
  78: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>
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.58.0 (02072b482 2022-01-11) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type bin

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

query stack during panic:
#0 [mir_built] building MIR for `Bug::{constant#0}`
#1 [unsafety_check_result] unsafety-checking `Bug::{constant#0}`
#2 [mir_const] processing MIR for `Bug::{constant#0}`
#3 [mir_const_qualif] const checking `Bug::{constant#0}`
#4 [eval_to_allocation_raw] const-evaluating + checking `Bug::{constant#0}`
#5 [eval_to_const_value_raw] simplifying constant for the type system `Bug::{constant#0}`
#6 [eval_to_const_value_raw] simplifying constant for the type system `Bug::{constant#0}`
#7 [check_item_well_formed] checking that `Bug` is well-formed
#8 [analysis] running analysis passes on this crate
end of query stack
For more information about this error, try `rustc --explain E0658`.
error: could not compile `playground` due to 2 previous er

@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 Jan 14, 2022
@compiler-errors
Copy link
Member

I was just looking at the parsing code for const generic exprs..

@rustbot claim

@compiler-errors
Copy link
Member

actually, so this isn't related to incorrectly parsing let, since we're parsing let in expr position to allow if-let chains.. -- this is due to const eval lowering to MIR and the fact that const generic parameters have no enclosing scope. Adding { } around the generic args works, but I don't know where exactly to hack in a scope for these params.

@rustbot release-assignment
@rustbot label A-const-eval A-mir

@rustbot rustbot added A-const-eval Area: Constant evaluation (MIR interpretation) A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html labels Jan 15, 2022
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Jan 15, 2022
@matthiaskrgr
Copy link
Member

Maybe fixing this also fixes rust-lang/rust-clippy#8245 🙂

@ouz-a
Copy link
Contributor

ouz-a commented Jan 20, 2022

This gives an error without ICE in 1.55 https://godbolt.org/z/fP1xMx8f3

@jyn514
Copy link
Member

jyn514 commented Mar 10, 2022

Adding { } around the generic args works, but I don't know where exactly to hack in a scope for these params.

It was unclear to me - I think @compiler-errors meant that changing (let a = (), 1).1 to {(let a = (), 1).1} gives a compile error instead of an ICE. So the proper fix here is probably to add delay_span_bug somewhere instead of panicking.

@ouz-a
Copy link
Contributor

ouz-a commented Mar 10, 2022

Adding { } around the generic args works, but I don't know where exactly to hack in a scope for these params.

It was unclear to me - I think @compiler-errors meant that changing (let a = (), 1).1 to {(let a = (), 1).1} gives a compile error instead of an ICE. So the proper fix here is probably to add delay_span_bug somewhere instead of panicking.

Then this should be easy.
@rustbot claim

fee1-dead added a commit to fee1-dead-contrib/rust that referenced this issue Apr 15, 2022
Check var scope if it exist

Fixes rust-lang#92893.

Added helper function to check the scope of a variable, if it doesn't have a scope call delay_span_bug, which avoids us trying to get a block/scope that doesn't exist.

Had to increase `ROOT_ENTRY_LIMIT` was getting tidy error
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Apr 15, 2022
Check var scope if it exist

Fixes rust-lang#92893.

Added helper function to check the scope of a variable, if it doesn't have a scope call delay_span_bug, which avoids us trying to get a block/scope that doesn't exist.

Had to increase `ROOT_ENTRY_LIMIT` was getting tidy error
@bors bors closed this as completed in a32e0f3 Apr 15, 2022
flip1995 pushed a commit to flip1995/rust that referenced this issue Apr 21, 2022
Check var scope if it exist

Fixes rust-lang#92893.

Added helper function to check the scope of a variable, if it doesn't have a scope call delay_span_bug, which avoids us trying to get a block/scope that doesn't exist.

Had to increase `ROOT_ENTRY_LIMIT` was getting tidy error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation (MIR interpretation) A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. 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.

7 participants