| 1 |
// Copyright (C) 2020-2024 Free Software Foundation, Inc. |
| 2 |
|
| 3 |
// This file is part of GCC. |
| 4 |
|
| 5 |
// GCC is free software; you can redistribute it and/or modify it under |
| 6 |
// the terms of the GNU General Public License as published by the Free |
| 7 |
// Software Foundation; either version 3, or (at your option) any later |
| 8 |
// version. |
| 9 |
|
| 10 |
// GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
| 11 |
// WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 |
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 13 |
// for more details. |
| 14 |
|
| 15 |
// You should have received a copy of the GNU General Public License |
| 16 |
// along with GCC; see the file COPYING3. If not see |
| 17 |
// <http://www.gnu.org/licenses/>. |
| 18 |
|
| 19 |
#ifndef RUST_ICE_FINALIZER_H |
| 20 |
#define RUST_ICE_FINALIZER_H |
| 21 |
|
| 22 |
#include "rust-linemap.h" |
| 23 |
#include "diagnostic.h" |
| 24 |
|
| 25 |
namespace Rust { |
| 26 |
namespace Resolver { |
| 27 |
|
| 28 |
/* The "break rust" Easter egg. |
| 29 |
|
| 30 |
Backstory: once upon a time, there used to be a bug in rustc: it would ICE |
| 31 |
during typechecking on a 'break' with an expression outside of a loop. The |
| 32 |
issue has been reported [0] and fixed [1], but in recognition of this, as a |
| 33 |
special Easter egg, "break rust" was made to intentionally cause an ICE. |
| 34 |
|
| 35 |
[0]: https://github.com/rust-lang/rust/issues/43162 |
| 36 |
[1]: https://github.com/rust-lang/rust/pull/43745 |
| 37 |
|
| 38 |
This was made in a way that does not break valid programs: namely, it only |
| 39 |
happens when the 'break' is outside of a loop (so invalid anyway). |
| 40 |
|
| 41 |
GCC Rust supports this essential feature as well, but in a slightly |
| 42 |
different way. Instead of delaying the error until type checking, we emit |
| 43 |
it here in the resolution phase. We, too, only do this to programs that |
| 44 |
are already invalid: we only emit our funny ICE if the name "rust" (which |
| 45 |
must be immediately inside a break-with-a-value expression) fails to |
| 46 |
resolve. Note that "break (rust)" does not trigger our ICE, only using |
| 47 |
"break rust" directly does, and only if there's no "rust" in scope. We do |
| 48 |
this in the same way regardless of whether the "break" is outside of a loop |
| 49 |
or inside one. |
| 50 |
|
| 51 |
As a GNU extension, we also support "break gcc", much to the same effect, |
| 52 |
subject to the same rules. */ |
| 53 |
|
| 54 |
/* The finalizer for our funny ICE. This prints a custom message instead of |
| 55 |
the default bug reporting instructions, as there is no bug to report. */ |
| 56 |
|
| 57 |
void ATTRIBUTE_NORETURN |
| 58 |
funny_ice_text_finalizer (diagnostic_text_output_format &text_output, |
| 59 |
const diagnostic_info *diagnostic, |
| 60 |
diagnostic_t diag_kind); |
| 61 |
|
| 62 |
} // namespace Resolver |
| 63 |
} // namespace Rust |
| 64 |
|
| 65 |
#endif /* ! RUST_ICE_FINALIZER_H */ |