Skip to content

breaking labeled while-loop in const assignment results in ICE #51350

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
DutchGhost opened this issue Jun 4, 2018 · 5 comments · Fixed by #60360
Closed

breaking labeled while-loop in const assignment results in ICE #51350

DutchGhost opened this issue Jun 4, 2018 · 5 comments · Fixed by #60360
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@DutchGhost
Copy link
Contributor

DutchGhost commented Jun 4, 2018

A while ago, this would cause an illigal instruction, but has been fixed, see #50856 , and no longer is an issue in the current nightly.

'a: while break 'a {};

Except, using such code while creating a constant, results in an ICE:
https://play.rust-lang.org/?gist=e974c3b625754ce340a4bd77bd3b7235&version=nightly&mode=debug

const crash: () = 'a: while break 'a {};

fn main() {

}

This is rustc 1.28.0-nightly (5d0631a 2018-05-30).

Backtrace:

error: internal compiler error: librustc_mir\transform\qualify_consts.rs:272: multiple assignments to _0
 --> src\main.rs:1:19
  |
1 | const crash: () = 'a: while break 'a {};
  |                   ^^^^^^^^^^^^^^^^^^^^^

thread 'main' panicked at 'Box<Any>', librustc_errors\lib.rs:499:9
stack backtrace:
   0: <std::sync::mpsc::RecvTimeoutError as core::fmt::Debug>::fmt
   1: <std::sys::windows::dynamic_lib::DynamicLibrary as core::ops::drop::Drop>::drop
   2: std::panicking::take_hook
   3: std::panicking::take_hook
   4: rustc::ty::structural_impls::<impl rustc::ty::context::Lift<'tcx> for rustc::middle::const_val::ErrKind<'a>>::lift_to_tcx
   5: std::panicking::rust_panic_with_hook
   6: <rustc_mir::transform::uniform_array_move_out::LocalUse as core::fmt::Debug>::fmt
   7: <rustc_mir::transform::uniform_array_move_out::LocalUse as core::fmt::Debug>::fmt
   8: <rustc_mir::dataflow::move_paths::abs_domain::AbstractOperand as core::fmt::Debug>::fmt
   9: <rustc_mir::dataflow::move_paths::abs_domain::AbstractOperand as core::fmt::Debug>::fmt
  10: <rustc_mir::dataflow::move_paths::abs_domain::AbstractOperand as core::fmt::Debug>::fmt
  11: <rustc_mir::dataflow::move_paths::abs_domain::AbstractOperand as core::fmt::Debug>::fmt
  12: <rustc_mir::transform::qualify_consts::Qualif as core::fmt::UpperHex>::fmt
  13: <rustc_mir::transform::qualify_consts::Qualif as core::fmt::UpperHex>::fmt
  14: <rustc_mir::transform::qualify_consts::Mode as core::fmt::Display>::fmt
  15: <rustc_mir::monomorphize::collector::MonoItemCollectionMode as core::fmt::Debug>::fmt
  16: <rustc_mir::transform::qualify_consts::Mode as core::fmt::Display>::fmt
  17: rustc_mir::transform::qualify_consts::provide
  18: rustc::ty::context::tls::track_diagnostic
  19: rustc::ty::context::tls::track_diagnostic
  20: rustc::dep_graph::graph::DepGraph::assert_ignored
  21: rustc::ty::context::tls::track_diagnostic
  22: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_mark_green_and_read
  23: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_mark_green_and_read
  24: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::mir_const_qualif
  25: rustc_mir::transform::mir_validated
  26: rustc::ty::maps::on_disk_cache::__ty_decoder_impl::<impl serialize::serialize::Decoder for rustc::ty::maps::on_disk_cache::CacheDecoder<'a, 'tcx, 'x>>::read_str
  27: rustc::ty::context::tls::track_diagnostic
  28: rustc::ty::context::tls::track_diagnostic
  29: rustc::dep_graph::graph::DepGraph::assert_ignored
  30: rustc::ty::context::tls::track_diagnostic
  31: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_mark_green_and_read
  32: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_mark_green_and_read
  33: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_mark_green_and_read
  34: rustc_borrowck::borrowck::provide
  35: rustc::ty::context::tls::track_diagnostic
  36: rustc::ty::context::tls::track_diagnostic
  37: rustc::dep_graph::graph::DepGraph::assert_ignored
  38: rustc::ty::context::tls::track_diagnostic
  39: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_mark_green_and_read
  40: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_mark_green_and_read
  41: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::borrowck
  42: rustc_borrowck::borrowck::check_crate
  43: <humantime::duration::Error as std::error::Error>::cause
  44: <rustc_driver::pretty::NoAnn<'hir> as rustc_driver::pretty::HirPrinterSupport<'hir>>::sess
  45: <unknown>
  46: rustc_driver::driver::compile_input
  47: rustc_driver::run_compiler
  48: rustc_driver::target_features::add_configuration
  49: rustc_driver::target_features::add_configuration
  50: _rust_maybe_catch_panic
  51: rustc_driver::set_sigpipe_handler
  52: rustc_driver::main
  53: <unknown>
  54: std::panicking::update_panic_count
  55: _rust_maybe_catch_panic
  56: std::rt::lang_start_internal
  57: <unknown>
  58: <unknown>
  59: BaseThreadInitThunk
  60: RtlUserThreadStart
query stack during panic:
#0 [mir_const_qualif] processing `crash`
#1 [mir_validated] processing `crash`
#2 [borrowck] processing `crash`
end of query stack
error: aborting due to previous error
@DutchGhost DutchGhost changed the title breaking labeled while loop in const array assignment results in ICE breaking labeled while-loop in const assignment results in ICE Jun 4, 2018
@estebank estebank added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Jun 4, 2018
@shssoichiro
Copy link
Contributor

I can look into this. I should be able to reference the previous PR to help resolve the issue.

@varkor
Copy link
Member

varkor commented Jun 23, 2018

@shssoichiro: the problem here is quite different. The issue is that the break gets turned into a TerminatorKind::Return, which then causes assign to be called (which causes the ICE):

self.assign(&Place::Local(index), Location {

and hence the error to never be reached here:

Really, it feels like this error is happening at too low a level, and it'd be better to match on the expressions at a higher level to report a similar error, rather than doing the analysis on the MIR.

@DutchGhost
Copy link
Contributor Author

Still ICE's in both 2015 and 2018 editions.

@DutchGhost
Copy link
Contributor Author

As of now, this no longer ICE's. Looking on godbolt, since stable 1.33 this code just compiles.

@Centril Centril added E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. labels Apr 28, 2019
rasendubi added a commit to rasendubi/rust that referenced this issue Apr 28, 2019
@rasendubi
Copy link
Contributor

Added a test case: #60360

Centril added a commit to Centril/rust that referenced this issue Apr 29, 2019
…ntril

Add test case for labeled break in const assignment

Fixes rust-lang#51350.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants