Skip to content

Commit 6c03617

Browse files
committed
Auto merge of #115769 - matthiaskrgr:rollup-bo82nn9, r=matthiaskrgr
Rollup of 3 pull requests Successful merges: - #115687 (Add `i686-pc-windows-gnullvm` triple) - #115765 (Add source type for invalid bool casts) - #115768 (Remove spastorino as "on vacation") r? `@ghost` `@rustbot` modify labels: rollup
2 parents 366dab1 + 10da075 commit 6c03617

File tree

13 files changed

+134
-16
lines changed

13 files changed

+134
-16
lines changed

compiler/rustc_hir_typeck/src/cast.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,13 @@ impl<'a, 'tcx> CastCheck<'tcx> {
321321
.emit();
322322
}
323323
CastError::CastToBool => {
324-
let mut err =
325-
struct_span_err!(fcx.tcx.sess, self.span, E0054, "cannot cast as `bool`");
324+
let mut err = struct_span_err!(
325+
fcx.tcx.sess,
326+
self.span,
327+
E0054,
328+
"cannot cast `{}` as `bool`",
329+
self.expr_ty
330+
);
326331

327332
if self.expr_ty.is_numeric() {
328333
match fcx.tcx.sess.source_map().span_to_snippet(self.expr_span) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, Target};
2+
3+
pub fn target() -> Target {
4+
let mut base = super::windows_gnullvm_base::opts();
5+
base.cpu = "pentium4".into();
6+
base.max_atomic_width = Some(64);
7+
base.frame_pointer = FramePointer::Always; // Required for backtraces
8+
base.linker = Some("i686-w64-mingw32-clang".into());
9+
10+
// Mark all dynamic libraries and executables as compatible with the larger 4GiB address
11+
// space available to x86 Windows binaries on x86_64.
12+
base.add_pre_link_args(
13+
LinkerFlavor::Gnu(Cc::No, Lld::No),
14+
&["-m", "i386pe", "--large-address-aware"],
15+
);
16+
17+
Target {
18+
llvm_target: "i686-pc-windows-gnu".into(),
19+
pointer_width: 32,
20+
data_layout: "e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:64-\
21+
i64:64-f80:32-n8:16:32-a:0:32-S32"
22+
.into(),
23+
arch: "x86".into(),
24+
options: base,
25+
}
26+
}

compiler/rustc_target/src/spec/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,7 @@ supported_targets! {
14201420
("x86_64-uwp-windows-gnu", x86_64_uwp_windows_gnu),
14211421

14221422
("aarch64-pc-windows-gnullvm", aarch64_pc_windows_gnullvm),
1423+
("i686-pc-windows-gnullvm", i686_pc_windows_gnullvm),
14231424
("x86_64-pc-windows-gnullvm", x86_64_pc_windows_gnullvm),
14241425

14251426
("aarch64-pc-windows-msvc", aarch64_pc_windows_msvc),

src/doc/rustc/src/platform-support.md

+1
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ target | std | host | notes
267267
[`i586-pc-nto-qnx700`](platform-support/nto-qnx.md) | * | | 32-bit x86 QNX Neutrino 7.0 RTOS |
268268
`i686-apple-darwin` | ✓ | ✓ | 32-bit macOS (10.7+, Lion+)
269269
`i686-pc-windows-msvc` | * | | 32-bit Windows XP support
270+
[`i686-pc-windows-gnullvm`](platform-support/pc-windows-gnullvm.md) | ✓ | ✓ |
270271
`i686-unknown-haiku` | ✓ | ✓ | 32-bit Haiku
271272
[`i686-unknown-netbsd`](platform-support/netbsd.md) | ✓ | ✓ | NetBSD/i386 with SSE2
272273
[`i686-unknown-openbsd`](platform-support/openbsd.md) | ✓ | ✓ | 32-bit OpenBSD

src/doc/rustc/src/platform-support/pc-windows-gnullvm.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Windows targets similar to `*-pc-windows-gnu` but using UCRT as the runtime and
66

77
Target triples available so far:
88
- `aarch64-pc-windows-gnullvm`
9+
- `i686-pc-windows-gnullvm`
910
- `x86_64-pc-windows-gnullvm`
1011

1112
## Target maintainers
@@ -42,7 +43,7 @@ Once these targets bootstrap themselves on native hardware they should pass Rust
4243

4344
## Cross-compilation toolchains and C code
4445

45-
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.
46+
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.
4647
Those include:
4748
- [llvm-mingw](https://github.com/mstorsjo/llvm-mingw)
4849
- [MSYS2 with CLANG* environment](https://www.msys2.org/docs/environments)

tests/ui/cast/cast-as-bool.rs

+38-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,48 @@
11
fn main() {
2-
let u = 5 as bool; //~ ERROR cannot cast as `bool`
2+
let u = 5 as bool; //~ ERROR cannot cast `i32` as `bool`
33
//~| HELP compare with zero instead
44
//~| SUGGESTION 5 != 0
55

6-
let t = (1 + 2) as bool; //~ ERROR cannot cast as `bool`
6+
let t = (1 + 2) as bool; //~ ERROR cannot cast `i32` as `bool`
77
//~| HELP compare with zero instead
88
//~| SUGGESTION (1 + 2) != 0
99

10+
let _ = 5_u32 as bool; //~ ERROR cannot cast `u32` as `bool`
11+
//~| HELP compare with zero instead
12+
13+
let _ = 64.0_f64 as bool; //~ ERROR cannot cast `f64` as `bool`
14+
//~| HELP compare with zero instead
15+
16+
// Enums that can normally be cast to integers can't be cast to `bool`, just like integers.
17+
// Note that enums that cannot be cast to integers can't be cast to anything at *all*
18+
// so that's not tested here.
19+
enum IntEnum {
20+
Zero,
21+
One,
22+
Two
23+
}
24+
let _ = IntEnum::One as bool; //~ ERROR cannot cast `IntEnum` as `bool`
25+
26+
fn uwu(_: u8) -> String {
27+
todo!()
28+
}
29+
30+
unsafe fn owo() {}
31+
32+
// fn item to bool
33+
let _ = uwu as bool; //~ ERROR cannot cast `fn(u8) -> String {uwu}` as `bool`
34+
// unsafe fn item
35+
let _ = owo as bool; //~ ERROR cannot cast `unsafe fn() {owo}` as `bool`
36+
37+
// fn ptr to bool
38+
let _ = uwu as fn(u8) -> String as bool; //~ ERROR cannot cast `fn(u8) -> String` as `bool`
39+
40+
let _ = 'x' as bool; //~ ERROR cannot cast `char` as `bool`
41+
42+
let ptr = 1 as *const ();
43+
44+
let _ = ptr as bool; //~ ERROR cannot cast `*const ()` as `bool`
45+
1046
let v = "hello" as bool;
1147
//~^ ERROR casting `&'static str` as `bool` is invalid
1248
//~| HELP consider using the `is_empty` method on `&'static str` to determine if it contains anything

tests/ui/cast/cast-as-bool.stderr

+52-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,66 @@
1-
error[E0054]: cannot cast as `bool`
1+
error[E0054]: cannot cast `i32` as `bool`
22
--> $DIR/cast-as-bool.rs:2:13
33
|
44
LL | let u = 5 as bool;
55
| ^^^^^^^^^ help: compare with zero instead: `5 != 0`
66

7-
error[E0054]: cannot cast as `bool`
7+
error[E0054]: cannot cast `i32` as `bool`
88
--> $DIR/cast-as-bool.rs:6:13
99
|
1010
LL | let t = (1 + 2) as bool;
1111
| ^^^^^^^^^^^^^^^ help: compare with zero instead: `(1 + 2) != 0`
1212

13-
error[E0606]: casting `&'static str` as `bool` is invalid
13+
error[E0054]: cannot cast `u32` as `bool`
1414
--> $DIR/cast-as-bool.rs:10:13
1515
|
16+
LL | let _ = 5_u32 as bool;
17+
| ^^^^^^^^^^^^^ help: compare with zero instead: `5_u32 != 0`
18+
19+
error[E0054]: cannot cast `f64` as `bool`
20+
--> $DIR/cast-as-bool.rs:13:13
21+
|
22+
LL | let _ = 64.0_f64 as bool;
23+
| ^^^^^^^^^^^^^^^^ help: compare with zero instead: `64.0_f64 != 0`
24+
25+
error[E0054]: cannot cast `IntEnum` as `bool`
26+
--> $DIR/cast-as-bool.rs:24:13
27+
|
28+
LL | let _ = IntEnum::One as bool;
29+
| ^^^^^^^^^^^^^^^^^^^^ unsupported cast
30+
31+
error[E0054]: cannot cast `fn(u8) -> String {uwu}` as `bool`
32+
--> $DIR/cast-as-bool.rs:33:13
33+
|
34+
LL | let _ = uwu as bool;
35+
| ^^^^^^^^^^^ unsupported cast
36+
37+
error[E0054]: cannot cast `unsafe fn() {owo}` as `bool`
38+
--> $DIR/cast-as-bool.rs:35:13
39+
|
40+
LL | let _ = owo as bool;
41+
| ^^^^^^^^^^^ unsupported cast
42+
43+
error[E0054]: cannot cast `fn(u8) -> String` as `bool`
44+
--> $DIR/cast-as-bool.rs:38:13
45+
|
46+
LL | let _ = uwu as fn(u8) -> String as bool;
47+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsupported cast
48+
49+
error[E0054]: cannot cast `char` as `bool`
50+
--> $DIR/cast-as-bool.rs:40:13
51+
|
52+
LL | let _ = 'x' as bool;
53+
| ^^^^^^^^^^^ unsupported cast
54+
55+
error[E0054]: cannot cast `*const ()` as `bool`
56+
--> $DIR/cast-as-bool.rs:44:13
57+
|
58+
LL | let _ = ptr as bool;
59+
| ^^^^^^^^^^^ unsupported cast
60+
61+
error[E0606]: casting `&'static str` as `bool` is invalid
62+
--> $DIR/cast-as-bool.rs:46:13
63+
|
1664
LL | let v = "hello" as bool;
1765
| ^^^^^^^^^^^^^^^
1866
|
@@ -21,7 +69,7 @@ help: consider using the `is_empty` method on `&'static str` to determine if it
2169
LL | let v = !"hello".is_empty();
2270
| + ~~~~~~~~~~~
2371

24-
error: aborting due to 3 previous errors
72+
error: aborting due to 11 previous errors
2573

2674
Some errors have detailed explanations: E0054, E0606.
2775
For more information about an error, try `rustc --explain E0054`.

tests/ui/cast/cast-rfc0401-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
fn main() {
66
let _ = 3 as bool;
7-
//~^ ERROR cannot cast as `bool`
7+
//~^ ERROR cannot cast `i32` as `bool`
88
}

tests/ui/cast/cast-rfc0401-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0054]: cannot cast as `bool`
1+
error[E0054]: cannot cast `i32` as `bool`
22
--> $DIR/cast-rfc0401-2.rs:6:13
33
|
44
LL | let _ = 3 as bool;

tests/ui/error-codes/E0054.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0054]: cannot cast as `bool`
1+
error[E0054]: cannot cast `i32` as `bool`
22
--> $DIR/E0054.rs:3:24
33
|
44
LL | let x_is_nonzero = x as bool;

tests/ui/error-festival.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ error[E0605]: non-primitive cast: `u8` as `Vec<u8>`
5959
LL | x as Vec<u8>;
6060
| ^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
6161

62-
error[E0054]: cannot cast as `bool`
62+
error[E0054]: cannot cast `{integer}` as `bool`
6363
--> $DIR/error-festival.rs:33:24
6464
|
6565
LL | let x_is_nonzero = x as bool;

tests/ui/mismatched_types/cast-rfc0401.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ error[E0606]: casting `f32` as `*const u8` is invalid
8282
LL | let _ = f as *const u8;
8383
| ^^^^^^^^^^^^^^
8484

85-
error[E0054]: cannot cast as `bool`
85+
error[E0054]: cannot cast `i32` as `bool`
8686
--> $DIR/cast-rfc0401.rs:39:13
8787
|
8888
LL | let _ = 3_i32 as bool;
8989
| ^^^^^^^^^^^^^ help: compare with zero instead: `3_i32 != 0`
9090

91-
error[E0054]: cannot cast as `bool`
91+
error[E0054]: cannot cast `E` as `bool`
9292
--> $DIR/cast-rfc0401.rs:40:13
9393
|
9494
LL | let _ = E::A as bool;

triagebot.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ cc = ["@nnethercote"]
585585
[assign]
586586
warn_non_default_branch = true
587587
contributing_url = "https://rustc-dev-guide.rust-lang.org/getting-started.html"
588-
users_on_vacation = ["jyn514", "clubby789", "spastorino"]
588+
users_on_vacation = ["jyn514", "clubby789"]
589589

590590
[assign.adhoc_groups]
591591
compiler-team = [

0 commit comments

Comments
 (0)