]> git.ipfire.org Git - thirdparty/gcc.git/commit
gccrs: resolve: Add "break rust" Easter egg
authorSergey Bugaev <bugaevc@gmail.com>
Mon, 3 Apr 2023 15:58:43 +0000 (18:58 +0300)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:34:09 +0000 (18:34 +0100)
commit10d9514c67ac76963feb4e8cd2310a63d2519b8f
treec323c0e19bb3b95a8e56bb1e58ef098864d7a235
parent5138ddc3d652b66d3292c1543c34752e9ed78fc6
gccrs: resolve: Add "break rust" Easter egg

When we encounter a "break rust" statement, emit a funny error message
and intentionally cause an ICE. This matches the corresponding Easter
egg in rustc. As a GNU extension, "break gcc" is also supported.

The conditions for this to happen are:
* The break expression must be literally "rust" or "gcc". For instance,
  "break (rust)" will not trigger the Easter egg.
* The name ("rust" or "gcc") must not be in scope; if it is, no error
  is emitted, and the compilation proceeds as usual. In other words,
  this only affects how GCC diagnoses programs that would fail to
  compile anyway.

Note that this is different from the conditions under which rustc emits
its ICE. For rustc, it matters whether or not the "break" is inside a
loop, and for us it matters whether or not the name resolves. The end
result should be the same anyway: valid programs continue to compile,
and typing in

fn main() {
    break rust;
}

triggers a funny ICE.

Closes https://github.com/Rust-GCC/gccrs/issues/1996

gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-expr.cc: Add "break rust" Easter egg

gcc/testsuite/ChangeLog:
* lib/prune.exp (prune_ices):
Also prune "You have broken GCC Rust. This is a feature."
* rust/compile/break-rust1.rs: New test
* rust/compile/break-rust2.rs: New test
* rust/compile/break-rust3.rs: New test

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
gcc/rust/resolve/rust-ast-resolve-expr.cc
gcc/testsuite/lib/prune.exp
gcc/testsuite/rust/compile/break-rust1.rs [new file with mode: 0644]
gcc/testsuite/rust/compile/break-rust2.rs [new file with mode: 0644]
gcc/testsuite/rust/compile/break-rust3.rs [new file with mode: 0644]