From 32c45317a15e68a2aba8df973706479857f61d75 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= <mati865@gmail.com>
Date: Fri, 8 Sep 2023 22:37:06 +0200
Subject: [PATCH 1/3] Add i686-pc-windows-gnullvm triple

---
 .../src/spec/i686_pc_windows_gnullvm.rs       | 26 +++++++++++++++++++
 compiler/rustc_target/src/spec/mod.rs         |  1 +
 src/doc/rustc/src/platform-support.md         |  1 +
 .../platform-support/pc-windows-gnullvm.md    |  3 ++-
 4 files changed, 30 insertions(+), 1 deletion(-)
 create mode 100644 compiler/rustc_target/src/spec/i686_pc_windows_gnullvm.rs

diff --git a/compiler/rustc_target/src/spec/i686_pc_windows_gnullvm.rs b/compiler/rustc_target/src/spec/i686_pc_windows_gnullvm.rs
new file mode 100644
index 00000000000..3154b512a52
--- /dev/null
+++ b/compiler/rustc_target/src/spec/i686_pc_windows_gnullvm.rs
@@ -0,0 +1,26 @@
+use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, Target};
+
+pub fn target() -> Target {
+    let mut base = super::windows_gnullvm_base::opts();
+    base.cpu = "pentium4".into();
+    base.max_atomic_width = Some(64);
+    base.frame_pointer = FramePointer::Always; // Required for backtraces
+    base.linker = Some("i686-w64-mingw32-clang".into());
+
+    // Mark all dynamic libraries and executables as compatible with the larger 4GiB address
+    // space available to x86 Windows binaries on x86_64.
+    base.add_pre_link_args(
+        LinkerFlavor::Gnu(Cc::No, Lld::No),
+        &["-m", "i386pe", "--large-address-aware"],
+    );
+
+    Target {
+        llvm_target: "i686-pc-windows-gnu".into(),
+        pointer_width: 32,
+        data_layout: "e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:64-\
+            i64:64-f80:32-n8:16:32-a:0:32-S32"
+            .into(),
+        arch: "x86".into(),
+        options: base,
+    }
+}
diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs
index fca99381c0c..8aa72797a0d 100644
--- a/compiler/rustc_target/src/spec/mod.rs
+++ b/compiler/rustc_target/src/spec/mod.rs
@@ -1420,6 +1420,7 @@ supported_targets! {
     ("x86_64-uwp-windows-gnu", x86_64_uwp_windows_gnu),
 
     ("aarch64-pc-windows-gnullvm", aarch64_pc_windows_gnullvm),
+    ("i686-pc-windows-gnullvm", i686_pc_windows_gnullvm),
     ("x86_64-pc-windows-gnullvm", x86_64_pc_windows_gnullvm),
 
     ("aarch64-pc-windows-msvc", aarch64_pc_windows_msvc),
diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md
index 269fe928754..70b35526ee5 100644
--- a/src/doc/rustc/src/platform-support.md
+++ b/src/doc/rustc/src/platform-support.md
@@ -267,6 +267,7 @@ target | std | host | notes
 [`i586-pc-nto-qnx700`](platform-support/nto-qnx.md) | * |  | 32-bit x86 QNX Neutrino 7.0 RTOS |
 `i686-apple-darwin` | ✓ | ✓ | 32-bit macOS (10.7+, Lion+)
 `i686-pc-windows-msvc` | * |  | 32-bit Windows XP support
+[`i686-pc-windows-gnullvm`](platform-support/pc-windows-gnullvm.md) | ✓ | ✓ |
 `i686-unknown-haiku` | ✓ | ✓ | 32-bit Haiku
 [`i686-unknown-netbsd`](platform-support/netbsd.md) | ✓ | ✓ | NetBSD/i386 with SSE2
 [`i686-unknown-openbsd`](platform-support/openbsd.md) | ✓ | ✓ | 32-bit OpenBSD
diff --git a/src/doc/rustc/src/platform-support/pc-windows-gnullvm.md b/src/doc/rustc/src/platform-support/pc-windows-gnullvm.md
index fb0cea05d44..a6246fa3bd8 100644
--- a/src/doc/rustc/src/platform-support/pc-windows-gnullvm.md
+++ b/src/doc/rustc/src/platform-support/pc-windows-gnullvm.md
@@ -6,6 +6,7 @@ Windows targets similar to `*-pc-windows-gnu` but using UCRT as the runtime and
 
 Target triples available so far:
 - `aarch64-pc-windows-gnullvm`
+- `i686-pc-windows-gnullvm`
 - `x86_64-pc-windows-gnullvm`
 
 ## Target maintainers
@@ -42,7 +43,7 @@ Once these targets bootstrap themselves on native hardware they should pass Rust
 
 ## Cross-compilation toolchains and C code
 
-Compatible C code can be built with Clang's `aarch64-pc-windows-gnu` and `x86_64-pc-windows-gnu` targets as long as LLVM based C toolchains are used.
+Compatible C code can be built with Clang's `aarch64-pc-windows-gnu`, `i686-pc-windows-gnullvm` and `x86_64-pc-windows-gnu` targets as long as LLVM based C toolchains are used.
 Those include:
 - [llvm-mingw](https://github.com/mstorsjo/llvm-mingw)
 - [MSYS2 with CLANG* environment](https://www.msys2.org/docs/environments)

From e36adff4c24c1cd61fcc72c94cf9d312ff366dc1 Mon Sep 17 00:00:00 2001
From: asquared31415 <34665709+asquared31415@users.noreply.github.com>
Date: Mon, 11 Sep 2023 18:04:22 +0000
Subject: [PATCH 2/3] add source type for invalid bool casts

---
 compiler/rustc_hir_typeck/src/cast.rs         |  9 ++-
 tests/ui/cast/cast-as-bool.rs                 | 40 ++++++++++++-
 tests/ui/cast/cast-as-bool.stderr             | 56 +++++++++++++++++--
 tests/ui/cast/cast-rfc0401-2.rs               |  2 +-
 tests/ui/cast/cast-rfc0401-2.stderr           |  2 +-
 tests/ui/error-codes/E0054.stderr             |  2 +-
 tests/ui/error-festival.stderr                |  2 +-
 tests/ui/mismatched_types/cast-rfc0401.stderr |  4 +-
 8 files changed, 103 insertions(+), 14 deletions(-)

diff --git a/compiler/rustc_hir_typeck/src/cast.rs b/compiler/rustc_hir_typeck/src/cast.rs
index 31a03fabe4f..e8d4e6b447f 100644
--- a/compiler/rustc_hir_typeck/src/cast.rs
+++ b/compiler/rustc_hir_typeck/src/cast.rs
@@ -321,8 +321,13 @@ impl<'a, 'tcx> CastCheck<'tcx> {
                 .emit();
             }
             CastError::CastToBool => {
-                let mut err =
-                    struct_span_err!(fcx.tcx.sess, self.span, E0054, "cannot cast as `bool`");
+                let mut err = struct_span_err!(
+                    fcx.tcx.sess,
+                    self.span,
+                    E0054,
+                    "cannot cast `{}` as `bool`",
+                    self.expr_ty
+                );
 
                 if self.expr_ty.is_numeric() {
                     match fcx.tcx.sess.source_map().span_to_snippet(self.expr_span) {
diff --git a/tests/ui/cast/cast-as-bool.rs b/tests/ui/cast/cast-as-bool.rs
index fbebc80d91c..750a88f97eb 100644
--- a/tests/ui/cast/cast-as-bool.rs
+++ b/tests/ui/cast/cast-as-bool.rs
@@ -1,12 +1,48 @@
 fn main() {
-    let u = 5 as bool; //~ ERROR cannot cast as `bool`
+    let u = 5 as bool; //~ ERROR cannot cast `i32` as `bool`
                        //~| HELP compare with zero instead
                        //~| SUGGESTION 5 != 0
 
-    let t = (1 + 2) as bool; //~ ERROR cannot cast as `bool`
+    let t = (1 + 2) as bool; //~ ERROR cannot cast `i32` as `bool`
                              //~| HELP compare with zero instead
                              //~| SUGGESTION (1 + 2) != 0
 
+    let _ = 5_u32 as bool; //~ ERROR cannot cast `u32` as `bool`
+                           //~| HELP compare with zero instead
+
+    let _ = 64.0_f64 as bool; //~ ERROR cannot cast `f64` as `bool`
+                              //~| HELP compare with zero instead
+
+    // Enums that can normally be cast to integers can't be cast to `bool`, just like integers.
+    // Note that enums that cannot be cast to integers can't be cast to anything at *all*
+    // so that's not tested here.
+    enum IntEnum {
+        Zero,
+        One,
+        Two
+    }
+    let _ = IntEnum::One as bool; //~ ERROR cannot cast `IntEnum` as `bool`
+
+    fn uwu(_: u8) -> String {
+        todo!()
+    }
+
+    unsafe fn owo() {}
+
+    // fn item to bool
+    let _ = uwu as bool; //~ ERROR cannot cast `fn(u8) -> String {uwu}` as `bool`
+    // unsafe fn item
+    let _ = owo as bool; //~ ERROR cannot cast `unsafe fn() {owo}` as `bool`
+
+    // fn ptr to bool
+    let _ = uwu as fn(u8) -> String as bool; //~ ERROR cannot cast `fn(u8) -> String` as `bool`
+
+    let _ = 'x' as bool; //~ ERROR cannot cast `char` as `bool`
+
+    let ptr = 1 as *const ();
+
+    let _ = ptr as bool; //~ ERROR cannot cast `*const ()` as `bool`
+
     let v = "hello" as bool;
     //~^ ERROR casting `&'static str` as `bool` is invalid
     //~| HELP consider using the `is_empty` method on `&'static str` to determine if it contains anything
diff --git a/tests/ui/cast/cast-as-bool.stderr b/tests/ui/cast/cast-as-bool.stderr
index 19ac8f10fec..852fb30cc20 100644
--- a/tests/ui/cast/cast-as-bool.stderr
+++ b/tests/ui/cast/cast-as-bool.stderr
@@ -1,18 +1,66 @@
-error[E0054]: cannot cast as `bool`
+error[E0054]: cannot cast `i32` as `bool`
   --> $DIR/cast-as-bool.rs:2:13
    |
 LL |     let u = 5 as bool;
    |             ^^^^^^^^^ help: compare with zero instead: `5 != 0`
 
-error[E0054]: cannot cast as `bool`
+error[E0054]: cannot cast `i32` as `bool`
   --> $DIR/cast-as-bool.rs:6:13
    |
 LL |     let t = (1 + 2) as bool;
    |             ^^^^^^^^^^^^^^^ help: compare with zero instead: `(1 + 2) != 0`
 
-error[E0606]: casting `&'static str` as `bool` is invalid
+error[E0054]: cannot cast `u32` as `bool`
   --> $DIR/cast-as-bool.rs:10:13
    |
+LL |     let _ = 5_u32 as bool;
+   |             ^^^^^^^^^^^^^ help: compare with zero instead: `5_u32 != 0`
+
+error[E0054]: cannot cast `f64` as `bool`
+  --> $DIR/cast-as-bool.rs:13:13
+   |
+LL |     let _ = 64.0_f64 as bool;
+   |             ^^^^^^^^^^^^^^^^ help: compare with zero instead: `64.0_f64 != 0`
+
+error[E0054]: cannot cast `IntEnum` as `bool`
+  --> $DIR/cast-as-bool.rs:24:13
+   |
+LL |     let _ = IntEnum::One as bool;
+   |             ^^^^^^^^^^^^^^^^^^^^ unsupported cast
+
+error[E0054]: cannot cast `fn(u8) -> String {uwu}` as `bool`
+  --> $DIR/cast-as-bool.rs:33:13
+   |
+LL |     let _ = uwu as bool;
+   |             ^^^^^^^^^^^ unsupported cast
+
+error[E0054]: cannot cast `unsafe fn() {owo}` as `bool`
+  --> $DIR/cast-as-bool.rs:35:13
+   |
+LL |     let _ = owo as bool;
+   |             ^^^^^^^^^^^ unsupported cast
+
+error[E0054]: cannot cast `fn(u8) -> String` as `bool`
+  --> $DIR/cast-as-bool.rs:38:13
+   |
+LL |     let _ = uwu as fn(u8) -> String as bool;
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsupported cast
+
+error[E0054]: cannot cast `char` as `bool`
+  --> $DIR/cast-as-bool.rs:40:13
+   |
+LL |     let _ = 'x' as bool;
+   |             ^^^^^^^^^^^ unsupported cast
+
+error[E0054]: cannot cast `*const ()` as `bool`
+  --> $DIR/cast-as-bool.rs:44:13
+   |
+LL |     let _ = ptr as bool;
+   |             ^^^^^^^^^^^ unsupported cast
+
+error[E0606]: casting `&'static str` as `bool` is invalid
+  --> $DIR/cast-as-bool.rs:46:13
+   |
 LL |     let v = "hello" as bool;
    |             ^^^^^^^^^^^^^^^
    |
@@ -21,7 +69,7 @@ help: consider using the `is_empty` method on `&'static str` to determine if it
 LL |     let v = !"hello".is_empty();
    |             +       ~~~~~~~~~~~
 
-error: aborting due to 3 previous errors
+error: aborting due to 11 previous errors
 
 Some errors have detailed explanations: E0054, E0606.
 For more information about an error, try `rustc --explain E0054`.
diff --git a/tests/ui/cast/cast-rfc0401-2.rs b/tests/ui/cast/cast-rfc0401-2.rs
index 7709aa34104..70604a587ea 100644
--- a/tests/ui/cast/cast-rfc0401-2.rs
+++ b/tests/ui/cast/cast-rfc0401-2.rs
@@ -4,5 +4,5 @@
 
 fn main() {
     let _ = 3 as bool;
-    //~^ ERROR cannot cast as `bool`
+    //~^ ERROR cannot cast `i32` as `bool`
 }
diff --git a/tests/ui/cast/cast-rfc0401-2.stderr b/tests/ui/cast/cast-rfc0401-2.stderr
index 52f6af78a9b..5dc21ca847c 100644
--- a/tests/ui/cast/cast-rfc0401-2.stderr
+++ b/tests/ui/cast/cast-rfc0401-2.stderr
@@ -1,4 +1,4 @@
-error[E0054]: cannot cast as `bool`
+error[E0054]: cannot cast `i32` as `bool`
   --> $DIR/cast-rfc0401-2.rs:6:13
    |
 LL |     let _ = 3 as bool;
diff --git a/tests/ui/error-codes/E0054.stderr b/tests/ui/error-codes/E0054.stderr
index 6b1092760fb..ea81f4476a7 100644
--- a/tests/ui/error-codes/E0054.stderr
+++ b/tests/ui/error-codes/E0054.stderr
@@ -1,4 +1,4 @@
-error[E0054]: cannot cast as `bool`
+error[E0054]: cannot cast `i32` as `bool`
   --> $DIR/E0054.rs:3:24
    |
 LL |     let x_is_nonzero = x as bool;
diff --git a/tests/ui/error-festival.stderr b/tests/ui/error-festival.stderr
index e8ee1d96942..74a2bc8d768 100644
--- a/tests/ui/error-festival.stderr
+++ b/tests/ui/error-festival.stderr
@@ -59,7 +59,7 @@ error[E0605]: non-primitive cast: `u8` as `Vec<u8>`
 LL |     x as Vec<u8>;
    |     ^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
 
-error[E0054]: cannot cast as `bool`
+error[E0054]: cannot cast `{integer}` as `bool`
   --> $DIR/error-festival.rs:33:24
    |
 LL |     let x_is_nonzero = x as bool;
diff --git a/tests/ui/mismatched_types/cast-rfc0401.stderr b/tests/ui/mismatched_types/cast-rfc0401.stderr
index 6b9ac3c5852..0cea60746bf 100644
--- a/tests/ui/mismatched_types/cast-rfc0401.stderr
+++ b/tests/ui/mismatched_types/cast-rfc0401.stderr
@@ -82,13 +82,13 @@ error[E0606]: casting `f32` as `*const u8` is invalid
 LL |     let _ = f as *const u8;
    |             ^^^^^^^^^^^^^^
 
-error[E0054]: cannot cast as `bool`
+error[E0054]: cannot cast `i32` as `bool`
   --> $DIR/cast-rfc0401.rs:39:13
    |
 LL |     let _ = 3_i32 as bool;
    |             ^^^^^^^^^^^^^ help: compare with zero instead: `3_i32 != 0`
 
-error[E0054]: cannot cast as `bool`
+error[E0054]: cannot cast `E` as `bool`
   --> $DIR/cast-rfc0401.rs:40:13
    |
 LL |     let _ = E::A as bool;

From 5860c4b006a7e9eb6fca7319b13dc0739a3de808 Mon Sep 17 00:00:00 2001
From: Santiago Pastorino <spastorino@gmail.com>
Date: Mon, 11 Sep 2023 16:55:34 -0300
Subject: [PATCH 3/3] Remove spastorino as "on vacation"

---
 triagebot.toml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/triagebot.toml b/triagebot.toml
index 39c18a55697..7492c0d67fd 100644
--- a/triagebot.toml
+++ b/triagebot.toml
@@ -585,7 +585,7 @@ cc = ["@nnethercote"]
 [assign]
 warn_non_default_branch = true
 contributing_url = "https://rustc-dev-guide.rust-lang.org/getting-started.html"
-users_on_vacation = ["jyn514", "clubby789", "spastorino"]
+users_on_vacation = ["jyn514", "clubby789"]
 
 [assign.adhoc_groups]
 compiler-team = [