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: broken MIR (on stable & beta) #113352

Closed
e2-71828 opened this issue Jul 5, 2023 · 4 comments
Closed

ICE: broken MIR (on stable & beta) #113352

e2-71828 opened this issue Jul 5, 2023 · 4 comments
Labels
C-bug Category: This is a bug. E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc 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

@e2-71828
Copy link

e2-71828 commented Jul 5, 2023

Code

use std::sync::{Arc,Weak,OnceLock};

pub struct WeakOnce<T>(OnceLock<Weak<T>>);
impl<T> WeakOnce<T> {
    pub const fn new() -> Self { WeakOnce(OnceLock::new()) }

    pub fn init(&self, val:T)->Arc<T> {
        let val = Arc::new(val);
        self.0.set(Arc::downgrade(&val)).unwrap();
        val
    }

    pub fn try_get(&self)->Option<Arc<T>> {
        self.0.get().and_then(Weak::upgrade)
    }

    pub fn get(&self)->Arc<T> {
        self.try_get().unwrap_or_else(|| panic!("Singleton {} not available", std::any::type_name::<T>()))
    }
}

pub(crate) static ONCE: WeakOnce<Context> = WeakOnce::new();
pub struct Context {
    pub x: String,
}

impl Context {
    pub fn init(x: String)->Arc<Self> {
        let ctx = ONCE.init(Context {x});
        std::thread::spawn(|| {
            while Some(ctx) = ONCE.try_get() {
                
            }
        });  
        ctx
    }
}

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=9cdd839ff9751cbceeb04cf44ad8ebc5

(NB: This code has a bug separate from the ICE; line 31 should read while let .... Fixing this also prevents the ICE.)

Meta

ICE happens on playground stable and beta, but not nightly (as of 2023-07-05):

note: rustc 1.70.0 (90c541806 2023-05-31) running on x86_64-unknown-linux-gnu
note: compiler flags: --crate-type lib -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2
note: rustc 1.71.0-beta.4 (dbf31f17d 2023-06-24) running on x86_64-unknown-linux-gnu
note: compiler flags: --crate-type lib -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2

Error output

Compiling playground v0.0.1 (/playground)
warning: value assigned to `ctx` is never read
  --> src/lib.rs:31:24
   |
