From 2ecb40e04a3ff8aeefc470598d8ea51edc197b26 Mon Sep 17 00:00:00 2001 From: Pavel Grigorenko Date: Tue, 14 Jan 2025 18:13:52 +0300 Subject: [PATCH 1/6] Stabilize `vec_pop_if` --- library/alloc/src/lib.rs | 1 - library/alloc/src/vec/mod.rs | 4 +--- library/alloc/tests/lib.rs | 1 - 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 28e4217e30394..494f2b7aadb4d 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -155,7 +155,6 @@ #![feature(unicode_internals)] #![feature(unsize)] #![feature(unwrap_infallible)] -#![feature(vec_pop_if)] // tidy-alphabetical-end // // Language features: diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 88bd3f414ea16..34aacd337b4f2 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -2518,8 +2518,6 @@ impl Vec { /// # Examples /// /// ``` - /// #![feature(vec_pop_if)] - /// /// let mut vec = vec![1, 2, 3, 4]; /// let pred = |x: &mut i32| *x % 2 == 0; /// @@ -2527,7 +2525,7 @@ impl Vec { /// assert_eq!(vec, [1, 2, 3]); /// assert_eq!(vec.pop_if(pred), None); /// ``` - #[unstable(feature = "vec_pop_if", issue = "122741")] + #[stable(feature = "vec_pop_if", since = "CURRENT_RUSTC_VERSION")] pub fn pop_if(&mut self, predicate: impl FnOnce(&mut T) -> bool) -> Option { let last = self.last_mut()?; if predicate(last) { self.pop() } else { None } diff --git a/library/alloc/tests/lib.rs b/library/alloc/tests/lib.rs index d8364d750fa8f..733b2508f6686 100644 --- a/library/alloc/tests/lib.rs +++ b/library/alloc/tests/lib.rs @@ -37,7 +37,6 @@ #![feature(local_waker)] #![feature(str_as_str)] #![feature(strict_provenance_lints)] -#![feature(vec_pop_if)] #![feature(vec_deque_pop_if)] #![feature(unique_rc_arc)] #![feature(macro_metavar_expr_concat)] From 68081f47b4fabbc99d3b206e27073a576e937c54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Thu, 2 Jan 2025 00:33:04 +0900 Subject: [PATCH 2/6] Add cygwin target. Co-authored-by: Ookiineko Co-authored-by: nora <48135649+Noratrieb@users.noreply.github.com> Co-authored-by: Jubilee --- compiler/rustc_target/src/spec/base/cygwin.rs | 51 +++++++++++++++++++ compiler/rustc_target/src/spec/base/mod.rs | 1 + compiler/rustc_target/src/spec/mod.rs | 5 +- .../src/spec/targets/x86_64_pc_cygwin.rs | 32 ++++++++++++ src/bootstrap/src/core/builder/cargo.rs | 6 ++- src/doc/rustc/src/SUMMARY.md | 1 + src/doc/rustc/src/platform-support.md | 1 + .../src/platform-support/x86_64-pc-cygwin.md | 39 ++++++++++++++ tests/assembly/targets/targets-pe.rs | 3 ++ tests/ui/check-cfg/well-known-values.stderr | 4 +- 10 files changed, 138 insertions(+), 5 deletions(-) create mode 100644 compiler/rustc_target/src/spec/base/cygwin.rs create mode 100644 compiler/rustc_target/src/spec/targets/x86_64_pc_cygwin.rs create mode 100644 src/doc/rustc/src/platform-support/x86_64-pc-cygwin.md diff --git a/compiler/rustc_target/src/spec/base/cygwin.rs b/compiler/rustc_target/src/spec/base/cygwin.rs new file mode 100644 index 0000000000000..2d29060c47a39 --- /dev/null +++ b/compiler/rustc_target/src/spec/base/cygwin.rs @@ -0,0 +1,51 @@ +use std::borrow::Cow; + +use crate::spec::{Cc, DebuginfoKind, LinkerFlavor, Lld, SplitDebuginfo, TargetOptions, cvs}; + +pub(crate) fn opts() -> TargetOptions { + let mut pre_link_args = TargetOptions::link_args(LinkerFlavor::Gnu(Cc::No, Lld::No), &[ + // FIXME: Disable ASLR for now to fix relocation error + "--disable-dynamicbase", + "--enable-auto-image-base", + ]); + crate::spec::add_link_args(&mut pre_link_args, LinkerFlavor::Gnu(Cc::Yes, Lld::No), &[ + // Tell GCC to avoid linker plugins, because we are not bundling + // them with Windows installer, and Rust does its own LTO anyways. + "-fno-use-linker-plugin", + "-Wl,--disable-dynamicbase", + "-Wl,--enable-auto-image-base", + ]); + let cygwin_libs = &["-lcygwin", "-lgcc", "-lcygwin", "-luser32", "-lkernel32", "-lgcc_s"]; + let mut late_link_args = + TargetOptions::link_args(LinkerFlavor::Gnu(Cc::No, Lld::No), cygwin_libs); + crate::spec::add_link_args( + &mut late_link_args, + LinkerFlavor::Gnu(Cc::Yes, Lld::No), + cygwin_libs, + ); + TargetOptions { + os: "cygwin".into(), + vendor: "pc".into(), + // FIXME(#13846) this should be enabled for cygwin + function_sections: false, + linker: Some("gcc".into()), + dynamic_linking: true, + dll_prefix: "".into(), + dll_suffix: ".dll".into(), + exe_suffix: ".exe".into(), + families: cvs!["unix"], + is_like_windows: true, + allows_weak_linkage: false, + pre_link_args, + late_link_args, + abi_return_struct_as_int: true, + emit_debug_gdb_scripts: false, + requires_uwtable: true, + eh_frame_header: false, + // FIXME(davidtwco): Support Split DWARF on Cygwin - may require LLVM changes to + // output DWO, despite using DWARF, doesn't use ELF.. + debuginfo_kind: DebuginfoKind::Pdb, + supported_split_debuginfo: Cow::Borrowed(&[SplitDebuginfo::Off]), + ..Default::default() + } +} diff --git a/compiler/rustc_target/src/spec/base/mod.rs b/compiler/rustc_target/src/spec/base/mod.rs index 28d10dcf2ff3a..b9139c8452c5f 100644 --- a/compiler/rustc_target/src/spec/base/mod.rs +++ b/compiler/rustc_target/src/spec/base/mod.rs @@ -3,6 +3,7 @@ pub(crate) mod android; pub(crate) mod apple; pub(crate) mod avr_gnu; pub(crate) mod bpf; +pub(crate) mod cygwin; pub(crate) mod dragonfly; pub(crate) mod freebsd; pub(crate) mod fuchsia; diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 72600225e7a38..5afe4caec7637 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -2019,6 +2019,7 @@ supported_targets! { ("riscv64imac-unknown-nuttx-elf", riscv64imac_unknown_nuttx_elf), ("riscv64gc-unknown-nuttx-elf", riscv64gc_unknown_nuttx_elf), + ("x86_64-pc-cygwin", x86_64_pc_cygwin), } /// Cow-Vec-Str: Cow<'static, [Cow<'static, str>]> @@ -3004,8 +3005,8 @@ impl Target { ); check_eq!( self.is_like_windows, - self.os == "windows" || self.os == "uefi", - "`is_like_windows` must be set if and only if `os` is `windows` or `uefi`" + self.os == "windows" || self.os == "uefi" || self.os == "cygwin", + "`is_like_windows` must be set if and only if `os` is `windows`, `uefi` or `cygwin`" ); check_eq!( self.is_like_wasm, diff --git a/compiler/rustc_target/src/spec/targets/x86_64_pc_cygwin.rs b/compiler/rustc_target/src/spec/targets/x86_64_pc_cygwin.rs new file mode 100644 index 0000000000000..a5bedd07e6be8 --- /dev/null +++ b/compiler/rustc_target/src/spec/targets/x86_64_pc_cygwin.rs @@ -0,0 +1,32 @@ +use crate::spec::{Cc, LinkerFlavor, Lld, Target, base}; + +pub(crate) fn target() -> Target { + let mut base = base::cygwin::opts(); + base.cpu = "x86-64".into(); + // FIXME: Disable ASLR for now to fix relocation error + base.add_pre_link_args(LinkerFlavor::Gnu(Cc::No, Lld::No), &[ + "-m", + "i386pep", + "--disable-high-entropy-va", + ]); + base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &[ + "-m64", + "-Wl,--disable-high-entropy-va", + ]); + base.max_atomic_width = Some(64); + base.linker = Some("x86_64-pc-cygwin-gcc".into()); + Target { + llvm_target: "x86_64-pc-cygwin".into(), + pointer_width: 64, + data_layout: + "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128".into(), + arch: "x86_64".into(), + options: base, + metadata: crate::spec::TargetMetadata { + description: Some("64-bit x86 Cygwin".into()), + tier: Some(3), + host_tools: Some(false), + std: Some(true), + }, + } +} diff --git a/src/bootstrap/src/core/builder/cargo.rs b/src/bootstrap/src/core/builder/cargo.rs index 2ecab262413fa..dc1ef7ce245cf 100644 --- a/src/bootstrap/src/core/builder/cargo.rs +++ b/src/bootstrap/src/core/builder/cargo.rs @@ -245,7 +245,11 @@ impl Cargo { // flesh out rpath support more fully in the future. self.rustflags.arg("-Zosx-rpath-install-name"); Some(format!("-Wl,-rpath,@loader_path/../{libdir}")) - } else if !target.is_windows() && !target.contains("aix") && !target.contains("xous") { + } else if !target.is_windows() + && !target.contains("cygwin") + && !target.contains("aix") + && !target.contains("xous") + { self.rustflags.arg("-Clink-args=-Wl,-z,origin"); Some(format!("-Wl,-rpath,$ORIGIN/../{libdir}")) } else { diff --git a/src/doc/rustc/src/SUMMARY.md b/src/doc/rustc/src/SUMMARY.md index 670e4bd1be68b..33d94d0939c08 100644 --- a/src/doc/rustc/src/SUMMARY.md +++ b/src/doc/rustc/src/SUMMARY.md @@ -101,6 +101,7 @@ - [\*-win7-windows-gnu](platform-support/win7-windows-gnu.md) - [\*-win7-windows-msvc](platform-support/win7-windows-msvc.md) - [x86_64-fortanix-unknown-sgx](platform-support/x86_64-fortanix-unknown-sgx.md) + - [x86_64-pc-cygwin](platform-support/x86_64-pc-cygwin.md) - [x86_64-pc-solaris](platform-support/solaris.md) - [x86_64-unknown-linux-none.md](platform-support/x86_64-unknown-linux-none.md) - [x86_64-unknown-none](platform-support/x86_64-unknown-none.md) diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index 3b6abdd84832c..ac243a55810d4 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -406,6 +406,7 @@ target | std | host | notes [`wasm64-unknown-unknown`](platform-support/wasm64-unknown-unknown.md) | ? | | WebAssembly [`x86_64-apple-tvos`](platform-support/apple-tvos.md) | ✓ | | x86 64-bit tvOS [`x86_64-apple-watchos-sim`](platform-support/apple-watchos.md) | ✓ | | x86 64-bit Apple WatchOS simulator +[`x86_64-pc-cygwin`](platform-support/x86_64-pc-cygwin.md) | ? | | 64-bit x86 Cygwin | [`x86_64-pc-nto-qnx710`](platform-support/nto-qnx.md) | ✓ | | x86 64-bit QNX Neutrino 7.1 RTOS with default network stack (io-pkt) | [`x86_64-pc-nto-qnx710_iosock`](platform-support/nto-qnx.md) | ✓ | | x86 64-bit QNX Neutrino 7.1 RTOS with new network stack (io-sock) | [`x86_64-pc-nto-qnx800`](platform-support/nto-qnx.md) | ✓ | | x86 64-bit QNX Neutrino 8.0 RTOS | diff --git a/src/doc/rustc/src/platform-support/x86_64-pc-cygwin.md b/src/doc/rustc/src/platform-support/x86_64-pc-cygwin.md new file mode 100644 index 0000000000000..a8fc4f181d8ad --- /dev/null +++ b/src/doc/rustc/src/platform-support/x86_64-pc-cygwin.md @@ -0,0 +1,39 @@ +# `x86_64-pc-cygwin` + +**Tier: 3** + +Windows targets supporting Cygwin. +The `*-cygwin` targets are **not** intended as native target for applications, +a developer writing Windows applications should use the `*-pc-windows-*` targets instead, which are *native* Windows. + +Cygwin is only intended as an emulation layer for Unix-only programs which do not support the native Windows targets. + +## Target maintainers + +- [Berrysoft](https://github.com/Berrysoft) + +## Requirements + +This target is cross compiled. It needs `x86_64-pc-cygwin-gcc` as linker. + +The `target_os` of the target is `cygwin`, and it is `unix`. + +## Building the target + +For cross-compilation you want LLVM with [llvm/llvm-project#121439 (merged)](https://github.com/llvm/llvm-project/pull/121439) applied to fix the LLVM codegen on importing external global variables from DLLs. +No native builds on Cygwin now. It should be possible theoretically though, but might need a lot of patches. + +## Building Rust programs + +Rust does not yet ship pre-compiled artifacts for this target. To compile for +this target, you will either need to build Rust with the target enabled (see +"Building the target" above), or build your own copy of `core` by using +`build-std` or similar. + +## Testing + +Created binaries work fine on Windows with Cygwin. + +## Cross-compilation toolchains and C code + +Compatible C code can be built with GCC shipped with Cygwin. Clang is untested. diff --git a/tests/assembly/targets/targets-pe.rs b/tests/assembly/targets/targets-pe.rs index ab74de5c8ec42..1fa4dc821dd37 100644 --- a/tests/assembly/targets/targets-pe.rs +++ b/tests/assembly/targets/targets-pe.rs @@ -84,6 +84,9 @@ //@ revisions: x86_64_win7_windows_msvc //@ [x86_64_win7_windows_msvc] compile-flags: --target x86_64-win7-windows-msvc //@ [x86_64_win7_windows_msvc] needs-llvm-components: x86 +//@ revisions: x86_64_pc_cygwin +//@ [x86_64_pc_cygwin] compile-flags: --target x86_64-pc-cygwin +//@ [x86_64_pc_cygwin] needs-llvm-components: x86 // Sanity-check that each target can produce assembly code. diff --git a/tests/ui/check-cfg/well-known-values.stderr b/tests/ui/check-cfg/well-known-values.stderr index ffebd7e553198..71d1f37372037 100644 --- a/tests/ui/check-cfg/well-known-values.stderr +++ b/tests/ui/check-cfg/well-known-values.stderr @@ -201,7 +201,7 @@ warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` LL | target_os = "_UNEXPECTED_VALUE", | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `nuttx`, `openbsd`, `psp`, `psx`, `redox`, `rtems`, `solaris`, `solid_asp3`, `teeos`, `trusty`, `tvos`, `uefi`, `unknown`, `visionos`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`, and `zkvm` + = note: expected values for `target_os` are: `aix`, `android`, `cuda`, `cygwin`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `nuttx`, `openbsd`, `psp`, `psx`, `redox`, `rtems`, `solaris`, `solid_asp3`, `teeos`, `trusty`, `tvos`, `uefi`, `unknown`, `visionos`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`, and `zkvm` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` @@ -274,7 +274,7 @@ LL | #[cfg(target_os = "linuz")] // testing that we suggest `linux` | | | help: there is a expected value with a similar name: `"linux"` | - = note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `nuttx`, `openbsd`, `psp`, `psx`, `redox`, `rtems`, `solaris`, `solid_asp3`, `teeos`, `trusty`, `tvos`, `uefi`, `unknown`, `visionos`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`, and `zkvm` + = note: expected values for `target_os` are: `aix`, `android`, `cuda`, `cygwin`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `nuttx`, `openbsd`, `psp`, `psx`, `redox`, `rtems`, `solaris`, `solid_asp3`, `teeos`, `trusty`, `tvos`, `uefi`, `unknown`, `visionos`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`, and `zkvm` = note: see for more information about checking conditional configuration warning: 28 warnings emitted From 402a52e1998558b4de77e2c7520bd4b6a25fd2e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Wed, 5 Feb 2025 09:26:17 +0800 Subject: [PATCH 3/6] Apply suggestions --- compiler/rustc_target/src/spec/base/cygwin.rs | 8 +------- .../src/spec/targets/x86_64_pc_cygwin.rs | 14 +++----------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/compiler/rustc_target/src/spec/base/cygwin.rs b/compiler/rustc_target/src/spec/base/cygwin.rs index 2d29060c47a39..8cb3cceb2d59b 100644 --- a/compiler/rustc_target/src/spec/base/cygwin.rs +++ b/compiler/rustc_target/src/spec/base/cygwin.rs @@ -4,14 +4,10 @@ use crate::spec::{Cc, DebuginfoKind, LinkerFlavor, Lld, SplitDebuginfo, TargetOp pub(crate) fn opts() -> TargetOptions { let mut pre_link_args = TargetOptions::link_args(LinkerFlavor::Gnu(Cc::No, Lld::No), &[ - // FIXME: Disable ASLR for now to fix relocation error "--disable-dynamicbase", "--enable-auto-image-base", ]); crate::spec::add_link_args(&mut pre_link_args, LinkerFlavor::Gnu(Cc::Yes, Lld::No), &[ - // Tell GCC to avoid linker plugins, because we are not bundling - // them with Windows installer, and Rust does its own LTO anyways. - "-fno-use-linker-plugin", "-Wl,--disable-dynamicbase", "-Wl,--enable-auto-image-base", ]); @@ -42,9 +38,7 @@ pub(crate) fn opts() -> TargetOptions { emit_debug_gdb_scripts: false, requires_uwtable: true, eh_frame_header: false, - // FIXME(davidtwco): Support Split DWARF on Cygwin - may require LLVM changes to - // output DWO, despite using DWARF, doesn't use ELF.. - debuginfo_kind: DebuginfoKind::Pdb, + debuginfo_kind: DebuginfoKind::Dwarf, supported_split_debuginfo: Cow::Borrowed(&[SplitDebuginfo::Off]), ..Default::default() } diff --git a/compiler/rustc_target/src/spec/targets/x86_64_pc_cygwin.rs b/compiler/rustc_target/src/spec/targets/x86_64_pc_cygwin.rs index a5bedd07e6be8..8da4fe6b8b152 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64_pc_cygwin.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64_pc_cygwin.rs @@ -3,16 +3,8 @@ use crate::spec::{Cc, LinkerFlavor, Lld, Target, base}; pub(crate) fn target() -> Target { let mut base = base::cygwin::opts(); base.cpu = "x86-64".into(); - // FIXME: Disable ASLR for now to fix relocation error - base.add_pre_link_args(LinkerFlavor::Gnu(Cc::No, Lld::No), &[ - "-m", - "i386pep", - "--disable-high-entropy-va", - ]); - base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &[ - "-m64", - "-Wl,--disable-high-entropy-va", - ]); + base.add_pre_link_args(LinkerFlavor::Gnu(Cc::No, Lld::No), &["-m", "i386pep"]); + base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]); base.max_atomic_width = Some(64); base.linker = Some("x86_64-pc-cygwin-gcc".into()); Target { @@ -26,7 +18,7 @@ pub(crate) fn target() -> Target { description: Some("64-bit x86 Cygwin".into()), tier: Some(3), host_tools: Some(false), - std: Some(true), + std: None, }, } } From a3a9c28ba1100e1e9dd157889850c51078659df2 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 7 Feb 2025 16:19:13 +0100 Subject: [PATCH 4/6] Update minifier version to `0.3.4` --- Cargo.lock | 4 ++-- src/librustdoc/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7c8f06a023969..1467bd59295f4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2322,9 +2322,9 @@ dependencies = [ [[package]] name = "minifier" -version = "0.3.2" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd559bbf5d350ac7f2c1cf92ed71a869b847a92bce0c1318b47932a5b5f65cdd" +checksum = "1cf47565b1430f5fe6c81d3afcb4b835271348d7eb35294a4d592e38dd09ea22" [[package]] name = "minimal-lexical" diff --git a/src/librustdoc/Cargo.toml b/src/librustdoc/Cargo.toml index 70749f7cb17a0..cf5091a68d4c6 100644 --- a/src/librustdoc/Cargo.toml +++ b/src/librustdoc/Cargo.toml @@ -13,7 +13,7 @@ rinja = { version = "0.3", default-features = false, features = ["config"] } base64 = "0.21.7" itertools = "0.12" indexmap = "2" -minifier = { version = "0.3.2", default-features = false } +minifier = { version = "0.3.4", default-features = false } pulldown-cmark-old = { version = "0.9.6", package = "pulldown-cmark", default-features = false } regex = "1" rustdoc-json-types = { path = "../rustdoc-json-types" } From fb52da38088ccc885aaedc02b227dc5ffca15f84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sat, 25 Jan 2025 22:30:38 +0100 Subject: [PATCH 5/6] crashes: more tests --- tests/crashes/135470.rs | 40 +++++++++++++++++++++++++++++++++ tests/crashes/135528.rs | 18 +++++++++++++++ tests/crashes/135570.rs | 12 ++++++++++ tests/crashes/135617.rs | 13 +++++++++++ tests/crashes/135646.rs | 5 +++++ tests/crashes/135668.rs | 38 +++++++++++++++++++++++++++++++ tests/crashes/135718.rs | 50 +++++++++++++++++++++++++++++++++++++++++ tests/crashes/135720.rs | 4 ++++ tests/crashes/135845.rs | 6 +++++ tests/crashes/135863.rs | 10 +++++++++ tests/crashes/136063.rs | 6 +++++ 11 files changed, 202 insertions(+) create mode 100644 tests/crashes/135470.rs create mode 100644 tests/crashes/135528.rs create mode 100644 tests/crashes/135570.rs create mode 100644 tests/crashes/135617.rs create mode 100644 tests/crashes/135646.rs create mode 100644 tests/crashes/135668.rs create mode 100644 tests/crashes/135718.rs create mode 100644 tests/crashes/135720.rs create mode 100644 tests/crashes/135845.rs create mode 100644 tests/crashes/135863.rs create mode 100644 tests/crashes/136063.rs diff --git a/tests/crashes/135470.rs b/tests/crashes/135470.rs new file mode 100644 index 0000000000000..7d357a9317f34 --- /dev/null +++ b/tests/crashes/135470.rs @@ -0,0 +1,40 @@ +//@ known-bug: #135470 +//@ compile-flags: --edition=2021 -Copt-level=0 + +use std::future::Future; +trait Access { + type Lister; + + fn list() -> impl Future { + async { todo!() } + } +} + +trait Foo {} +impl Access for dyn Foo { + type Lister = (); +} + +fn main() { + let svc = async { + async { ::list() }.await; + }; + &svc as &dyn Service; +} + +trait UnaryService { + fn call2() {} +} +trait Unimplemented {} +impl UnaryService for T {} +struct Wrap(T); +impl UnaryService for Wrap {} + +trait Service { + fn call(&self); +} +impl Service for T { + fn call(&self) { + Wrap::::call2(); + } +} diff --git a/tests/crashes/135528.rs b/tests/crashes/135528.rs new file mode 100644 index 0000000000000..a1418f40be6a6 --- /dev/null +++ b/tests/crashes/135528.rs @@ -0,0 +1,18 @@ +//@ known-bug: #135528 +//@ compile-flags: -Zvalidate-mir -Zinline-mir=yes +#![feature(type_alias_impl_trait)] +type Tait = impl Copy; + +fn set(x: &isize) -> isize { + *x +} + +fn d(x: Tait) { + set(x); +} + +fn other_define() -> Tait { + () +} + +fn main() {} diff --git a/tests/crashes/135570.rs b/tests/crashes/135570.rs new file mode 100644 index 0000000000000..a9eda97ef9de7 --- /dev/null +++ b/tests/crashes/135570.rs @@ -0,0 +1,12 @@ +//@ known-bug: #135570 +//@compile-flags: -Zvalidate-mir -Zmir-enable-passes=+Inline -Copt-level=0 -Zmir-enable-passes=+GVN +//@ only-x86_64 + +fn function_with_bytes( +) -> &'static [u8] { + BYTES +} + +fn main() { + function_with_bytes::() == &[]; +} diff --git a/tests/crashes/135617.rs b/tests/crashes/135617.rs new file mode 100644 index 0000000000000..ac524b823a089 --- /dev/null +++ b/tests/crashes/135617.rs @@ -0,0 +1,13 @@ +//@ known-bug: #135617 +trait Project { + const ASSOC: usize; +} + +fn foo() +where + for<'a> (): Project, +{ + [(); <() as Project>::ASSOC]; +} + +pub fn main() {} diff --git a/tests/crashes/135646.rs b/tests/crashes/135646.rs new file mode 100644 index 0000000000000..67b0ad93db4c0 --- /dev/null +++ b/tests/crashes/135646.rs @@ -0,0 +1,5 @@ +//@ known-bug: #135646 +//@ compile-flags: --edition=2024 -Zpolonius=next +fn main() { + &{ [1, 2, 3][4] }; +} diff --git a/tests/crashes/135668.rs b/tests/crashes/135668.rs new file mode 100644 index 0000000000000..8126a65606b27 --- /dev/null +++ b/tests/crashes/135668.rs @@ -0,0 +1,38 @@ +//@ known-bug: #135668 +//@ compile-flags: --edition=2021 +use std::future::Future; + +pub async fn foo() { + let _ = create_task().await; +} + +async fn create_task() -> impl Sized { + bind(documentation) +} + +async fn documentation() { + include_str!("nonexistent"); +} + +fn bind(_filter: F) -> impl Sized +where + F: FilterBase, +{ + || -> ::Assoc { panic!() } +} + +trait FilterBase { + type Assoc; +} + +impl FilterBase for F +where + F: Fn() -> R, + // Removing the below line makes it correctly error on both stable and beta + R: Future, + // Removing the below line makes it ICE on both stable and beta + R: Send, + // Removing the above two bounds makes it ICE on stable but correctly error on beta +{ + type Assoc = F; +} diff --git a/tests/crashes/135718.rs b/tests/crashes/135718.rs new file mode 100644 index 0000000000000..c0e628f4c46c3 --- /dev/null +++ b/tests/crashes/135718.rs @@ -0,0 +1,50 @@ +//@ known-bug: #135718 + +struct Equal; + +struct Bar; + +trait TwiceNested {} +impl TwiceNested for Bar where Bar: NestMakeEqual {} + +struct Sum; + +trait Not { + fn not(); +} + +impl

