Skip to content

Commit 1d6754d

Browse files
committed
Auto merge of rust-lang#83199 - JohnTitor:rollup-zrfk94a, r=JohnTitor
Rollup of 10 pull requests Successful merges: - rust-lang#81822 (Added `try_exists()` method to `std::path::Path`) - rust-lang#83072 (Update `Vec` docs) - rust-lang#83077 (rustdoc: reduce GC work during search) - rust-lang#83091 (Constify `copy` related functions) - rust-lang#83156 (Fall-back to sans-serif if Arial is not available) - rust-lang#83157 (No background for code in portability snippets) - rust-lang#83160 (Deprecate RustcEncodable and RustcDecodable.) - rust-lang#83162 (Specify *.woff2 files as binary) - rust-lang#83172 (More informative diagnotic from `x.py test` attempt atop beta checkout) - rust-lang#83196 (Use delay_span_bug instead of panic in layout_scalar_valid_range) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents f24ce9b + ec07427 commit 1d6754d

File tree

21 files changed

+196
-110
lines changed

21 files changed

+196
-110
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*.mir linguist-language=Rust
99
src/etc/installer/gfx/* binary
1010
*.woff binary
11+
*.woff2 binary
1112
src/vendor/** -text
1213
Cargo.lock linguist-generated=false
1314

compiler/rustc_middle/src/ty/context.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -1091,13 +1091,16 @@ impl<'tcx> TyCtxt<'tcx> {
10911091
None => return Bound::Unbounded,
10921092
};
10931093
debug!("layout_scalar_valid_range: attr={:?}", attr);
1094-
for meta in attr.meta_item_list().expect("rustc_layout_scalar_valid_range takes args") {
1095-
match meta.literal().expect("attribute takes lit").kind {
1096-
ast::LitKind::Int(a, _) => return Bound::Included(a),
1097-
_ => span_bug!(attr.span, "rustc_layout_scalar_valid_range expects int arg"),
1098-
}
1094+
if let Some(
1095+
&[ast::NestedMetaItem::Literal(ast::Lit { kind: ast::LitKind::Int(a, _), .. })],
1096+
) = attr.meta_item_list().as_deref()
1097+
{
1098+
Bound::Included(a)
1099+
} else {
1100+
self.sess
1101+
.delay_span_bug(attr.span, "invalid rustc_layout_scalar_valid_range attribute");
1102+
Bound::Unbounded
10991103
}
1100-
span_bug!(attr.span, "no arguments to `rustc_layout_scalar_valid_range` attribute");
11011104
};
11021105
(
11031106
get(sym::rustc_layout_scalar_valid_range_start),

library/alloc/src/vec/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ use self::spec_extend::SpecExtend;
126126

127127
mod spec_extend;
128128

129-
/// A contiguous growable array type, written `Vec<T>` but pronounced 'vector'.
129+
/// A contiguous growable array type, written as `Vec<T>` and pronounced 'vector'.
130130
///
131131
/// # Examples
132132
///
@@ -215,7 +215,7 @@ mod spec_extend;
215215
///
216216
/// # Slicing
217217
///
218-
/// A `Vec` can be mutable. Slices, on the other hand, are read-only objects.
218+
/// A `Vec` can be mutable. On the other hand, slices are read-only objects.
219219
/// To get a [slice][prim@slice], use [`&`]. Example:
220220
///
221221
/// ```
@@ -352,7 +352,7 @@ mod spec_extend;
352352
/// not break, however: using `unsafe` code to write to the excess capacity,
353353
/// and then increasing the length to match, is always valid.
354354
///
355-
/// `Vec` does not currently guarantee the order in which elements are dropped.
355+
/// Currently, `Vec` does not guarantee the order in which elements are dropped.
356356
/// The order has changed in the past and may change again.
357357
///
358358
/// [`get`]: ../../std/vec/struct.Vec.html#method.get

library/core/src/intrinsics.rs

-12
Original file line numberDiff line numberDiff line change
@@ -1902,18 +1902,6 @@ pub(crate) fn is_aligned_and_not_null<T>(ptr: *const T) -> bool {
19021902
!ptr.is_null() && ptr as usize % mem::align_of::<T>() == 0
19031903
}
19041904

1905-
/// Checks whether the regions of memory starting at `src` and `dst` of size
1906-
/// `count * size_of::<T>()` do *not* overlap.
1907-
pub(crate) fn is_nonoverlapping<T>(src: *const T, dst: *const T, count: usize) -> bool {
1908-
let src_usize = src as usize;
1909-
let dst_usize = dst as usize;
1910-
let size = mem::size_of::<T>().checked_mul(count).unwrap();
1911-
let diff = if src_usize > dst_usize { src_usize - dst_usize } else { dst_usize - src_usize };
1912-
// If the absolute distance between the ptrs is at least as big as the size of the buffer,
1913-
// they do not overlap.
1914-
diff >= size
1915-
}
1916-
19171905
/// Sets `count * size_of::<T>()` bytes of memory starting at `dst` to
19181906
/// `val`.
19191907
///

library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
#![feature(const_slice_from_raw_parts)]
9999
#![feature(const_slice_ptr_len)]
100100
#![feature(const_size_of_val)]
101+
#![feature(const_swap)]
101102
#![feature(const_align_of_val)]
102103
#![feature(const_type_id)]
103104
#![feature(const_type_name)]

library/core/src/macros/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1468,6 +1468,10 @@ pub(crate) mod builtin {
14681468
#[rustc_builtin_macro]
14691469
#[stable(feature = "rust1", since = "1.0.0")]
14701470
#[allow_internal_unstable(core_intrinsics, libstd_sys_internals)]
1471+
#[rustc_deprecated(
1472+
since = "1.52.0",
1473+
reason = "rustc-serialize is deprecated and no longer supported"
1474+
)]
14711475
pub macro RustcDecodable($item:item) {
14721476
/* compiler built-in */
14731477
}
@@ -1476,6 +1480,10 @@ pub(crate) mod builtin {
14761480
#[rustc_builtin_macro]
14771481
#[stable(feature = "rust1", since = "1.0.0")]
14781482
#[allow_internal_unstable(core_intrinsics)]
1483+
#[rustc_deprecated(
1484+
since = "1.52.0",
1485+
reason = "rustc-serialize is deprecated and no longer supported"
1486+
)]
14791487
pub macro RustcEncodable($item:item) {
14801488
/* compiler built-in */
14811489
}

library/core/src/mem/mod.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,8 @@ pub unsafe fn uninitialized<T>() -> T {
682682
/// ```
683683
#[inline]
684684
#[stable(feature = "rust1", since = "1.0.0")]
685-
pub fn swap<T>(x: &mut T, y: &mut T) {
685+
#[rustc_const_unstable(feature = "const_swap", issue = "83163")]
686+
pub const fn swap<T>(x: &mut T, y: &mut T) {
686687
// SAFETY: the raw pointers have been created from safe mutable references satisfying all the
687688
// constraints on `ptr::swap_nonoverlapping_one`
688689
unsafe {
@@ -812,7 +813,8 @@ pub fn take<T: Default>(dest: &mut T) -> T {
812813
#[inline]
813814
#[stable(feature = "rust1", since = "1.0.0")]
814815
#[must_use = "if you don't need the old value, you can just assign the new value directly"]
815-
pub fn replace<T>(dest: &mut T, src: T) -> T {
816+
#[rustc_const_unstable(feature = "const_replace", issue = "83164")]
817+
pub const fn replace<T>(dest: &mut T, src: T) -> T {
816818
// SAFETY: We read from `dest` but directly write `src` into it afterwards,
817819
// such that the old value is not duplicated. Nothing is dropped and
818820
// nothing here can panic.
@@ -931,7 +933,8 @@ pub fn drop<T>(_x: T) {}
931933
/// ```
932934
#[inline]
933935
#[stable(feature = "rust1", since = "1.0.0")]
934-
pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
936+
#[rustc_const_unstable(feature = "const_transmute_copy", issue = "83165")]
937+
pub const unsafe fn transmute_copy<T, U>(src: &T) -> U {
935938
// If U has a higher alignment requirement, src may not be suitably aligned.
936939
if align_of::<U>() > align_of::<T>() {
937940
// SAFETY: `src` is a reference which is guaranteed to be valid for reads.

library/core/src/prelude/v1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub use crate::{
6161
};
6262

6363
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
64-
#[allow(deprecated)]
64+
#[allow(deprecated, deprecated_in_future)]
6565
#[doc(no_inline)]
6666
pub use crate::macros::builtin::{
6767
bench, global_allocator, test, test_case, RustcDecodable, RustcEncodable,

library/core/src/ptr/const_ptr.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -819,9 +819,10 @@ impl<T: ?Sized> *const T {
819819
/// See [`ptr::copy`] for safety concerns and examples.
820820
///
821821
/// [`ptr::copy`]: crate::ptr::copy()
822+
#[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")]
822823
#[stable(feature = "pointer_methods", since = "1.26.0")]
823824
#[inline]
824-
pub unsafe fn copy_to(self, dest: *mut T, count: usize)
825+
pub const unsafe fn copy_to(self, dest: *mut T, count: usize)
825826
where
826827
T: Sized,
827828
{
@@ -837,9 +838,10 @@ impl<T: ?Sized> *const T {
837838
/// See [`ptr::copy_nonoverlapping`] for safety concerns and examples.
838839
///
839840
/// [`ptr::copy_nonoverlapping`]: crate::ptr::copy_nonoverlapping()
841+
#[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")]
840842
#[stable(feature = "pointer_methods", since = "1.26.0")]
841843
#[inline]
842-
pub unsafe fn copy_to_nonoverlapping(self, dest: *mut T, count: usize)
844+
pub const unsafe fn copy_to_nonoverlapping(self, dest: *mut T, count: usize)
843845
where
844846
T: Sized,
845847
{

library/core/src/ptr/mod.rs

+11-15
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
use crate::cmp::Ordering;
6868
use crate::fmt;
6969
use crate::hash;
70-
use crate::intrinsics::{self, abort, is_aligned_and_not_null, is_nonoverlapping};
70+
use crate::intrinsics::{self, abort, is_aligned_and_not_null};
7171
use crate::mem::{self, MaybeUninit};
7272

7373
#[stable(feature = "rust1", since = "1.0.0")]
@@ -394,7 +394,8 @@ pub const fn slice_from_raw_parts_mut<T>(data: *mut T, len: usize) -> *mut [T] {
394394
/// ```
395395
#[inline]
396396
#[stable(feature = "rust1", since = "1.0.0")]
397-
pub unsafe fn swap<T>(x: *mut T, y: *mut T) {
397+
#[rustc_const_unstable(feature = "const_swap", issue = "83163")]
398+
pub const unsafe fn swap<T>(x: *mut T, y: *mut T) {
398399
// Give ourselves some scratch space to work with.
399400
// We do not have to worry about drops: `MaybeUninit` does nothing when dropped.
400401
let mut tmp = MaybeUninit::<T>::uninit();
@@ -451,16 +452,8 @@ pub unsafe fn swap<T>(x: *mut T, y: *mut T) {
451452
/// ```
452453
#[inline]
453454
#[stable(feature = "swap_nonoverlapping", since = "1.27.0")]
454-
pub unsafe fn swap_nonoverlapping<T>(x: *mut T, y: *mut T, count: usize) {
455-
if cfg!(debug_assertions)
456-
&& !(is_aligned_and_not_null(x)
457-
&& is_aligned_and_not_null(y)
458-
&& is_nonoverlapping(x, y, count))
459-
{
460-
// Not panicking to keep codegen impact smaller.
461-
abort();
462-
}
463-
455+
#[rustc_const_unstable(feature = "const_swap", issue = "83163")]
456+
pub const unsafe fn swap_nonoverlapping<T>(x: *mut T, y: *mut T, count: usize) {
464457
let x = x as *mut u8;
465458
let y = y as *mut u8;
466459
let len = mem::size_of::<T>() * count;
@@ -470,7 +463,8 @@ pub unsafe fn swap_nonoverlapping<T>(x: *mut T, y: *mut T, count: usize) {
470463
}
471464

472465
#[inline]
473-
pub(crate) unsafe fn swap_nonoverlapping_one<T>(x: *mut T, y: *mut T) {
466+
#[rustc_const_unstable(feature = "const_swap", issue = "83163")]
467+
pub(crate) const unsafe fn swap_nonoverlapping_one<T>(x: *mut T, y: *mut T) {
474468
// For types smaller than the block optimization below,
475469
// just swap directly to avoid pessimizing codegen.
476470
if mem::size_of::<T>() < 32 {
@@ -488,7 +482,8 @@ pub(crate) unsafe fn swap_nonoverlapping_one<T>(x: *mut T, y: *mut T) {
488482
}
489483

490484
#[inline]
491-
unsafe fn swap_nonoverlapping_bytes(x: *mut u8, y: *mut u8, len: usize) {
485+
#[rustc_const_unstable(feature = "const_swap", issue = "83163")]
486+
const unsafe fn swap_nonoverlapping_bytes(x: *mut u8, y: *mut u8, len: usize) {
492487
// The approach here is to utilize simd to swap x & y efficiently. Testing reveals
493488
// that swapping either 32 bytes or 64 bytes at a time is most efficient for Intel
494489
// Haswell E processors. LLVM is more able to optimize if we give a struct a
@@ -589,7 +584,8 @@ unsafe fn swap_nonoverlapping_bytes(x: *mut u8, y: *mut u8, len: usize) {
589584
/// ```
590585
#[inline]
591586
#[stable(feature = "rust1", since = "1.0.0")]
592-
pub unsafe fn replace<T>(dst: *mut T, mut src: T) -> T {
587+
#[rustc_const_unstable(feature = "const_replace", issue = "83164")]
588+
pub const unsafe fn replace<T>(dst: *mut T, mut src: T) -> T {
593589
// SAFETY: the caller must guarantee that `dst` is valid to be
594590
// cast to a mutable reference (valid for writes, aligned, initialized),
595591
// and cannot overlap `src` since `dst` must point to a distinct

library/core/src/ptr/mut_ptr.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -926,9 +926,10 @@ impl<T: ?Sized> *mut T {
926926
/// See [`ptr::copy`] for safety concerns and examples.
927927
///
928928
/// [`ptr::copy`]: crate::ptr::copy()
929+
#[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")]
929930
#[stable(feature = "pointer_methods", since = "1.26.0")]
930931
#[inline]
931-
pub unsafe fn copy_to(self, dest: *mut T, count: usize)
932+
pub const unsafe fn copy_to(self, dest: *mut T, count: usize)
932933
where
933934
T: Sized,
934935
{
@@ -944,9 +945,10 @@ impl<T: ?Sized> *mut T {
944945
/// See [`ptr::copy_nonoverlapping`] for safety concerns and examples.
945946
///
946947
/// [`ptr::copy_nonoverlapping`]: crate::ptr::copy_nonoverlapping()
948+
#[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")]
947949
#[stable(feature = "pointer_methods", since = "1.26.0")]
948950
#[inline]
949-
pub unsafe fn copy_to_nonoverlapping(self, dest: *mut T, count: usize)
951+
pub const unsafe fn copy_to_nonoverlapping(self, dest: *mut T, count: usize)
950952
where
951953
T: Sized,
952954
{
@@ -962,9 +964,10 @@ impl<T: ?Sized> *mut T {
962964
/// See [`ptr::copy`] for safety concerns and examples.
963965
///
964966
/// [`ptr::copy`]: crate::ptr::copy()
967+
#[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")]
965968
#[stable(feature = "pointer_methods", since = "1.26.0")]
966969
#[inline]
967-
pub unsafe fn copy_from(self, src: *const T, count: usize)
970+
pub const unsafe fn copy_from(self, src: *const T, count: usize)
968971
where
969972
T: Sized,
970973
{
@@ -980,9 +983,10 @@ impl<T: ?Sized> *mut T {
980983
/// See [`ptr::copy_nonoverlapping`] for safety concerns and examples.
981984
///
982985
/// [`ptr::copy_nonoverlapping`]: crate::ptr::copy_nonoverlapping()
986+
#[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")]
983987
#[stable(feature = "pointer_methods", since = "1.26.0")]
984988
#[inline]
985-
pub unsafe fn copy_from_nonoverlapping(self, src: *const T, count: usize)
989+
pub const unsafe fn copy_from_nonoverlapping(self, src: *const T, count: usize)
986990
where
987991
T: Sized,
988992
{

library/std/src/path.rs

+30
Original file line numberDiff line numberDiff line change
@@ -2472,6 +2472,36 @@ impl Path {
24722472
fs::metadata(self).is_ok()
24732473
}
24742474

2475+
/// Returns `Ok(true)` if the path points at an existing entity.
2476+
///
2477+
/// This function will traverse symbolic links to query information about the
2478+
/// destination file. In case of broken symbolic links this will return `Ok(false)`.
2479+
///
2480+
/// As opposed to the `exists()` method, this one doesn't silently ignore errors
2481+
/// unrelated to the path not existing. (E.g. it will return `Err(_)` in case of permission
2482+
/// denied on some of the parent directories.)
2483+
///
2484+
/// # Examples
2485+
///
2486+
/// ```no_run
2487+
/// #![feature(path_try_exists)]
2488+
///
2489+
/// use std::path::Path;
2490+
/// assert!(!Path::new("does_not_exist.txt").try_exists().expect("Can't check existence of file does_not_exist.txt"));
2491+
/// assert!(Path::new("/root/secret_file.txt").try_exists().is_err());
2492+
/// ```
2493+
// FIXME: stabilization should modify documentation of `exists()` to recommend this method
2494+
// instead.
2495+
#[unstable(feature = "path_try_exists", issue = "83186")]
2496+
#[inline]
2497+
pub fn try_exists(&self) -> io::Result<bool> {
2498+
match fs::metadata(self) {
2499+
Ok(_) => Ok(true),
2500+
Err(error) if error.kind() == io::ErrorKind::NotFound => Ok(false),
2501+
Err(error) => Err(error),
2502+
}
2503+
}
2504+
24752505
/// Returns `true` if the path exists on disk and is pointing at a regular file.
24762506
///
24772507
/// This function will traverse symbolic links to query information about the

library/std/src/prelude/v1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub use core::prelude::v1::{
4848
// FIXME: Attribute and internal derive macros are not documented because for them rustdoc generates
4949
// dead links which fail link checker testing.
5050
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
51-
#[allow(deprecated)]
51+
#[allow(deprecated, deprecated_in_future)]
5252
#[doc(hidden)]
5353
pub use core::prelude::v1::{
5454
bench, global_allocator, test, test_case, RustcDecodable, RustcEncodable,

src/bootstrap/test.rs

+13
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,19 @@ impl Step for Tidy {
791791

792792
if builder.config.channel == "dev" || builder.config.channel == "nightly" {
793793
builder.info("fmt check");
794+
if builder.config.initial_rustfmt.is_none() {
795+
let inferred_rustfmt_dir = builder.config.initial_rustc.parent().unwrap();
796+
eprintln!(
797+
"\
798+
error: no `rustfmt` binary found in {PATH}
799+
info: `rust.channel` is currently set to \"{CHAN}\"
800+
help: if you are testing a beta branch, set `rust.channel` to \"beta\" in the `config.toml` file
801+
help: to skip test's attempt to check tidiness, pass `--exclude src/tools/tidy` to `x.py test`",
802+
PATH = inferred_rustfmt_dir.display(),
803+
CHAN = builder.config.channel,
804+
);
805+
std::process::exit(1);
806+
}
794807
crate::format::format(&builder.build, !builder.config.cmd.bless());
795808
}
796809
}

0 commit comments

Comments
 (0)