Skip to content

Commit

Permalink
Auto merge of rust-lang#135113 - workingjubilee:rollup-yy6nxel, r=wor…
Browse files Browse the repository at this point in the history
…kingjubilee

Rollup of 4 pull requests

Successful merges:

 - rust-lang#134925 (deny usage of special FileCheck prefixes as revision names)
 - rust-lang#134996 (Add UWP (msvc) target support page)
 - rust-lang#135104 (do not in-place-iterate over flatmap/flatten)
 - rust-lang#135110 (library: fix adler{ -> 2}.debug)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Jan 5, 2025
2 parents 3dc3c52 + bfd7ac1 commit 8417f83
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 59 deletions.
2 changes: 1 addition & 1 deletion library/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ codegen-units = 10000
[profile.release.package]
addr2line.debug = 0
addr2line.opt-level = "s"
adler.debug = 0
adler2.debug = 0
gimli.debug = 0
gimli.opt-level = "s"
miniz_oxide.debug = 0
Expand Down
39 changes: 20 additions & 19 deletions library/alloc/tests/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1204,22 +1204,16 @@ fn test_from_iter_specialization_with_iterator_adapters() {
#[test]
fn test_in_place_specialization_step_up_down() {
fn assert_in_place_trait<T: InPlaceIterable>(_: &T) {}
let src = vec![[0u8; 4]; 256];
let srcptr = src.as_ptr();
let src_cap = src.capacity();
let iter = src.into_iter().flatten();
assert_in_place_trait(&iter);
let sink = iter.collect::<Vec<_>>();
let sinkptr = sink.as_ptr();
assert_eq!(srcptr as *const u8, sinkptr);
assert_eq!(src_cap * 4, sink.capacity());

let iter = sink.into_iter().array_chunks::<4>();
let src = vec![0u8; 1024];
let srcptr = src.as_ptr();
let src_bytes = src.capacity();
let iter = src.into_iter().array_chunks::<4>();
assert_in_place_trait(&iter);
let sink = iter.collect::<Vec<_>>();
let sinkptr = sink.as_ptr();
assert_eq!(srcptr, sinkptr);
assert_eq!(src_cap, sink.capacity());
assert_eq!(srcptr.addr(), sinkptr.addr());
assert_eq!(src_bytes, sink.capacity() * 4);

let mut src: Vec<u8> = Vec::with_capacity(17);
let src_bytes = src.capacity();
Expand All @@ -1236,13 +1230,6 @@ fn test_in_place_specialization_step_up_down() {
let sink: Vec<[u8; 2]> = iter.collect();
assert_eq!(sink.len(), 8);
assert!(sink.capacity() <= 25);

let src = vec![[0u8; 4]; 256];
let srcptr = src.as_ptr();
let iter = src.into_iter().flat_map(|a| a.into_iter().map(|b| b.wrapping_add(1)));
assert_in_place_trait(&iter);
let sink = iter.collect::<Vec<_>>();
assert_eq!(srcptr as *const u8, sink.as_ptr());
}

#[test]
Expand Down Expand Up @@ -1350,6 +1337,20 @@ fn test_collect_after_iterator_clone() {
assert_eq!(v, [1, 1, 1, 1, 1]);
assert!(v.len() <= v.capacity());
}

// regression test for #135103, similar to the one above Flatten/FlatMap had an unsound InPlaceIterable
// implementation.
#[test]
fn test_flatten_clone() {
const S: String = String::new();

let v = vec![[S, "Hello World!".into()], [S, S]];
let mut i = v.into_iter().flatten();
let _ = i.next();
let result: Vec<String> = i.clone().collect();
assert_eq!(result, ["Hello World!", "", ""]);
}

#[test]
fn test_cow_from() {
let borrowed: &[_] = &["borrowed", "(slice)"];
Expand Down
34 changes: 2 additions & 32 deletions library/core/src/iter/adapters/flatten.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::iter::adapters::SourceIter;
use crate::iter::{
Cloned, Copied, Empty, Filter, FilterMap, Fuse, FusedIterator, InPlaceIterable, Map, Once,
OnceWith, TrustedFused, TrustedLen,
Cloned, Copied, Empty, Filter, FilterMap, Fuse, FusedIterator, Map, Once, OnceWith,
TrustedFused, TrustedLen,
};
use crate::num::NonZero;
use crate::ops::{ControlFlow, Try};
Expand Down Expand Up @@ -157,21 +157,6 @@ where
{
}

#[unstable(issue = "none", feature = "inplace_iteration")]
unsafe impl<I, U, F> InPlaceIterable for FlatMap<I, U, F>
where
I: InPlaceIterable,
U: BoundedSize + IntoIterator,
{
const EXPAND_BY: Option<NonZero<usize>> = const {
match (I::EXPAND_BY, U::UPPER_BOUND) {
(Some(m), Some(n)) => m.checked_mul(n),
_ => None,
}
};
const MERGE_BY: Option<NonZero<usize>> = I::MERGE_BY;
}

#[unstable(issue = "none", feature = "inplace_iteration")]
unsafe impl<I, U, F> SourceIter for FlatMap<I, U, F>
where
Expand Down Expand Up @@ -386,21 +371,6 @@ where
{
}

#[unstable(issue = "none", feature = "inplace_iteration")]
unsafe impl<I> InPlaceIterable for Flatten<I>
where
I: InPlaceIterable + Iterator,
<I as Iterator>::Item: IntoIterator + BoundedSize,
{
const EXPAND_BY: Option<NonZero<usize>> = const {
match (I::EXPAND_BY, I::Item::UPPER_BOUND) {
(Some(m), Some(n)) => m.checked_mul(n),
_ => None,
}
};
const MERGE_BY: Option<NonZero<usize>> = I::MERGE_BY;
}

#[unstable(issue = "none", feature = "inplace_iteration")]
unsafe impl<I> SourceIter for Flatten<I>
where
Expand Down
5 changes: 3 additions & 2 deletions library/std/src/sys/pal/windows/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
#[cfg(test)]
mod tests;

use super::api::{self, WinError};
use super::to_u16s;
#[cfg(not(target_vendor = "uwp"))]
use super::api::WinError;
use super::{api, to_u16s};
use crate::error::Error as StdError;
use crate::ffi::{OsStr, OsString};
use crate::os::windows::ffi::EncodeWide;
Expand Down
1 change: 1 addition & 0 deletions src/doc/rustc/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
- [*-unknown-openbsd](platform-support/openbsd.md)
- [*-unknown-redox](platform-support/redox.md)
- [\*-unknown-uefi](platform-support/unknown-uefi.md)
- [\*-uwp-windows-msvc](platform-support/uwp-windows-msvc.md)
- [\*-wrs-vxworks](platform-support/vxworks.md)
- [wasm32-wasip1](platform-support/wasm32-wasip1.md)
- [wasm32-wasip1-threads](platform-support/wasm32-wasip1-threads.md)
Expand Down
10 changes: 5 additions & 5 deletions src/doc/rustc/src/platform-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ target | std | host | notes
[`aarch64-unknown-redox`](platform-support/redox.md) | ✓ | | ARM64 Redox OS
[`aarch64-unknown-teeos`](platform-support/aarch64-unknown-teeos.md) | ? | | ARM64 TEEOS |
[`aarch64-unknown-trusty`](platform-support/trusty.md) | ? | |
`aarch64-uwp-windows-msvc` | ✓ | |
[`aarch64-uwp-windows-msvc`](platform-support/uwp-windows-msvc.md) | ✓ | |
[`aarch64-wrs-vxworks`](platform-support/vxworks.md) | ✓ | | ARM64 VxWorks OS
`aarch64_be-unknown-linux-gnu` | ✓ | ✓ | ARM64 Linux (big-endian)
`aarch64_be-unknown-linux-gnu_ilp32` | ✓ | ✓ | ARM64 Linux (big-endian, ILP32 ABI)
Expand Down Expand Up @@ -312,7 +312,7 @@ target | std | host | notes
[`i686-unknown-openbsd`](platform-support/openbsd.md) | ✓ | ✓ | 32-bit OpenBSD [^x86_32-floats-return-ABI]
[`i686-unknown-redox`](platform-support/redox.md) | ✓ | | i686 Redox OS
`i686-uwp-windows-gnu` | ✓ | | [^x86_32-floats-return-ABI]
`i686-uwp-windows-msvc` | ✓ | | [^x86_32-floats-return-ABI]
[`i686-uwp-windows-msvc`](platform-support/uwp-windows-msvc.md) | ✓ | | [^x86_32-floats-return-ABI]
[`i686-win7-windows-msvc`](platform-support/win7-windows-msvc.md) | ✓ | | 32-bit Windows 7 support [^x86_32-floats-return-ABI]
[`i686-wrs-vxworks`](platform-support/vxworks.md) | ✓ | | [^x86_32-floats-return-ABI]
[`loongarch64-unknown-linux-ohos`](platform-support/openharmony.md) | ✓ | | LoongArch64 OpenHarmony
Expand Down Expand Up @@ -383,8 +383,8 @@ target | std | host | notes
[`thumbv4t-none-eabi`](platform-support/armv4t-none-eabi.md) | * | | Thumb-mode Bare Armv4T
[`thumbv5te-none-eabi`](platform-support/armv5te-none-eabi.md) | * | | Thumb-mode Bare Armv5TE
[`thumbv6m-nuttx-eabi`](platform-support/nuttx.md) | * | | ARMv6M with NuttX
`thumbv7a-pc-windows-msvc` | | |
`thumbv7a-uwp-windows-msvc` | | |
`thumbv7a-pc-windows-msvc` | | |
[`thumbv7a-uwp-windows-msvc`](platform-support/uwp-windows-msvc.md) | | |
[`thumbv7em-nuttx-eabi`](platform-support/nuttx.md) | * | | ARMv7EM with NuttX
[`thumbv7em-nuttx-eabihf`](platform-support/nuttx.md) | * | | ARMv7EM with NuttX, hardfloat
[`thumbv7m-nuttx-eabi`](platform-support/nuttx.md) | * | | ARMv7M with NuttX
Expand All @@ -406,7 +406,7 @@ target | std | host | notes
[`x86_64-unknown-openbsd`](platform-support/openbsd.md) | ✓ | ✓ | 64-bit OpenBSD
[`x86_64-unknown-trusty`](platform-support/trusty.md) | ? | |
`x86_64-uwp-windows-gnu` | ✓ | |
`x86_64-uwp-windows-msvc` | ✓ | |
[`x86_64-uwp-windows-msvc`](platform-support/uwp-windows-msvc.md) | ✓ | |
[`x86_64-win7-windows-msvc`](platform-support/win7-windows-msvc.md) | ✓ | | 64-bit Windows 7 support
[`x86_64-wrs-vxworks`](platform-support/vxworks.md) | ✓ | |
[`x86_64h-apple-darwin`](platform-support/x86_64h-apple-darwin.md) | ✓ | ✓ | macOS with late-gen Intel (at least Haswell)
Expand Down
52 changes: 52 additions & 0 deletions src/doc/rustc/src/platform-support/uwp-windows-msvc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# `x86_64-uwp-windows-msvc`, `i686-uwp-windows-msvc`, `thumbv7a-uwp-windows-msvc` and `aarch64-uwp-windows-msvc`

**Tier: 3**

Windows targets for Universal Windows Platform (UWP) applications, using MSVC toolchain.

## Target maintainers

- [@bdbai](https://github.com/bdbai)

## Requirements

These targets are cross-compiled with std support. The host requirement and
binary format are the same as the corresponding non-UWP targets (i.e.
`x86_64-pc-windows-msvc`, `i686-pc-windows-msvc`, `thumbv7a-pc-windows-msvc`
and `aarch64-pc-windows-msvc`).

## Building the targets

The targets can be built by enabling them for a `rustc` build, for example:

```toml
[build]
build-stage = 1
target = ["x86_64-uwp-windows-msvc", "aarch64-uwp-windows-msvc"]
```

## Building Rust programs

Rust does not yet ship pre-compiled artifacts for these targets. To compile for
these targets, you will either need to build Rust with the targets enabled (see
"Building the targets" above), or build your own copy of `std` by using
`build-std` or similar.

Example of building a Rust project for x64 UWP using `build-std`:

```pwsh
cargo build -Z build-std=std,panic_abort --target x86_64-uwp-windows-msvc
```

## Testing

Currently there is no support to run the rustc test suite for this target.

## Cross-compilation toolchains and C code

In general, the toolchain target should match the corresponding non-UWP
targets. Beware that not all Win32 APIs behave the same way in UWP, and some
are restricted in [AppContainer](https://learn.microsoft.com/en-us/windows/win32/secauthz/appcontainer-for-legacy-applications-)
or even not available at all. If the C code being compiled happens to use any
of restricted or unavailable APIs, consider using allowed alternatives or
disable certain feature sets to avoid using them.
12 changes: 12 additions & 0 deletions src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,9 @@ fn iter_header(

impl Config {
fn parse_and_update_revisions(&self, testfile: &Path, line: &str, existing: &mut Vec<String>) {
const FORBIDDEN_REVISION_NAMES: [&str; 9] =
["CHECK", "COM", "NEXT", "SAME", "EMPTY", "NOT", "COUNT", "DAG", "LABEL"];

if let Some(raw) = self.parse_name_value_directive(line, "revisions") {
if self.mode == Mode::RunMake {
panic!("`run-make` tests do not support revisions: {}", testfile.display());
Expand All @@ -948,6 +951,15 @@ impl Config {
raw,
testfile.display()
);
} else if matches!(self.mode, Mode::Assembly | Mode::Codegen | Mode::MirOpt)
&& FORBIDDEN_REVISION_NAMES.contains(&revision.as_str())
{
panic!(
"revision name `{revision}` is not permitted in a test suite that uses `FileCheck` annotations\n\
as it is confusing when used as custom `FileCheck` prefix: `{revision}` in line `{}`: {}",
raw,
testfile.display()
);
}
existing.push(revision);
}
Expand Down
53 changes: 53 additions & 0 deletions src/tools/compiletest/src/header/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,59 @@ fn test_duplicate_revisions() {
parse_rs(&config, "//@ revisions: rpass1 rpass1");
}

#[test]
#[should_panic(
expected = "revision name `CHECK` is not permitted in a test suite that uses `FileCheck` annotations"
)]
fn test_assembly_mode_forbidden_revisions() {
let config = cfg().mode("assembly").build();
parse_rs(&config, "//@ revisions: CHECK");
}

#[test]
#[should_panic(
expected = "revision name `CHECK` is not permitted in a test suite that uses `FileCheck` annotations"
)]
fn test_codegen_mode_forbidden_revisions() {
let config = cfg().mode("codegen").build();
parse_rs(&config, "//@ revisions: CHECK");
}

#[test]
#[should_panic(
expected = "revision name `CHECK` is not permitted in a test suite that uses `FileCheck` annotations"
)]
fn test_miropt_mode_forbidden_revisions() {
let config = cfg().mode("mir-opt").build();
parse_rs(&config, "//@ revisions: CHECK");
}

#[test]
fn test_forbidden_revisions_allowed_in_non_filecheck_dir() {
let revisions = ["CHECK", "COM", "NEXT", "SAME", "EMPTY", "NOT", "COUNT", "DAG", "LABEL"];
let modes = [
"pretty",
"debuginfo",
"rustdoc",
"rustdoc-json",
"codegen-units",
"incremental",
"ui",
"js-doc-test",
"coverage-map",
"coverage-run",
"crashes",
];

for rev in revisions {
let content = format!("//@ revisions: {rev}");
for mode in modes {
let config = cfg().mode(mode).build();
parse_rs(&config, &content);
}
}
}

#[test]
fn ignore_arch() {
let archs = [
Expand Down

0 comments on commit 8417f83

Please sign in to comment.