Not for Sum +where + Bar: NestMakeEqual, + Self: Problem

, +{ + fn not() {} +} + +trait NestMakeEqual { + type NestEq; +} + +trait MakeEqual { + type Eq; +} + +struct Foo; +impl MakeEqual for Foo { + type Eq = Equal; +} + +impl NestMakeEqual for Bar +where + Foo: MakeEqual, +{ + type NestEq = O; +} + +trait Problem {} +impl Problem<()> for Sum where Bar: TwiceNested {} +impl Problem for Sum where Bar: TwiceNested {} + +fn main() { + Sum::not(); +} diff --git a/tests/crashes/135720.rs b/tests/crashes/135720.rs new file mode 100644 index 0000000000000..ee85bc4b66a1a --- /dev/null +++ b/tests/crashes/135720.rs @@ -0,0 +1,4 @@ +//@ known-bug: #135720 +#![feature(generic_const_exprs)] +type S<'l> = [i32; A]; +fn lint_me(x: S<()>) {} diff --git a/tests/crashes/135845.rs b/tests/crashes/135845.rs new file mode 100644 index 0000000000000..ed038d8a1f187 --- /dev/null +++ b/tests/crashes/135845.rs @@ -0,0 +1,6 @@ +//@ known-bug: #135845 +struct S<'a, T: ?Sized>(&'a T); + +fn b<'a>() -> S<'static, _> { + S::<'a>(&0) +} diff --git a/tests/crashes/135863.rs b/tests/crashes/135863.rs new file mode 100644 index 0000000000000..a0ff5988a0db2 --- /dev/null +++ b/tests/crashes/135863.rs @@ -0,0 +1,10 @@ +//@ known-bug: #135863 +struct A; + +impl A { + fn len(self: &&B) {} +} + +fn main() { + A.len() +} diff --git a/tests/crashes/136063.rs b/tests/crashes/136063.rs new file mode 100644 index 0000000000000..078cc59dfa28a --- /dev/null +++ b/tests/crashes/136063.rs @@ -0,0 +1,6 @@ +//@ known-bug: #136063 +#![feature(generic_const_exprs)] +trait A {} +impl A<1> for bool {} +fn bar(arg : &dyn A) { bar(true) } +pub fn main() {} From ace6bb9869747b50d7d4bfaacc65d0592ec94aef Mon Sep 17 00:00:00 2001 From: yukang Date: Sun, 9 Feb 2025 12:20:39 +0800 Subject: [PATCH 6/6] Fix unwrap error in overflowing int literal --- compiler/rustc_lint/src/types.rs | 6 +++++- compiler/rustc_lint/src/types/literal.rs | 5 ++--- tests/ui/lint/lint-overflowing-int-136675.rs | 4 ++++ .../lint/lint-overflowing-int-136675.stderr | 21 +++++++++++++++++++ 4 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 tests/ui/lint/lint-overflowing-int-136675.rs create mode 100644 tests/ui/lint/lint-overflowing-int-136675.stderr diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index 80007f34db356..9cf5d0f460b31 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -543,7 +543,11 @@ impl<'tcx> LateLintPass<'tcx> for TypeLimits { lit: &'tcx hir::Lit, negated: bool, ) { - lint_literal(cx, self, hir_id, lit.span, lit, negated) + if negated { + self.negated_expr_id = Some(hir_id); + self.negated_expr_span = Some(lit.span); + } + lint_literal(cx, self, hir_id, lit.span, lit, negated); } fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx hir::Expr<'tcx>) { diff --git a/compiler/rustc_lint/src/types/literal.rs b/compiler/rustc_lint/src/types/literal.rs index 71e6e229907ac..287344f969368 100644 --- a/compiler/rustc_lint/src/types/literal.rs +++ b/compiler/rustc_lint/src/types/literal.rs @@ -245,12 +245,11 @@ fn lint_int_literal<'tcx>( lit: &hir::Lit, t: ty::IntTy, v: u128, - negated: bool, ) { let int_type = t.normalize(cx.sess().target.pointer_width); let (min, max) = int_ty_range(int_type); let max = max as u128; - let negative = negated ^ (type_limits.negated_expr_id == Some(hir_id)); + let negative = type_limits.negated_expr_id == Some(hir_id); // Detect literal value out of range [min, max] inclusive // avoiding use of -min to prevent overflow/panic @@ -366,7 +365,7 @@ pub(crate) fn lint_literal<'tcx>( ty::Int(t) => { match lit.node { ast::LitKind::Int(v, ast::LitIntType::Signed(_) | ast::LitIntType::Unsuffixed) => { - lint_int_literal(cx, type_limits, hir_id, span, lit, t, v.get(), negated) + lint_int_literal(cx, type_limits, hir_id, span, lit, t, v.get()) } _ => bug!(), }; diff --git a/tests/ui/lint/lint-overflowing-int-136675.rs b/tests/ui/lint/lint-overflowing-int-136675.rs new file mode 100644 index 0000000000000..616531519a62f --- /dev/null +++ b/tests/ui/lint/lint-overflowing-int-136675.rs @@ -0,0 +1,4 @@ +fn main() { + if let -129 = 0i8 {} //~ ERROR literal out of range for `i8` + let x: i8 = -129; //~ ERROR literal out of range for `i8` +} diff --git a/tests/ui/lint/lint-overflowing-int-136675.stderr b/tests/ui/lint/lint-overflowing-int-136675.stderr new file mode 100644 index 0000000000000..3b67c663ac2b7 --- /dev/null +++ b/tests/ui/lint/lint-overflowing-int-136675.stderr @@ -0,0 +1,21 @@ +error: literal out of range for `i8` + --> $DIR/lint-overflowing-int-136675.rs:2:12 + | +LL | if let -129 = 0i8 {} + | ^^^^ + | + = note: the literal `-129` does not fit into the type `i8` whose range is `-128..=127` + = help: consider using the type `i16` instead + = note: `#[deny(overflowing_literals)]` on by default + +error: literal out of range for `i8` + --> $DIR/lint-overflowing-int-136675.rs:3:17 + | +LL | let x: i8 = -129; + | ^^^^ + | + = note: the literal `-129` does not fit into the type `i8` whose range is `-128..=127` + = help: consider using the type `i16` instead + +error: aborting due to 2 previous errors +