Skip to content

Invalid assignment in a while loop causes an ICE #93727

Closed
@Aiden2207

Description

@Aiden2207

Code

fn main() {
    while false{
        1 = 1;
    }   
}

Playground

When running on the most recent stable rust, I get

error: internal compiler error[[E0070]](https://doc.rust-lang.org/stable/error-index.html#E0070): invalid left-hand side of assignment
 --> src/main.rs:4:11
  |
4 |         1 = 1;
  |         - ^
  |         |
  |         cannot assign to this expression
  |
help: you might have meant to use pattern destructuring
  |
3 |     while let false{
  |           +++

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler/rustc_errors/src/lib.rs:1188:13
stack backtrace:
   0: rust_begin_unwind
             at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/core/src/panicking.rs:107:14
   2: core::panicking::panic_display::<&str>
   3: <rustc_errors::HandlerInner>::flush_delayed
   4: <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop
   5: core::ptr::drop_in_place::<rustc_session::parse::ParseSess>
   6: <alloc::rc::Rc<rustc_session::session::Session> as core::ops::drop::Drop>::drop
   7: core::ptr::drop_in_place::<rustc_interface::interface::Compiler>
   8: 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}>
   9: <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.

error: internal compiler error: unexpected panic

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.1 (db9d1b20b 2022-01-20) 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:
end of query stack
error: could not compile `playground

On beta, the compiler doesn't crash, but rustc does give a questionable recommendation to fix the issue:

error[[E0070]](https://doc.rust-lang.org/beta/error-index.html#E0070): invalid left-hand side of assignment
 --> src/main.rs:4:11
  |
4 |         1 = 1;
  |         - ^
  |         |
  |         cannot assign to this expression
  |
help: you might have meant to use pattern destructuring
  |
3 |     while let false{
  |           +++

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

On nightly(2022-02-06 as the time of writing) it compiles fine, giving the expected error message:

error[[E0070]](https://doc.rust-lang.org/nightly/error-index.html#E0070): invalid left-hand side of assignment
 --> src/main.rs:4:11
  |
4 |         1 = 1;
  |         - ^
  |         |
  |         cannot assign to this expression

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions