Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c82742e

Browse files
committedMar 11, 2024·
Auto merge of rust-lang#122327 - jhpratt:rollup-q311wv9, r=jhpratt
Rollup of 8 pull requests Successful merges: - rust-lang#121148 (Add slice::try_range) - rust-lang#121573 (unix_sigpipe: Add test for SIGPIPE disposition in child processes) - rust-lang#121633 (Win10: Use `GetSystemTimePreciseAsFileTime` directly) - rust-lang#121840 (Expose the Freeze trait again (unstably) and forbid implementing it manually) - rust-lang#121907 (skip sanity check for non-host targets in `check` builds) - rust-lang#122002 (std::threads: revisit stack address calculation on netbsd.) - rust-lang#122108 (Add `target.*.runner` configuration for targets) - rust-lang#122298 (RawVec::into_box: avoid unnecessary intermediate reference) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a6d93ac + c49bdb3 commit c82742e

File tree

40 files changed

+319
-48
lines changed

40 files changed

+319
-48
lines changed
 

‎compiler/rustc_codegen_cranelift/example/mini_core.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
rustc_attrs,
99
transparent_unions,
1010
auto_traits,
11+
freeze_impls,
1112
thread_local
1213
)]
1314
#![no_core]

‎compiler/rustc_codegen_gcc/example/mini_core.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![feature(
22
no_core, lang_items, intrinsics, unboxed_closures, type_ascription, extern_types,
3-
decl_macro, rustc_attrs, transparent_unions, auto_traits,
3+
decl_macro, rustc_attrs, transparent_unions, auto_traits, freeze_impls,
44
thread_local
55
)]
66
#![no_core]

‎compiler/rustc_feature/src/unstable.rs

+2
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,8 @@ declare_features! (
471471
(unstable, fn_align, "1.53.0", Some(82232)),
472472
/// Support delegating implementation of functions to other already implemented functions.
473473
(incomplete, fn_delegation, "1.76.0", Some(118212)),
474+
/// Allows impls for the Freeze trait.
475+
(internal, freeze_impls, "CURRENT_RUSTC_VERSION", Some(121675)),
474476
/// Allows defining gen blocks and `gen fn`.
475477
(unstable, gen_blocks, "1.75.0", Some(117078)),
476478
/// Infer generic args for both consts and types.

‎compiler/rustc_hir_analysis/src/coherence/mod.rs

+14
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_errors::{codes::*, struct_span_code_err};
1010
use rustc_hir::def_id::{DefId, LocalDefId};
1111
use rustc_middle::query::Providers;
1212
use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt};
13+
use rustc_session::parse::feature_err;
1314
use rustc_span::{sym, ErrorGuaranteed};
1415
use rustc_trait_selection::traits;
1516

@@ -49,6 +50,19 @@ fn enforce_trait_manually_implementable(
4950
) -> Result<(), ErrorGuaranteed> {
5051
let impl_header_span = tcx.def_span(impl_def_id);
5152

53+
if tcx.lang_items().freeze_trait() == Some(trait_def_id) {
54+
if !tcx.features().freeze_impls {
55+
feature_err(
56+
&tcx.sess,
57+
sym::freeze_impls,
58+
impl_header_span,
59+
"explicit impls for the `Freeze` trait are not permitted",
60+
)
61+
.with_span_label(impl_header_span, format!("impl of `Freeze` not allowed"))
62+
.emit();
63+
}
64+
}
65+
5266
// Disallow *all* explicit impls of traits marked `#[rustc_deny_explicit_impl]`
5367
if trait_def.deny_explicit_impl {
5468
let trait_name = tcx.item_name(trait_def_id);

‎compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,7 @@ symbols! {
864864
format_placeholder,
865865
format_unsafe_arg,
866866
freeze,
867+
freeze_impls,
867868
freg,
868869
frem_algebraic,
869870
frem_fast,

‎config.example.toml

+11
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,17 @@
842842
# See that option for more info.
843843
#codegen-backends = rust.codegen-backends (array)
844844

845+
# This is a "runner" to pass to `compiletest` when executing tests. Tests will
846+
# execute this tool where the binary-to-test is passed as an argument. Can
847+
# be useful for situations such as when WebAssembly is being tested and a
848+
# runtime needs to be configured. This value is similar to
849+
# Cargo's `CARGO_$target_RUNNER` configuration.
850+
#
851+
# This configuration is a space-separated list of arguments so `foo bar` would
852+
# execute the program `foo` with the first argument as `bar` and the second
853+
# argument as the test binary.
854+
#runner = <none> (string)
855+
845856
# =============================================================================
846857
# Distribution options
847858
#

‎library/alloc/src/raw_vec.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use core::cmp;
55
use core::hint;
66
use core::mem::{self, ManuallyDrop, MaybeUninit, SizedTypeProperties};
77
use core::ptr::{self, NonNull, Unique};
8-
use core::slice;
98

109
#[cfg(not(no_global_oom_handling))]
1110
use crate::alloc::handle_alloc_error;
@@ -192,7 +191,7 @@ impl<T, A: Allocator> RawVec<T, A> {
192191

193192
let me = ManuallyDrop::new(self);
194193
unsafe {
195-
let slice = slice::from_raw_parts_mut(me.ptr() as *mut MaybeUninit<T>, len);
194+
let slice = ptr::slice_from_raw_parts_mut(me.ptr() as *mut MaybeUninit<T>, len);
196195
Box::from_raw_in(slice, ptr::read(&me.alloc))
197196
}
198197
}

‎library/alloc/src/slice.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ use crate::vec::Vec;
3333
#[cfg(test)]
3434
mod tests;
3535

36-
#[unstable(feature = "slice_range", issue = "76393")]
37-
pub use core::slice::range;
3836
#[unstable(feature = "array_chunks", issue = "74985")]
3937
pub use core::slice::ArrayChunks;
4038
#[unstable(feature = "array_chunks", issue = "74985")]
@@ -51,6 +49,8 @@ pub use core::slice::{from_mut, from_ref};
5149
pub use core::slice::{from_mut_ptr_range, from_ptr_range};
5250
#[stable(feature = "rust1", since = "1.0.0")]
5351
pub use core::slice::{from_raw_parts, from_raw_parts_mut};
52+
#[unstable(feature = "slice_range", issue = "76393")]
53+
pub use core::slice::{range, try_range};
5454
#[stable(feature = "slice_group_by", since = "1.77.0")]
5555
pub use core::slice::{ChunkBy, ChunkByMut};
5656
#[stable(feature = "rust1", since = "1.0.0")]

‎library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@
204204
// tidy-alphabetical-start
205205
#![cfg_attr(bootstrap, feature(diagnostic_namespace))]
206206
#![cfg_attr(bootstrap, feature(platform_intrinsics))]
207+
#![cfg_attr(not(bootstrap), feature(freeze_impls))]
207208
#![feature(abi_unadjusted)]
208209
#![feature(adt_const_params)]
209210
#![feature(allow_internal_unsafe)]

‎library/core/src/marker.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -810,15 +810,21 @@ pub trait DiscriminantKind {
810810
type Discriminant: Clone + Copy + Debug + Eq + PartialEq + Hash + Send + Sync + Unpin;
811811
}
812812

813-
/// Compiler-internal trait used to determine whether a type contains
813+
/// Used to determine whether a type contains
814814
/// any `UnsafeCell` internally, but not through an indirection.
815815
/// This affects, for example, whether a `static` of that type is
816816
/// placed in read-only static memory or writable static memory.
817+
/// This can be used to declare that a constant with a generic type
818+
/// will not contain interior mutability, and subsequently allow
819+
/// placing the constant behind references.
817820
#[lang = "freeze"]
818-
pub(crate) unsafe auto trait Freeze {}
821+
#[unstable(feature = "freeze", issue = "121675")]
822+
pub unsafe auto trait Freeze {}
819823

824+
#[unstable(feature = "freeze", issue = "121675")]
820825
impl<T: ?Sized> !Freeze for UnsafeCell<T> {}
821826
marker_impls! {
827+
#[unstable(feature = "freeze", issue = "121675")]
822828
unsafe Freeze for
823829
{T: ?Sized} PhantomData<T>,
824830
{T: ?Sized} *const T,

‎library/core/src/slice/index.rs

+55-4
Original file line numberDiff line numberDiff line change
@@ -704,17 +704,15 @@ where
704704
{
705705
let len = bounds.end;
706706

707-
let start: ops::Bound<&usize> = range.start_bound();
708-
let start = match start {
707+
let start = match range.start_bound() {
709708
ops::Bound::Included(&start) => start,
710709
ops::Bound::Excluded(start) => {
711710
start.checked_add(1).unwrap_or_else(|| slice_start_index_overflow_fail())
712711
}
713712
ops::Bound::Unbounded => 0,
714713
};
715714

716-
let end: ops::Bound<&usize> = range.end_bound();
717-
let end = match end {
715+
let end = match range.end_bound() {
718716
ops::Bound::Included(end) => {
719717
end.checked_add(1).unwrap_or_else(|| slice_end_index_overflow_fail())
720718
}
@@ -732,6 +730,59 @@ where
732730
ops::Range { start, end }
733731
}
734732

733+
/// Performs bounds-checking of a range without panicking.
734+
///
735+
/// This is a version of [`range`] that returns [`None`] instead of panicking.
736+
///
737+
/// # Examples
738+
///
739+
/// ```
740+
/// #![feature(slice_range)]
741+
///
742+
/// use std::slice;
743+
///
744+
/// let v = [10, 40, 30];
745+
/// assert_eq!(Some(1..2), slice::try_range(1..2, ..v.len()));
746+
/// assert_eq!(Some(0..2), slice::try_range(..2, ..v.len()));
747+
/// assert_eq!(Some(1..3), slice::try_range(1.., ..v.len()));
748+
/// ```
749+
///
750+
/// Returns [`None`] when [`Index::index`] would panic:
751+
///
752+
/// ```
753+
/// #![feature(slice_range)]
754+
///
755+
/// use std::slice;
756+
///
757+
/// assert_eq!(None, slice::try_range(2..1, ..3));
758+
/// assert_eq!(None, slice::try_range(1..4, ..3));
759+
/// assert_eq!(None, slice::try_range(1..=usize::MAX, ..3));
760+
/// ```
761+
///
762+
/// [`Index::index`]: ops::Index::index
763+
#[unstable(feature = "slice_range", issue = "76393")]
764+
#[must_use]
765+
pub fn try_range<R>(range: R, bounds: ops::RangeTo<usize>) -> Option<ops::Range<usize>>
766+
where
767+
R: ops::RangeBounds<usize>,
768+
{
769+
let len = bounds.end;
770+
771+
let start = match range.start_bound() {
772+
ops::Bound::Included(&start) => start,
773+
ops::Bound::Excluded(start) => start.checked_add(1)?,
774+
ops::Bound::Unbounded => 0,
775+
};
776+
777+
let end = match range.end_bound() {
778+
ops::Bound::Included(end) => end.checked_add(1)?,
779+
ops::Bound::Excluded(&end) => end,
780+
ops::Bound::Unbounded => len,
781+
};
782+
783+
if start > end || end > len { None } else { Some(ops::Range { start, end }) }
784+
}
785+
735786
/// Convert pair of `ops::Bound`s into `ops::Range` without performing any bounds checking and (in debug) overflow checking
736787
pub(crate) fn into_range_unchecked(
737788
len: usize,

‎library/core/src/slice/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub use sort::heapsort;
9191
pub use index::SliceIndex;
9292

9393
#[unstable(feature = "slice_range", issue = "76393")]
94-
pub use index::range;
94+
pub use index::{range, try_range};
9595

9696
#[stable(feature = "inherent_ascii_escape", since = "1.60.0")]
9797
pub use ascii::EscapeAscii;

‎library/std/src/sys/pal/unix/thread.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -806,9 +806,9 @@ pub mod guard {
806806
#[cfg(any(
807807
target_os = "android",
808808
target_os = "freebsd",
809+
target_os = "netbsd",
809810
target_os = "hurd",
810811
target_os = "linux",
811-
target_os = "netbsd",
812812
target_os = "l4re"
813813
))]
814814
unsafe fn get_stack_start() -> Option<*mut libc::c_void> {
@@ -911,9 +911,10 @@ pub mod guard {
911911
}
912912
}) * page_size;
913913
Some(guard)
914-
} else if cfg!(target_os = "openbsd") {
914+
} else if cfg!(any(target_os = "openbsd", target_os = "netbsd")) {
915915
// OpenBSD stack already includes a guard page, and stack is
916916
// immutable.
917+
// NetBSD stack includes the guard page.
917918
//
918919
// We'll just note where we expect rlimit to start
919920
// faulting, so our handler can report "stack overflow", and

‎library/std/src/sys/pal/windows/c.rs

+1
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ compat_fn_with_fallback! {
344344

345345
// >= Win8 / Server 2012
346346
// https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getsystemtimepreciseasfiletime
347+
#[cfg(target_vendor = "win7")]
347348
pub fn GetSystemTimePreciseAsFileTime(lpsystemtimeasfiletime: *mut FILETIME) -> () {
348349
GetSystemTimeAsFileTime(lpsystemtimeasfiletime)
349350
}

‎library/std/src/sys/pal/windows/c/bindings.txt

+1
Original file line numberDiff line numberDiff line change
@@ -2476,6 +2476,7 @@ Windows.Win32.System.Pipes.PIPE_WAIT
24762476
Windows.Win32.System.SystemInformation.GetSystemDirectoryW
24772477
Windows.Win32.System.SystemInformation.GetSystemInfo
24782478
Windows.Win32.System.SystemInformation.GetSystemTimeAsFileTime
2479+
Windows.Win32.System.SystemInformation.GetSystemTimePreciseAsFileTime
24792480
Windows.Win32.System.SystemInformation.GetWindowsDirectoryW
24802481
Windows.Win32.System.SystemInformation.PROCESSOR_ARCHITECTURE
24812482
Windows.Win32.System.SystemInformation.SYSTEM_INFO

‎library/std/src/sys/pal/windows/c/windows_sys.rs

+4
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,10 @@ extern "system" {
345345
pub fn GetSystemTimeAsFileTime(lpsystemtimeasfiletime: *mut FILETIME) -> ();
346346
}
347347
#[link(name = "kernel32")]
348+
extern "system" {
349+
pub fn GetSystemTimePreciseAsFileTime(lpsystemtimeasfiletime: *mut FILETIME) -> ();
350+
}
351+
#[link(name = "kernel32")]
348352
extern "system" {
349353
pub fn GetTempPathW(nbufferlength: u32, lpbuffer: PWSTR) -> u32;
350354
}

‎src/bootstrap/src/core/build_steps/test.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1971,6 +1971,8 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
19711971

19721972
if builder.remote_tested(target) {
19731973
cmd.arg("--remote-test-client").arg(builder.tool_exe(Tool::RemoteTestClient));
1974+
} else if let Some(tool) = builder.runner(target) {
1975+
cmd.arg("--runner").arg(tool);
19741976
}
19751977

19761978
if suite != "mir-opt" {
@@ -2523,6 +2525,8 @@ fn prepare_cargo_test(
25232525
format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)),
25242526
format!("{} run 0", builder.tool_exe(Tool::RemoteTestClient).display()),
25252527
);
2528+
} else if let Some(tool) = builder.runner(target) {
2529+
cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)), tool);
25262530
}
25272531

25282532
cargo

‎src/bootstrap/src/core/config/config.rs

+3
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ pub struct Target {
581581
pub musl_libdir: Option<PathBuf>,
582582
pub wasi_root: Option<PathBuf>,
583583
pub qemu_rootfs: Option<PathBuf>,
584+
pub runner: Option<String>,
584585
pub no_std: bool,
585586
pub codegen_backends: Option<Vec<String>>,
586587
}
@@ -1144,6 +1145,7 @@ define_config! {
11441145
qemu_rootfs: Option<String> = "qemu-rootfs",
11451146
no_std: Option<bool> = "no-std",
11461147
codegen_backends: Option<Vec<String>> = "codegen-backends",
1148+
runner: Option<String> = "runner",
11471149
}
11481150
}
11491151

@@ -1864,6 +1866,7 @@ impl Config {
18641866
target.musl_libdir = cfg.musl_libdir.map(PathBuf::from);
18651867
target.wasi_root = cfg.wasi_root.map(PathBuf::from);
18661868
target.qemu_rootfs = cfg.qemu_rootfs.map(PathBuf::from);
1869+
target.runner = cfg.runner;
18671870
target.sanitizers = cfg.sanitizers;
18681871
target.profiler = cfg.profiler;
18691872
target.rpath = cfg.rpath;

‎src/bootstrap/src/core/sanity.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use std::fs;
1515
use std::path::PathBuf;
1616
use std::process::Command;
1717

18+
use crate::builder::Kind;
1819
use crate::core::config::Target;
1920
use crate::utils::helpers::output;
2021
use crate::Build;
@@ -64,6 +65,8 @@ pub fn check(build: &mut Build) {
6465
let mut skip_target_sanity =
6566
env::var_os("BOOTSTRAP_SKIP_TARGET_SANITY").is_some_and(|s| s == "1" || s == "true");
6667

68+
skip_target_sanity |= build.config.cmd.kind() == Kind::Check;
69+
6770
// Skip target sanity checks when we are doing anything with mir-opt tests or Miri
6871
let skipped_paths = [OsStr::new("mir-opt"), OsStr::new("miri")];
6972
skip_target_sanity |= build.config.paths.iter().any(|path| {
@@ -169,11 +172,8 @@ than building it.
169172
continue;
170173
}
171174

172-
// Some environments don't want or need these tools, such as when testing Miri.
173-
// FIXME: it would be better to refactor this code to split necessary setup from pure sanity
174-
// checks, and have a regular flag for skipping the latter. Also see
175-
// <https://github.com/rust-lang/rust/pull/103569#discussion_r1008741742>.
176-
if skip_target_sanity {
175+
// skip check for cross-targets
176+
if skip_target_sanity && target != &build.build {
177177
continue;
178178
}
179179

@@ -215,11 +215,8 @@ than building it.
215215
panic!("All the *-none-* and nvptx* targets are no-std targets")
216216
}
217217

218-
// Some environments don't want or need these tools, such as when testing Miri.
219-
// FIXME: it would be better to refactor this code to split necessary setup from pure sanity
220-
// checks, and have a regular flag for skipping the latter. Also see
221-
// <https://github.com/rust-lang/rust/pull/103569#discussion_r1008741742>.
222-
if skip_target_sanity {
218+
// skip check for cross-targets
219+
if skip_target_sanity && target != &build.build {
223220
continue;
224221
}
225222

‎src/bootstrap/src/lib.rs

+11
Original file line numberDiff line numberDiff line change
@@ -1354,6 +1354,17 @@ impl Build {
13541354
|| env::var_os("TEST_DEVICE_ADDR").is_some()
13551355
}
13561356

1357+
/// Returns an optional "runner" to pass to `compiletest` when executing
1358+
/// test binaries.
1359+
///
1360+
/// An example of this would be a WebAssembly runtime when testing the wasm
1361+
/// targets.
1362+
fn runner(&self, target: TargetSelection) -> Option<String> {
1363+
let target = self.config.target_config.get(&target)?;
1364+
let runner = target.runner.as_ref()?;
1365+
Some(runner.to_owned())
1366+
}
1367+
13571368
/// Returns the root of the "rootfs" image that this target will be using,
13581369
/// if one was configured.
13591370
///

‎src/bootstrap/src/utils/change_tracker.rs

+5
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
141141
severity: ChangeSeverity::Info,
142142
summary: "A new `boostrap-cache-path` option has been introduced which can be utilized to modify the cache path for bootstrap.",
143143
},
144+
ChangeInfo {
145+
change_id: 122108,
146+
severity: ChangeSeverity::Info,
147+
summary: "a new `target.*.runner` option is available to specify a wrapper executable required to run tests for a target",
148+
},
144149
];

0 commit comments

Comments
 (0)
Please sign in to comment.