31 |             while Some(ctx) = ONCE.try_get() {
   |                        ^^^
   |
   = help: maybe it is overwritten before being read?
   = note: `#[warn(unused_assignments)]` on by default

error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: coercion error but no error emitted
  --> src/lib.rs:31:19
   |
31 |             while Some(ctx) = ONCE.try_get() {
   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: delayed at    0: <rustc_errors::HandlerInner>::emit_diagnostic
              1: <rustc_errors::Handler>::delay_span_bug::<rustc_span::span_encoding::Span, &str>
              2: <rustc_hir_typeck::coercion::CoerceMany<&rustc_hir::hir::Expr>>::coerce_forced_unit
              3: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_block_with_expected
              4: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
              5: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
              6: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
              7: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_block_with_expected
              8: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
              9: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_block_with_expected
             10: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
             11: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_return_expr
             12: rustc_hir_typeck::check::check_fn
             13: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_closure
             14: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
             15: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_argument_types
             16: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_call
             17: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
             18: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_block_with_expected
             19: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
             20: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_return_expr
             21: rustc_hir_typeck::check::check_fn
             22: rustc_hir_typeck::typeck
             23: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::typeck, rustc_query_impl::plumbing::QueryCtxt>
             24: rustc_data_structures::sync::par_for_each_in::<&[rustc_span::def_id::LocalDefId], <rustc_middle::hir::map::Map>::par_body_owners<rustc_hir_typeck::typeck_item_bodies::{closure#0}>::{closure#0}>
             25: rustc_hir_typeck::typeck_item_bodies
             26: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::typeck_item_bodies, rustc_query_impl::plumbing::QueryCtxt>
             27: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck_item_bodies
             28: <rustc_session::session::Session>::time::<(), rustc_hir_analysis::check_crate::{closure#7}>
             29: rustc_hir_analysis::check_crate
             30: rustc_interface::passes::analysis
             31: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
             32: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
             33: <std::thread::local::LocalKey<core::cell::Cell<*const ()>>>::with::<rustc_middle::ty::context::tls::enter_context<<rustc_middle::ty::context::GlobalCtxt>::enter<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}::{closure#4}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
             34: <rustc_interface::interface::Compiler>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_span::ErrorGuaranteed>>
             35: rustc_span::set_source_map::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
             36: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
             37: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
             38: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                        at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/alloc/src/boxed.rs:1973:9
             39: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                        at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/alloc/src/boxed.rs:1973:9
             40: std::sys::unix::thread::Thread::new::thread_start
                        at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys/unix/thread.rs:108:17
             41: start_thread
             42: clone
           

error: internal compiler error[[E0308]](https://doc.rust-lang.org/stable/error_codes/E0308.html): mismatched types
  --> src/lib.rs:31:19
   |
31 |             while Some(ctx) = ONCE.try_get() {
   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `()`
   |
   = note: delayed at    0: <rustc_errors::HandlerInner>::emit_diagnostic
              1: <rustc_errors::Handler>::emit_diagnostic
              2: <rustc_span::ErrorGuaranteed as rustc_errors::diagnostic_builder::EmissionGuarantee>::diagnostic_builder_emit_producing_guarantee
              3: <rustc_hir_typeck::coercion::CoerceMany<&rustc_hir::hir::Expr>>::coerce_forced_unit
              4: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_block_with_expected
              5: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
              6: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
              7: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
              8: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_block_with_expected
              9: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
             10: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_block_with_expected
             11: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
             12: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_return_expr
             13: rustc_hir_typeck::check::check_fn
             14: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_closure
             15: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
             16: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_argument_types
             17: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_call
             18: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
             19: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_block_with_expected
             20: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
             21: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_return_expr
             22: rustc_hir_typeck::check::check_fn
             23: rustc_hir_typeck::typeck
             24: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::typeck, rustc_query_impl::plumbing::QueryCtxt>
             25: rustc_data_structures::sync::par_for_each_in::<&[rustc_span::def_id::LocalDefId], <rustc_middle::hir::map::Map>::par_body_owners<rustc_hir_typeck::typeck_item_bodies::{closure#0}>::{closure#0}>
             26: rustc_hir_typeck::typeck_item_bodies
             27: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::typeck_item_bodies, rustc_query_impl::plumbing::QueryCtxt>
             28: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck_item_bodies
             29: <rustc_session::session::Session>::time::<(), rustc_hir_analysis::check_crate::{closure#7}>
             30: rustc_hir_analysis::check_crate
             31: rustc_interface::passes::analysis
             32: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
             33: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
             34: <std::thread::local::LocalKey<core::cell::Cell<*const ()>>>::with::<rustc_middle::ty::context::tls::enter_context<<rustc_middle::ty::context::GlobalCtxt>::enter<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}::{closure#4}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
             35: <rustc_interface::interface::Compiler>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_span::ErrorGuaranteed>>
             36: rustc_span::set_source_map::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
             37: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
             38: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
             39: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                        at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/alloc/src/boxed.rs:1973:9
             40: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                        at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/alloc/src/boxed.rs:1973:9
             41: std::sys::unix::thread::Thread::new::thread_start
                        at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys/unix/thread.rs:108:17
             42: start_thread
             43: clone
           

error: internal compiler error: broken MIR in DefId(0:22 ~ playground[1036]::{impl#1}::init) ("return type"): bad type [type error]
  --> src/lib.rs:28:5
   |
28 |     pub fn init(x: String)->Arc<Self> {
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: delayed at    0: <rustc_errors::HandlerInner>::emit_diagnostic
              1: <rustc_errors::Handler>::delay_span_bug::<rustc_span::span_encoding::Span, &str>
              2: <rustc_borrowck::type_check::TypeVerifier as rustc_middle::mir::visit::Visitor>::visit_body
              3: rustc_borrowck::nll::compute_regions
              4: rustc_borrowck::do_mir_borrowck
              5: rustc_borrowck::mir_borrowck
              6: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::mir_borrowck, rustc_query_impl::plumbing::QueryCtxt>
              7: rustc_data_structures::sync::par_for_each_in::<&[rustc_span::def_id::LocalDefId], <rustc_middle::hir::map::Map>::par_body_owners<rustc_interface::passes::analysis::{closure#2}::{closure#0}>::{closure#0}>
              8: <rustc_session::session::Session>::time::<(), rustc_interface::passes::analysis::{closure#2}>
              9: rustc_interface::passes::analysis
             10: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
             11: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
             12: <std::thread::local::LocalKey<core::cell::Cell<*const ()>>>::with::<rustc_middle::ty::context::tls::enter_context<<rustc_middle::ty::context::GlobalCtxt>::enter<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}::{closure#4}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
             13: <rustc_interface::interface::Compiler>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_span::ErrorGuaranteed>>
             14: rustc_span::set_source_map::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
             15: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
             16: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
             17: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                        at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/alloc/src/boxed.rs:1973:9
             18: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                        at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/alloc/src/boxed.rs:1973:9
             19: std::sys::unix::thread::Thread::new::thread_start
                        at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys/unix/thread.rs:108:17
             20: start_thread
             21: clone
           

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at    0: <rustc_errors::HandlerInner>::emit_diagnostic
             1: <rustc_errors::Handler>::delay_span_bug::<rustc_span::span_encoding::Span, &str>
             2: <rustc_middle::ty::context::TyCtxt>::ty_error_misc
             3: <rustc_borrowck::type_check::TypeVerifier as rustc_middle::mir::visit::Visitor>::visit_body
             4: rustc_borrowck::nll::compute_regions
             5: rustc_borrowck::do_mir_borrowck
             6: rustc_borrowck::mir_borrowck
             7: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::mir_borrowck, rustc_query_impl::plumbing::QueryCtxt>
             8: rustc_data_structures::sync::par_for_each_in::<&[rustc_span::def_id::LocalDefId], <rustc_middle::hir::map::Map>::par_body_owners<rustc_interface::passes::analysis::{closure#2}::{closure#0}>::{closure#0}>
             9: <rustc_session::session::Session>::time::<(), rustc_interface::passes::analysis::{closure#2}>
            10: rustc_interface::passes::analysis
            11: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
            12: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
            13: <std::thread::local::LocalKey<core::cell::Cell<*const ()>>>::with::<rustc_middle::ty::context::tls::enter_context<<rustc_middle::ty::context::GlobalCtxt>::enter<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}::{closure#4}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
            14: <rustc_interface::interface::Compiler>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_span::ErrorGuaranteed>>
            15: rustc_span::set_source_map::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
            16: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
            17: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
            18: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                       at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/alloc/src/boxed.rs:1973:9
            19: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                       at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/alloc/src/boxed.rs:1973:9
            20: std::sys::unix::thread::Thread::new::thread_start
                       at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys/unix/thread.rs:108:17
            21: start_thread
            22: clone
          

error: internal compiler error: broken MIR in DefId(0:22 ~ playground[1036]::{impl#1}::init) (LocalDecl { mutability: Mut, local_info: Set(Boring), internal: false, ty: [type error], user_ty: None, source_info: SourceInfo { span: src/lib.rs:28:5: 28:38 (#0), scope: scope[0] } }): bad type [type error]
  --> src/lib.rs:28:5
   |
28 |     pub fn init(x: String)->Arc<Self> {
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: delayed at    0: <rustc_errors::HandlerInner>::emit_diagnostic
              1: <rustc_errors::Handler>::delay_span_bug::<rustc_span::span_encoding::Span, &str>
              2: <rustc_borrowck::type_check::TypeVerifier as rustc_middle::mir::visit::Visitor>::visit_body
              3: rustc_borrowck::nll::compute_regions
              4: rustc_borrowck::do_mir_borrowck
              5: rustc_borrowck::mir_borrowck
              6: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::mir_borrowck, rustc_query_impl::plumbing::QueryCtxt>
              7: rustc_data_structures::sync::par_for_each_in::<&[rustc_span::def_id::LocalDefId], <rustc_middle::hir::map::Map>::par_body_owners<rustc_interface::passes::analysis::{closure#2}::{closure#0}>::{closure#0}>
              8: <rustc_session::session::Session>::time::<(), rustc_interface::passes::analysis::{closure#2}>
              9: rustc_interface::passes::analysis
             10: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
             11: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
             12: <std::thread::local::LocalKey<core::cell::Cell<*const ()>>>::with::<rustc_middle::ty::context::tls::enter_context<<rustc_middle::ty::context::GlobalCtxt>::enter<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}::{closure#4}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
             13: <rustc_interface::interface::Compiler>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_span::ErrorGuaranteed>>
             14: rustc_span::set_source_map::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
             15: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
             16: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
             17: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                        at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/alloc/src/boxed.rs:1973:9
             18: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                        at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/alloc/src/boxed.rs:1973:9
             19: std::sys::unix::thread::Thread::new::thread_start
                        at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys/unix/thread.rs:108:17
             20: start_thread
             21: clone
           

error: internal compiler error: broken MIR in DefId(0:23 ~ playground[1036]::{impl#1}::init::{closure#0}) ("return type"): bad type [type error]
  --> src/lib.rs:30:28
   |
30 |         std::thread::spawn(|| {
   |                            ^^
   |
   = note: delayed at    0: <rustc_errors::HandlerInner>::emit_diagnostic
              1: <rustc_errors::Handler>::delay_span_bug::<rustc_span::span_encoding::Span, &str>
              2: <rustc_borrowck::type_check::TypeVerifier as rustc_middle::mir::visit::Visitor>::visit_body
              3: rustc_borrowck::nll::compute_regions
              4: rustc_borrowck::do_mir_borrowck
              5: rustc_borrowck::mir_borrowck
              6: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::mir_borrowck, rustc_query_impl::plumbing::QueryCtxt>
              7: rustc_data_structures::sync::par_for_each_in::<&[rustc_span::def_id::LocalDefId], <rustc_middle::hir::map::Map>::par_body_owners<rustc_interface::passes::analysis::{closure#2}::{closure#0}>::{closure#0}>
              8: <rustc_session::session::Session>::time::<(), rustc_interface::passes::analysis::{closure#2}>
              9: rustc_interface::passes::analysis
             10: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
             11: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
             12: <std::thread::local::LocalKey<core::cell::Cell<*const ()>>>::with::<rustc_middle::ty::context::tls::enter_context<<rustc_middle::ty::context::GlobalCtxt>::enter<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}::{closure#4}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
             13: <rustc_interface::interface::Compiler>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_span::ErrorGuaranteed>>
             14: rustc_span::set_source_map::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
             15: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
             16: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
             17: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                        at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/alloc/src/boxed.rs:1973:9
             18: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                        at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/alloc/src/boxed.rs:1973:9
             19: std::sys::unix::thread::Thread::new::thread_start
                        at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys/unix/thread.rs:108:17
             20: start_thread
             21: clone
           

error: internal compiler error: broken MIR in DefId(0:23 ~ playground[1036]::{impl#1}::init::{closure#0}) (LocalDecl { mutability: Mut, local_info: Set(Boring), internal: false, ty: [type error], user_ty: None, source_info: SourceInfo { span: src/lib.rs:30:28: 30:30 (#0), scope: scope[0] } }): bad type [type error]
  --> src/lib.rs:30:28
   |
30 |         std::thread::spawn(|| {
   |                            ^^
   |
   = note: delayed at    0: <rustc_errors::HandlerInner>::emit_diagnostic
              1: <rustc_errors::Handler>::delay_span_bug::<rustc_span::span_encoding::Span, &str>
              2: <rustc_borrowck::type_check::TypeVerifier as rustc_middle::mir::visit::Visitor>::visit_body
              3: rustc_borrowck::nll::compute_regions
              4: rustc_borrowck::do_mir_borrowck
              5: rustc_borrowck::mir_borrowck
              6: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::mir_borrowck, rustc_query_impl::plumbing::QueryCtxt>
              7: rustc_data_structures::sync::par_for_each_in::<&[rustc_span::def_id::LocalDefId], <rustc_middle::hir::map::Map>::par_body_owners<rustc_interface::passes::analysis::{closure#2}::{closure#0}>::{closure#0}>
              8: <rustc_session::session::Session>::time::<(), rustc_interface::passes::analysis::{closure#2}>
              9: rustc_interface::passes::analysis
             10: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
             11: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
             12: <std::thread::local::LocalKey<core::cell::Cell<*const ()>>>::with::<rustc_middle::ty::context::tls::enter_context<<rustc_middle::ty::context::GlobalCtxt>::enter<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}::{closure#4}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
             13: <rustc_interface::interface::Compiler>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_span::ErrorGuaranteed>>
             14: rustc_span::set_source_map::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
             15: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
             16: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
             17: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                        at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/alloc/src/boxed.rs:1973:9
             18: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                        at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/alloc/src/boxed.rs:1973:9
             19: std::sys::unix::thread::Thread::new::thread_start
                        at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys/unix/thread.rs:108:17
             20: start_thread
             21: clone
           

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.70.0 (90c541806 2023-05-31) running on x86_64-unknown-linux-gnu

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

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

query stack during panic:
end of query stack
For more information about this error, try `rustc --explain E0308`.
warning: `playground` (lib) generated 1 warning
error: could not compile `playground` (lib); 1 warning emitted
Backtrace

<backtrace>

@e2-71828 e2-71828 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 Jul 5, 2023
@compiler-errors compiler-errors added the E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc label Jul 5, 2023
@jieyouxu
Copy link
Contributor

jieyouxu commented Jul 5, 2023

I'll try to reduce this, it almost looks like some different variant of #112385.

@jieyouxu
Copy link
Contributor

jieyouxu commented Jul 5, 2023

Reduced (ICEing on stable, not nightly)

fn main() {
    let ctx = ();
    while Some(ctx) = None { }
}

It might just be another instance of #112385?

I think so, since this also ICEs on stable, which was the test case added in #112392.

fn main() {
    let ctx = Some(());
    while Some(ctx) = None { }
}

@e2-71828
Copy link
Author

e2-71828 commented Jul 5, 2023

It might just be another instance of #112385?

That seems likely to me. The only thing that your minimization missed is that the help message to use while let is not emitted for the original code here; that makes this no longer an ICE issue, just a potential diagnostics improvement:

Compiling playground v0.0.1 (/playground)
error[[E0308]](https://doc.rust-lang.org/nightly/error_codes/E0308.html): mismatched types
  --> src/lib.rs:31:19
   |
31 |             while Some(ctx) = ONCE.try_get() {
   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `()`

For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` (lib) due to previous error

@e2-71828
Copy link
Author

e2-71828 commented Jul 5, 2023

I have a minimal repro for the diagnostics problem; will submit as a new issue:

fn main() {
    let _ = || { while Some(_) = None { } };
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc 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

No branches or pull requests

3 participants