Auto merge of #138548 - jieyouxu:rollup-xpslct5, r=jieyouxu

Rollup of 16 pull requests

Successful merges:

 - #133055 (Expand `CloneToUninit` documentation.)
 - #137147 (Add exclude to config.toml)
 - #137864 (Don't drop `Rvalue::WrapUnsafeBinder` during GVN)
 - #137890 (doc: clarify that consume can be called after BufReader::peek)
 - #137956 (Add RTN support to rustdoc)
 - #137968 (Properly escape regexes in Python scripts)
 - #138082 (Remove `#[cfg(not(test))]` gates in `core`)
 - #138275 (expose `is_s390x_feature_detected!` from `std::arch`)
 - #138303 (Fix Ptr inconsistency in {Rc,Arc})
 - #138309 (Add missing doc for intrinsic (Fix PR135334))
 - #138323 (Expand and organize `offset_of!` documentation.)
 - #138329 (debug-assert that the size_hint is well-formed in `collect`)
 - #138465 (linkchecker: bump html5ever)
 - #138471 (Clean up some tests in tests/ui)
 - #138472 (Add codegen test for #129795)
 - #138484 (Use lit span when suggesting suffix lit cast)

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2025-03-16 02:02:45 +00:00
commit 66678e6822
77 changed files with 853 additions and 382 deletions

View file

@ -1548,16 +1548,14 @@ dependencies = [
[[package]] [[package]]
name = "html5ever" name = "html5ever"
version = "0.27.0" version = "0.29.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" checksum = "9b958f80f0fde8601dc6c08685adc743eecaa046181cebd5a57551468dfc2ddc"
dependencies = [ dependencies = [
"log", "log",
"mac", "mac",
"markup5ever", "markup5ever",
"proc-macro2", "match_token",
"quote",
"syn 2.0.96",
] ]
[[package]] [[package]]
@ -2023,7 +2021,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"windows-targets 0.52.6", "windows-targets 0.48.5",
] ]
[[package]] [[package]]
@ -2134,9 +2132,9 @@ checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4"
[[package]] [[package]]
name = "markup5ever" name = "markup5ever"
version = "0.12.1" version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" checksum = "03a7b81dfb91586d0677086d40a6d755070e0799b71bb897485bac408dfd5c69"
dependencies = [ dependencies = [
"log", "log",
"phf", "phf",
@ -2146,6 +2144,17 @@ dependencies = [
"tendril", "tendril",
] ]
[[package]]
name = "match_token"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88a9689d8d44bf9964484516275f5cd4c9b59457a6940c1d5d0ecbb94510a36b"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.96",
]
[[package]] [[package]]
name = "matchers" name = "matchers"
version = "0.1.0" version = "0.1.0"
@ -2628,7 +2637,7 @@ version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fd6780a80ae0c52cc120a26a1a42c1ae51b247a253e4e06113d23d2c2edd078" checksum = "1fd6780a80ae0c52cc120a26a1a42c1ae51b247a253e4e06113d23d2c2edd078"
dependencies = [ dependencies = [
"phf_shared 0.11.3", "phf_shared",
] ]
[[package]] [[package]]
@ -2637,18 +2646,8 @@ version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aef8048c789fa5e851558d709946d6d79a8ff88c0440c587967f8e94bfb1216a" checksum = "aef8048c789fa5e851558d709946d6d79a8ff88c0440c587967f8e94bfb1216a"
dependencies = [ dependencies = [
"phf_generator 0.11.3", "phf_generator",
"phf_shared 0.11.3", "phf_shared",
]
[[package]]
name = "phf_generator"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6"
dependencies = [
"phf_shared 0.10.0",
"rand 0.8.5",
] ]
[[package]] [[package]]
@ -2657,26 +2656,17 @@ version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c80231409c20246a13fddb31776fb942c38553c51e871f8cbd687a4cfb5843d" checksum = "3c80231409c20246a13fddb31776fb942c38553c51e871f8cbd687a4cfb5843d"
dependencies = [ dependencies = [
"phf_shared 0.11.3", "phf_shared",
"rand 0.8.5", "rand 0.8.5",
] ]
[[package]]
name = "phf_shared"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096"
dependencies = [
"siphasher 0.3.11",
]
[[package]] [[package]]
name = "phf_shared" name = "phf_shared"
version = "0.11.3" version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67eabc2ef2a60eb7faa00097bd1ffdb5bd28e62bf39990626a582201b7a754e5" checksum = "67eabc2ef2a60eb7faa00097bd1ffdb5bd28e62bf39990626a582201b7a754e5"
dependencies = [ dependencies = [
"siphasher 1.0.1", "siphasher",
] ]
[[package]] [[package]]
@ -4861,12 +4851,6 @@ version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1de1d4f81173b03af4c0cbed3c898f6bff5b870e4a7f5d6f4057d62a7a4b686e" checksum = "1de1d4f81173b03af4c0cbed3c898f6bff5b870e4a7f5d6f4057d62a7a4b686e"
[[package]]
name = "siphasher"
version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d"
[[package]] [[package]]
name = "siphasher" name = "siphasher"
version = "1.0.1" version = "1.0.1"
@ -4981,26 +4965,25 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]] [[package]]
name = "string_cache" name = "string_cache"
version = "0.8.7" version = "0.8.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" checksum = "938d512196766101d333398efde81bc1f37b00cb42c2f8350e5df639f040bbbe"
dependencies = [ dependencies = [
"new_debug_unreachable", "new_debug_unreachable",
"once_cell",
"parking_lot", "parking_lot",
"phf_shared 0.10.0", "phf_shared",
"precomputed-hash", "precomputed-hash",
"serde", "serde",
] ]
[[package]] [[package]]
name = "string_cache_codegen" name = "string_cache_codegen"
version = "0.5.2" version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" checksum = "c711928715f1fe0fe509c53b43e993a9a557babc2d0a3567d0a3006f1ac931a0"
dependencies = [ dependencies = [
"phf_generator 0.10.0", "phf_generator",
"phf_shared 0.10.0", "phf_shared",
"proc-macro2", "proc-macro2",
"quote", "quote",
] ]

View file

@ -1,4 +1,4 @@
From ad7ffe71baba46865f2e65266ab025920dfdc20b Mon Sep 17 00:00:00 2001 From 5d7c709608b01301d4628d2159265936d4440b67 Mon Sep 17 00:00:00 2001
From: bjorn3 <bjorn3@users.noreply.github.com> From: bjorn3 <bjorn3@users.noreply.github.com>
Date: Thu, 18 Feb 2021 18:45:28 +0100 Date: Thu, 18 Feb 2021 18:45:28 +0100
Subject: [PATCH] Disable 128bit atomic operations Subject: [PATCH] Disable 128bit atomic operations
@ -7,11 +7,10 @@ Cranelift doesn't support them yet
--- ---
library/core/src/panic/unwind_safe.rs | 6 ----- library/core/src/panic/unwind_safe.rs | 6 -----
library/core/src/sync/atomic.rs | 38 --------------------------- library/core/src/sync/atomic.rs | 38 ---------------------------
library/core/tests/atomic.rs | 4 --- 2 files changed, 44 deletions(-)
4 files changed, 4 insertions(+), 50 deletions(-)
diff --git a/library/core/src/panic/unwind_safe.rs b/library/core/src/panic/unwind_safe.rs diff --git a/library/core/src/panic/unwind_safe.rs b/library/core/src/panic/unwind_safe.rs
index 092b7cf..158cf71 100644 index a60f0799c0e..af056fbf41f 100644
--- a/library/core/src/panic/unwind_safe.rs --- a/library/core/src/panic/unwind_safe.rs
+++ b/library/core/src/panic/unwind_safe.rs +++ b/library/core/src/panic/unwind_safe.rs
@@ -216,9 +216,6 @@ impl RefUnwindSafe for crate::sync::atomic::AtomicI32 {} @@ -216,9 +216,6 @@ impl RefUnwindSafe for crate::sync::atomic::AtomicI32 {}
@ -21,7 +20,7 @@ index 092b7cf..158cf71 100644
-#[cfg(target_has_atomic_load_store = "128")] -#[cfg(target_has_atomic_load_store = "128")]
-#[unstable(feature = "integer_atomics", issue = "99069")] -#[unstable(feature = "integer_atomics", issue = "99069")]
-impl RefUnwindSafe for crate::sync::atomic::AtomicI128 {} -impl RefUnwindSafe for crate::sync::atomic::AtomicI128 {}
#[cfg(target_has_atomic_load_store = "ptr")] #[cfg(target_has_atomic_load_store = "ptr")]
#[stable(feature = "unwind_safe_atomic_refs", since = "1.14.0")] #[stable(feature = "unwind_safe_atomic_refs", since = "1.14.0")]
@@ -235,9 +232,6 @@ impl RefUnwindSafe for crate::sync::atomic::AtomicU32 {} @@ -235,9 +232,6 @@ impl RefUnwindSafe for crate::sync::atomic::AtomicU32 {}
@ -31,14 +30,14 @@ index 092b7cf..158cf71 100644
-#[cfg(target_has_atomic_load_store = "128")] -#[cfg(target_has_atomic_load_store = "128")]
-#[unstable(feature = "integer_atomics", issue = "99069")] -#[unstable(feature = "integer_atomics", issue = "99069")]
-impl RefUnwindSafe for crate::sync::atomic::AtomicU128 {} -impl RefUnwindSafe for crate::sync::atomic::AtomicU128 {}
#[cfg(target_has_atomic_load_store = "8")] #[cfg(target_has_atomic_load_store = "8")]
#[stable(feature = "unwind_safe_atomic_refs", since = "1.14.0")] #[stable(feature = "unwind_safe_atomic_refs", since = "1.14.0")]
diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs
index d9de37e..8293fce 100644 index bf2b6d59f88..d5ccce03bbf 100644
--- a/library/core/src/sync/atomic.rs --- a/library/core/src/sync/atomic.rs
+++ b/library/core/src/sync/atomic.rs +++ b/library/core/src/sync/atomic.rs
@@ -2996,44 +2996,6 @@ atomic_int! { @@ -3585,44 +3585,6 @@ pub const fn as_ptr(&self) -> *mut $int_type {
8, 8,
u64 AtomicU64 u64 AtomicU64
} }
@ -54,7 +53,7 @@ index d9de37e..8293fce 100644
- unstable(feature = "integer_atomics", issue = "99069"), - unstable(feature = "integer_atomics", issue = "99069"),
- rustc_const_unstable(feature = "integer_atomics", issue = "99069"), - rustc_const_unstable(feature = "integer_atomics", issue = "99069"),
- rustc_const_unstable(feature = "integer_atomics", issue = "99069"), - rustc_const_unstable(feature = "integer_atomics", issue = "99069"),
- cfg_attr(not(test), rustc_diagnostic_item = "AtomicI128"), - rustc_diagnostic_item = "AtomicI128",
- "i128", - "i128",
- "#![feature(integer_atomics)]\n\n", - "#![feature(integer_atomics)]\n\n",
- atomic_min, atomic_max, - atomic_min, atomic_max,
@ -73,7 +72,7 @@ index d9de37e..8293fce 100644
- unstable(feature = "integer_atomics", issue = "99069"), - unstable(feature = "integer_atomics", issue = "99069"),
- rustc_const_unstable(feature = "integer_atomics", issue = "99069"), - rustc_const_unstable(feature = "integer_atomics", issue = "99069"),
- rustc_const_unstable(feature = "integer_atomics", issue = "99069"), - rustc_const_unstable(feature = "integer_atomics", issue = "99069"),
- cfg_attr(not(test), rustc_diagnostic_item = "AtomicU128"), - rustc_diagnostic_item = "AtomicU128",
- "u128", - "u128",
- "#![feature(integer_atomics)]\n\n", - "#![feature(integer_atomics)]\n\n",
- atomic_umin, atomic_umax, - atomic_umin, atomic_umax,
@ -83,7 +82,6 @@ index d9de37e..8293fce 100644
#[cfg(target_has_atomic_load_store = "ptr")] #[cfg(target_has_atomic_load_store = "ptr")]
macro_rules! atomic_int_ptr_sized { macro_rules! atomic_int_ptr_sized {
( $($target_pointer_width:literal $align:literal)* ) => { $( --
-- 2.48.1
2.26.2.7.g19db9cfb68

View file

@ -252,7 +252,9 @@ pub fn lower_ty<'tcx>(tcx: TyCtxt<'tcx>, hir_ty: &hir::Ty<'tcx>) -> Ty<'tcx> {
// def-ID that will be used to determine the traits/predicates in // def-ID that will be used to determine the traits/predicates in
// scope. This is derived from the enclosing item-like thing. // scope. This is derived from the enclosing item-like thing.
let env_def_id = tcx.hir_get_parent_item(hir_ty.hir_id); let env_def_id = tcx.hir_get_parent_item(hir_ty.hir_id);
collect::ItemCtxt::new(tcx, env_def_id.def_id).lower_ty(hir_ty) collect::ItemCtxt::new(tcx, env_def_id.def_id)
.lowerer()
.lower_ty_maybe_return_type_notation(hir_ty)
} }
/// This is for rustdoc. /// This is for rustdoc.

View file

@ -2983,7 +2983,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return false; return false;
} }
let Ok(src) = self.tcx.sess.source_map().span_to_snippet(expr.span) else { let span = if let hir::ExprKind::Lit(lit) = &expr.kind { lit.span } else { expr.span };
let Ok(src) = self.tcx.sess.source_map().span_to_snippet(span) else {
return false; return false;
}; };
@ -3078,10 +3079,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Remove fractional part from literal, for example `42.0f32` into `42` // Remove fractional part from literal, for example `42.0f32` into `42`
let src = src.trim_end_matches(&checked_ty.to_string()); let src = src.trim_end_matches(&checked_ty.to_string());
let len = src.split('.').next().unwrap().len(); let len = src.split('.').next().unwrap().len();
expr.span.with_lo(expr.span.lo() + BytePos(len as u32)) span.with_lo(span.lo() + BytePos(len as u32))
} else { } else {
let len = src.trim_end_matches(&checked_ty.to_string()).len(); let len = src.trim_end_matches(&checked_ty.to_string()).len();
expr.span.with_lo(expr.span.lo() + BytePos(len as u32)) span.with_lo(span.lo() + BytePos(len as u32))
}, },
if expr.precedence() < ExprPrecedence::Unambiguous { if expr.precedence() < ExprPrecedence::Unambiguous {
// Readd `)` // Readd `)`

View file

@ -872,8 +872,14 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
self.simplify_place_projection(place, location); self.simplify_place_projection(place, location);
return self.new_pointer(*place, AddressKind::Address(mutbl)); return self.new_pointer(*place, AddressKind::Address(mutbl));
} }
Rvalue::WrapUnsafeBinder(ref mut op, _) => { Rvalue::WrapUnsafeBinder(ref mut op, ty) => {
return self.simplify_operand(op, location); let value = self.simplify_operand(op, location)?;
Value::Cast {
kind: CastKind::Transmute,
value,
from: op.ty(self.local_decls, self.tcx),
to: ty,
}
} }
// Operations. // Operations.

View file

@ -446,6 +446,10 @@
# a specific version. # a specific version.
#ccache = false #ccache = false
# List of paths to exclude from the build and test processes.
# For example, exclude = ["tests/ui", "src/tools/tidy"].
#exclude = []
# ============================================================================= # =============================================================================
# General install configuration options # General install configuration options
# ============================================================================= # =============================================================================

View file

@ -1327,11 +1327,14 @@ impl<T: ?Sized> Rc<T> {
/// ///
/// # Safety /// # Safety
/// ///
/// The pointer must have been obtained through `Rc::into_raw`, the /// The pointer must have been obtained through `Rc::into_raw` and must satisfy the
/// associated `Rc` instance must be valid (i.e. the strong count must be at /// same layout requirements specified in [`Rc::from_raw_in`][from_raw_in].
/// The associated `Rc` instance must be valid (i.e. the strong count must be at
/// least 1) for the duration of this method, and `ptr` must point to a block of memory /// least 1) for the duration of this method, and `ptr` must point to a block of memory
/// allocated by the global allocator. /// allocated by the global allocator.
/// ///
/// [from_raw_in]: Rc::from_raw_in
///
/// # Examples /// # Examples
/// ///
/// ``` /// ```
@ -1360,12 +1363,15 @@ impl<T: ?Sized> Rc<T> {
/// ///
/// # Safety /// # Safety
/// ///
/// The pointer must have been obtained through `Rc::into_raw`, the /// The pointer must have been obtained through `Rc::into_raw`and must satisfy the
/// associated `Rc` instance must be valid (i.e. the strong count must be at /// same layout requirements specified in [`Rc::from_raw_in`][from_raw_in].
/// The associated `Rc` instance must be valid (i.e. the strong count must be at
/// least 1) when invoking this method, and `ptr` must point to a block of memory /// least 1) when invoking this method, and `ptr` must point to a block of memory
/// allocated by the global allocator. This method can be used to release the final `Rc` and /// allocated by the global allocator. This method can be used to release the final `Rc` and
/// backing storage, but **should not** be called after the final `Rc` has been released. /// backing storage, but **should not** be called after the final `Rc` has been released.
/// ///
/// [from_raw_in]: Rc::from_raw_in
///
/// # Examples /// # Examples
/// ///
/// ``` /// ```
@ -1623,10 +1629,13 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
/// ///
/// # Safety /// # Safety
/// ///
/// The pointer must have been obtained through `Rc::into_raw`, the /// The pointer must have been obtained through `Rc::into_raw` and must satisfy the
/// associated `Rc` instance must be valid (i.e. the strong count must be at /// same layout requirements specified in [`Rc::from_raw_in`][from_raw_in].
/// The associated `Rc` instance must be valid (i.e. the strong count must be at
/// least 1) for the duration of this method, and `ptr` must point to a block of memory /// least 1) for the duration of this method, and `ptr` must point to a block of memory
/// allocated by `alloc` /// allocated by `alloc`.
///
/// [from_raw_in]: Rc::from_raw_in
/// ///
/// # Examples /// # Examples
/// ///
@ -1665,11 +1674,14 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
/// ///
/// # Safety /// # Safety
/// ///
/// The pointer must have been obtained through `Rc::into_raw`, the /// The pointer must have been obtained through `Rc::into_raw`and must satisfy the
/// associated `Rc` instance must be valid (i.e. the strong count must be at /// same layout requirements specified in [`Rc::from_raw_in`][from_raw_in].
/// The associated `Rc` instance must be valid (i.e. the strong count must be at
/// least 1) when invoking this method, and `ptr` must point to a block of memory /// least 1) when invoking this method, and `ptr` must point to a block of memory
/// allocated by `alloc`. This method can be used to release the final `Rc` and backing storage, /// allocated by `alloc`. This method can be used to release the final `Rc` and
/// but **should not** be called after the final `Rc` has been released. /// backing storage, but **should not** be called after the final `Rc` has been released.
///
/// [from_raw_in]: Rc::from_raw_in
/// ///
/// # Examples /// # Examples
/// ///

View file

@ -1453,11 +1453,14 @@ impl<T: ?Sized> Arc<T> {
/// ///
/// # Safety /// # Safety
/// ///
/// The pointer must have been obtained through `Arc::into_raw`, and the /// The pointer must have been obtained through `Arc::into_raw` and must satisfy the
/// associated `Arc` instance must be valid (i.e. the strong count must be at /// same layout requirements specified in [`Arc::from_raw_in`][from_raw_in].
/// The associated `Arc` instance must be valid (i.e. the strong count must be at
/// least 1) for the duration of this method, and `ptr` must point to a block of memory /// least 1) for the duration of this method, and `ptr` must point to a block of memory
/// allocated by the global allocator. /// allocated by the global allocator.
/// ///
/// [from_raw_in]: Arc::from_raw_in
///
/// # Examples /// # Examples
/// ///
/// ``` /// ```
@ -1488,13 +1491,16 @@ impl<T: ?Sized> Arc<T> {
/// ///
/// # Safety /// # Safety
/// ///
/// The pointer must have been obtained through `Arc::into_raw`, and the /// The pointer must have been obtained through `Arc::into_raw` and must satisfy the
/// associated `Arc` instance must be valid (i.e. the strong count must be at /// same layout requirements specified in [`Arc::from_raw_in`][from_raw_in].
/// The associated `Arc` instance must be valid (i.e. the strong count must be at
/// least 1) when invoking this method, and `ptr` must point to a block of memory /// least 1) when invoking this method, and `ptr` must point to a block of memory
/// allocated by the global allocator. This method can be used to release the final /// allocated by the global allocator. This method can be used to release the final
/// `Arc` and backing storage, but **should not** be called after the final `Arc` has been /// `Arc` and backing storage, but **should not** be called after the final `Arc` has been
/// released. /// released.
/// ///
/// [from_raw_in]: Arc::from_raw_in
///
/// # Examples /// # Examples
/// ///
/// ``` /// ```
@ -1806,11 +1812,14 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
/// ///
/// # Safety /// # Safety
/// ///
/// The pointer must have been obtained through `Arc::into_raw`, and the /// The pointer must have been obtained through `Arc::into_raw` and must satisfy the
/// associated `Arc` instance must be valid (i.e. the strong count must be at /// same layout requirements specified in [`Arc::from_raw_in`][from_raw_in].
/// least 1) for the duration of this method,, and `ptr` must point to a block of memory /// The associated `Arc` instance must be valid (i.e. the strong count must be at
/// least 1) for the duration of this method, and `ptr` must point to a block of memory
/// allocated by `alloc`. /// allocated by `alloc`.
/// ///
/// [from_raw_in]: Arc::from_raw_in
///
/// # Examples /// # Examples
/// ///
/// ``` /// ```
@ -1850,13 +1859,16 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
/// ///
/// # Safety /// # Safety
/// ///
/// The pointer must have been obtained through `Arc::into_raw`, the /// The pointer must have been obtained through `Arc::into_raw` and must satisfy the
/// associated `Arc` instance must be valid (i.e. the strong count must be at /// same layout requirements specified in [`Arc::from_raw_in`][from_raw_in].
/// The associated `Arc` instance must be valid (i.e. the strong count must be at
/// least 1) when invoking this method, and `ptr` must point to a block of memory /// least 1) when invoking this method, and `ptr` must point to a block of memory
/// allocated by `alloc`. This method can be used to release the final /// allocated by `alloc`. This method can be used to release the final
/// `Arc` and backing storage, but **should not** be called after the final `Arc` has been /// `Arc` and backing storage, but **should not** be called after the final `Arc` has been
/// released. /// released.
/// ///
/// [from_raw_in]: Arc::from_raw_in
///
/// # Examples /// # Examples
/// ///
/// ``` /// ```

View file

@ -109,7 +109,7 @@ use crate::{fmt, hash, intrinsics};
// unsafe traits and unsafe methods (i.e., `type_id` would still be safe to call, // unsafe traits and unsafe methods (i.e., `type_id` would still be safe to call,
// but we would likely want to indicate as such in documentation). // but we would likely want to indicate as such in documentation).
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "Any")] #[rustc_diagnostic_item = "Any"]
pub trait Any: 'static { pub trait Any: 'static {
/// Gets the `TypeId` of `self`. /// Gets the `TypeId` of `self`.
/// ///

View file

@ -1,6 +1,5 @@
use crate::ascii; use crate::ascii;
#[cfg(not(test))]
impl<const N: usize> [u8; N] { impl<const N: usize> [u8; N] {
/// Converts this array of bytes into an array of ASCII characters, /// Converts this array of bytes into an array of ASCII characters,
/// or returns `None` if any of the characters is non-ASCII. /// or returns `None` if any of the characters is non-ASCII.

View file

@ -56,7 +56,7 @@ impl bool {
/// ``` /// ```
#[doc(alias = "then_with")] #[doc(alias = "then_with")]
#[stable(feature = "lazy_bool_to_option", since = "1.50.0")] #[stable(feature = "lazy_bool_to_option", since = "1.50.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "bool_then")] #[rustc_diagnostic_item = "bool_then"]
#[inline] #[inline]
pub fn then<T, F: FnOnce() -> T>(self, f: F) -> Option<T> { pub fn then<T, F: FnOnce() -> T>(self, f: F) -> Option<T> {
if self { Some(f()) } else { None } if self { Some(f()) } else { None }

View file

@ -304,7 +304,7 @@ pub use once::OnceCell;
/// ``` /// ```
/// ///
/// See the [module-level documentation](self) for more. /// See the [module-level documentation](self) for more.
#[cfg_attr(not(test), rustc_diagnostic_item = "Cell")] #[rustc_diagnostic_item = "Cell"]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[repr(transparent)] #[repr(transparent)]
#[rustc_pub_transparent] #[rustc_pub_transparent]
@ -725,7 +725,7 @@ impl<T, const N: usize> Cell<[T; N]> {
/// A mutable memory location with dynamically checked borrow rules /// A mutable memory location with dynamically checked borrow rules
/// ///
/// See the [module-level documentation](self) for more. /// See the [module-level documentation](self) for more.
#[cfg_attr(not(test), rustc_diagnostic_item = "RefCell")] #[rustc_diagnostic_item = "RefCell"]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
pub struct RefCell<T: ?Sized> { pub struct RefCell<T: ?Sized> {
borrow: Cell<BorrowFlag>, borrow: Cell<BorrowFlag>,

View file

@ -1178,7 +1178,7 @@ impl char {
#[must_use] #[must_use]
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")] #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
#[rustc_const_stable(feature = "const_char_is_ascii", since = "1.32.0")] #[rustc_const_stable(feature = "const_char_is_ascii", since = "1.32.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "char_is_ascii")] #[rustc_diagnostic_item = "char_is_ascii"]
#[inline] #[inline]
pub const fn is_ascii(&self) -> bool { pub const fn is_ascii(&self) -> bool {
*self as u32 <= 0x7F *self as u32 <= 0x7F

View file

@ -262,34 +262,150 @@ pub struct AssertParamIsCopy<T: Copy + ?Sized> {
_field: crate::marker::PhantomData<T>, _field: crate::marker::PhantomData<T>,
} }
/// A generalization of [`Clone`] to dynamically-sized types stored in arbitrary containers. /// A generalization of [`Clone`] to [dynamically-sized types][DST] stored in arbitrary containers.
/// ///
/// This trait is implemented for all types implementing [`Clone`], and also [slices](slice) of all /// This trait is implemented for all types implementing [`Clone`], [slices](slice) of all
/// such types. You may also implement this trait to enable cloning trait objects and custom DSTs /// such types, and other dynamically-sized types in the standard library.
/// (structures containing dynamically-sized fields). /// You may also implement this trait to enable cloning custom DSTs
/// (structures containing dynamically-sized fields), or use it as a supertrait to enable
/// cloning a [trait object].
///
/// This trait is normally used via operations on container types which support DSTs,
/// so you should not typically need to call `.clone_to_uninit()` explicitly except when
/// implementing such a container or otherwise performing explicit management of an allocation,
/// or when implementing `CloneToUninit` itself.
/// ///
/// # Safety /// # Safety
/// ///
/// Implementations must ensure that when `.clone_to_uninit(dst)` returns normally rather than /// Implementations must ensure that when `.clone_to_uninit(dest)` returns normally rather than
/// panicking, it always leaves `*dst` initialized as a valid value of type `Self`. /// panicking, it always leaves `*dest` initialized as a valid value of type `Self`.
/// ///
/// # See also /// # Examples
/// ///
/// * [`Clone::clone_from`] is a safe function which may be used instead when `Self` is a [`Sized`] // FIXME(#126799): when `Box::clone` allows use of `CloneToUninit`, rewrite these examples with it
// since `Rc` is a distraction.
///
/// If you are defining a trait, you can add `CloneToUninit` as a supertrait to enable cloning of
/// `dyn` values of your trait:
///
/// ```
/// #![feature(clone_to_uninit)]
/// use std::rc::Rc;
///
/// trait Foo: std::fmt::Debug + std::clone::CloneToUninit {
/// fn modify(&mut self);
/// fn value(&self) -> i32;
/// }
///
/// impl Foo for i32 {
/// fn modify(&mut self) {
/// *self *= 10;
/// }
/// fn value(&self) -> i32 {
/// *self
/// }
/// }
///
/// let first: Rc<dyn Foo> = Rc::new(1234);
///
/// let mut second = first.clone();
/// Rc::make_mut(&mut second).modify(); // make_mut() will call clone_to_uninit()
///
/// assert_eq!(first.value(), 1234);
/// assert_eq!(second.value(), 12340);
/// ```
///
/// The following is an example of implementing `CloneToUninit` for a custom DST.
/// (It is essentially a limited form of what `derive(CloneToUninit)` would do,
/// if such a derive macro existed.)
///
/// ```
/// #![feature(clone_to_uninit)]
/// use std::clone::CloneToUninit;
/// use std::mem::offset_of;
/// use std::rc::Rc;
///
/// #[derive(PartialEq)]
/// struct MyDst<T: ?Sized> {
/// label: String,
/// contents: T,
/// }
///
/// unsafe impl<T: ?Sized + CloneToUninit> CloneToUninit for MyDst<T> {
/// unsafe fn clone_to_uninit(&self, dest: *mut u8) {
/// // The offset of `self.contents` is dynamic because it depends on the alignment of T
/// // which can be dynamic (if `T = dyn SomeTrait`). Therefore, we have to obtain it
/// // dynamically by examining `self`, rather than using `offset_of!`.
/// //
/// // SAFETY: `self` by definition points somewhere before `&self.contents` in the same
/// // allocation.
/// let offset_of_contents = unsafe {
/// (&raw const self.contents).byte_offset_from_unsigned(self)
/// };
///
/// // Clone the *sized* fields of `self` (just one, in this example).
/// // (By cloning this first and storing it temporarily in a local variable, we avoid
/// // leaking it in case of any panic, using the ordinary automatic cleanup of local
/// // variables. Such a leak would be sound, but undesirable.)
/// let label = self.label.clone();
///
/// // SAFETY: The caller must provide a `dest` such that these field offsets are valid
/// // to write to.
/// unsafe {
/// // Clone the unsized field directly from `self` to `dest`.
/// self.contents.clone_to_uninit(dest.add(offset_of_contents));
///
/// // Now write all the sized fields.
/// //
/// // Note that we only do this once all of the clone() and clone_to_uninit() calls
/// // have completed, and therefore we know that there are no more possible panics;
/// // this ensures no memory leaks in case of panic.
/// dest.add(offset_of!(Self, label)).cast::<String>().write(label);
/// }
/// // All fields of the struct have been initialized; therefore, the struct is initialized,
/// // and we have satisfied our `unsafe impl CloneToUninit` obligations.
/// }
/// }
///
/// fn main() {
/// // Construct MyDst<[u8; 4]>, then coerce to MyDst<[u8]>.
/// let first: Rc<MyDst<[u8]>> = Rc::new(MyDst {
/// label: String::from("hello"),
/// contents: [1, 2, 3, 4],
/// });
///
/// let mut second = first.clone();
/// // make_mut() will call clone_to_uninit().
/// for elem in Rc::make_mut(&mut second).contents.iter_mut() {
/// *elem *= 10;
/// }
///
/// assert_eq!(first.contents, [1, 2, 3, 4]);
/// assert_eq!(second.contents, [10, 20, 30, 40]);
/// assert_eq!(second.label, "hello");
/// }
/// ```
///
/// # See Also
///
/// * [`Clone::clone_from`] is a safe function which may be used instead when [`Self: Sized`](Sized)
/// and the destination is already initialized; it may be able to reuse allocations owned by /// and the destination is already initialized; it may be able to reuse allocations owned by
/// the destination. /// the destination, whereas `clone_to_uninit` cannot, since its destination is assumed to be
/// uninitialized.
/// * [`ToOwned`], which allocates a new destination container. /// * [`ToOwned`], which allocates a new destination container.
/// ///
/// [`ToOwned`]: ../../std/borrow/trait.ToOwned.html /// [`ToOwned`]: ../../std/borrow/trait.ToOwned.html
/// [DST]: https://doc.rust-lang.org/reference/dynamically-sized-types.html
/// [trait object]: https://doc.rust-lang.org/reference/types/trait-object.html
#[unstable(feature = "clone_to_uninit", issue = "126799")] #[unstable(feature = "clone_to_uninit", issue = "126799")]
pub unsafe trait CloneToUninit { pub unsafe trait CloneToUninit {
/// Performs copy-assignment from `self` to `dst`. /// Performs copy-assignment from `self` to `dest`.
/// ///
/// This is analogous to `std::ptr::write(dst.cast(), self.clone())`, /// This is analogous to `std::ptr::write(dest.cast(), self.clone())`,
/// except that `self` may be a dynamically-sized type ([`!Sized`](Sized)). /// except that `Self` may be a dynamically-sized type ([`!Sized`](Sized)).
/// ///
/// Before this function is called, `dst` may point to uninitialized memory. /// Before this function is called, `dest` may point to uninitialized memory.
/// After this function is called, `dst` will point to initialized memory; it will be /// After this function is called, `dest` will point to initialized memory; it will be
/// sound to create a `&Self` reference from the pointer with the [pointer metadata] /// sound to create a `&Self` reference from the pointer with the [pointer metadata]
/// from `self`. /// from `self`.
/// ///
@ -297,8 +413,8 @@ pub unsafe trait CloneToUninit {
/// ///
/// Behavior is undefined if any of the following conditions are violated: /// Behavior is undefined if any of the following conditions are violated:
/// ///
/// * `dst` must be [valid] for writes for `size_of_val(self)` bytes. /// * `dest` must be [valid] for writes for `size_of_val(self)` bytes.
/// * `dst` must be properly aligned to `align_of_val(self)`. /// * `dest` must be properly aligned to `align_of_val(self)`.
/// ///
/// [valid]: crate::ptr#safety /// [valid]: crate::ptr#safety
/// [pointer metadata]: crate::ptr::metadata() /// [pointer metadata]: crate::ptr::metadata()
@ -307,27 +423,26 @@ pub unsafe trait CloneToUninit {
/// ///
/// This function may panic. (For example, it might panic if memory allocation for a clone /// This function may panic. (For example, it might panic if memory allocation for a clone
/// of a value owned by `self` fails.) /// of a value owned by `self` fails.)
/// If the call panics, then `*dst` should be treated as uninitialized memory; it must not be /// If the call panics, then `*dest` should be treated as uninitialized memory; it must not be
/// read or dropped, because even if it was previously valid, it may have been partially /// read or dropped, because even if it was previously valid, it may have been partially
/// overwritten. /// overwritten.
/// ///
/// The caller may also need to take care to deallocate the allocation pointed to by `dst`, /// The caller may wish to to take care to deallocate the allocation pointed to by `dest`,
/// if applicable, to avoid a memory leak, and may need to take other precautions to ensure /// if applicable, to avoid a memory leak (but this is not a requirement).
/// soundness in the presence of unwinding.
/// ///
/// Implementors should avoid leaking values by, upon unwinding, dropping all component values /// Implementors should avoid leaking values by, upon unwinding, dropping all component values
/// that might have already been created. (For example, if a `[Foo]` of length 3 is being /// that might have already been created. (For example, if a `[Foo]` of length 3 is being
/// cloned, and the second of the three calls to `Foo::clone()` unwinds, then the first `Foo` /// cloned, and the second of the three calls to `Foo::clone()` unwinds, then the first `Foo`
/// cloned should be dropped.) /// cloned should be dropped.)
unsafe fn clone_to_uninit(&self, dst: *mut u8); unsafe fn clone_to_uninit(&self, dest: *mut u8);
} }
#[unstable(feature = "clone_to_uninit", issue = "126799")] #[unstable(feature = "clone_to_uninit", issue = "126799")]
unsafe impl<T: Clone> CloneToUninit for T { unsafe impl<T: Clone> CloneToUninit for T {
#[inline] #[inline]
unsafe fn clone_to_uninit(&self, dst: *mut u8) { unsafe fn clone_to_uninit(&self, dest: *mut u8) {
// SAFETY: we're calling a specialization with the same contract // SAFETY: we're calling a specialization with the same contract
unsafe { <T as self::uninit::CopySpec>::clone_one(self, dst.cast::<T>()) } unsafe { <T as self::uninit::CopySpec>::clone_one(self, dest.cast::<T>()) }
} }
} }
@ -335,10 +450,10 @@ unsafe impl<T: Clone> CloneToUninit for T {
unsafe impl<T: Clone> CloneToUninit for [T] { unsafe impl<T: Clone> CloneToUninit for [T] {
#[inline] #[inline]
#[cfg_attr(debug_assertions, track_caller)] #[cfg_attr(debug_assertions, track_caller)]
unsafe fn clone_to_uninit(&self, dst: *mut u8) { unsafe fn clone_to_uninit(&self, dest: *mut u8) {
let dst: *mut [T] = dst.with_metadata_of(self); let dest: *mut [T] = dest.with_metadata_of(self);
// SAFETY: we're calling a specialization with the same contract // SAFETY: we're calling a specialization with the same contract
unsafe { <T as self::uninit::CopySpec>::clone_slice(self, dst) } unsafe { <T as self::uninit::CopySpec>::clone_slice(self, dest) }
} }
} }
@ -346,21 +461,21 @@ unsafe impl<T: Clone> CloneToUninit for [T] {
unsafe impl CloneToUninit for str { unsafe impl CloneToUninit for str {
#[inline] #[inline]
#[cfg_attr(debug_assertions, track_caller)] #[cfg_attr(debug_assertions, track_caller)]
unsafe fn clone_to_uninit(&self, dst: *mut u8) { unsafe fn clone_to_uninit(&self, dest: *mut u8) {
// SAFETY: str is just a [u8] with UTF-8 invariant // SAFETY: str is just a [u8] with UTF-8 invariant
unsafe { self.as_bytes().clone_to_uninit(dst) } unsafe { self.as_bytes().clone_to_uninit(dest) }
} }
} }
#[unstable(feature = "clone_to_uninit", issue = "126799")] #[unstable(feature = "clone_to_uninit", issue = "126799")]
unsafe impl CloneToUninit for crate::ffi::CStr { unsafe impl CloneToUninit for crate::ffi::CStr {
#[cfg_attr(debug_assertions, track_caller)] #[cfg_attr(debug_assertions, track_caller)]
unsafe fn clone_to_uninit(&self, dst: *mut u8) { unsafe fn clone_to_uninit(&self, dest: *mut u8) {
// SAFETY: For now, CStr is just a #[repr(trasnsparent)] [c_char] with some invariants. // SAFETY: For now, CStr is just a #[repr(trasnsparent)] [c_char] with some invariants.
// And we can cast [c_char] to [u8] on all supported platforms (see: to_bytes_with_nul). // And we can cast [c_char] to [u8] on all supported platforms (see: to_bytes_with_nul).
// The pointer metadata properly preserves the length (so NUL is also copied). // The pointer metadata properly preserves the length (so NUL is also copied).
// See: `cstr_metadata_is_length_with_nul` in tests. // See: `cstr_metadata_is_length_with_nul` in tests.
unsafe { self.to_bytes_with_nul().clone_to_uninit(dst) } unsafe { self.to_bytes_with_nul().clone_to_uninit(dest) }
} }
} }

View file

@ -1481,7 +1481,7 @@ pub macro PartialOrd($item:item) {
#[inline] #[inline]
#[must_use] #[must_use]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "cmp_min")] #[rustc_diagnostic_item = "cmp_min"]
pub fn min<T: Ord>(v1: T, v2: T) -> T { pub fn min<T: Ord>(v1: T, v2: T) -> T {
v1.min(v2) v1.min(v2)
} }
@ -1573,7 +1573,7 @@ pub fn min_by_key<T, F: FnMut(&T) -> K, K: Ord>(v1: T, v2: T, mut f: F) -> T {
#[inline] #[inline]
#[must_use] #[must_use]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "cmp_max")] #[rustc_diagnostic_item = "cmp_max"]
pub fn max<T: Ord>(v1: T, v2: T) -> T { pub fn max<T: Ord>(v1: T, v2: T) -> T {
v1.max(v2) v1.max(v2)
} }

View file

@ -214,7 +214,7 @@ pub const fn identity<T>(x: T) -> T {
/// is_hello(s); /// is_hello(s);
/// ``` /// ```
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "AsRef")] #[rustc_diagnostic_item = "AsRef"]
pub trait AsRef<T: ?Sized> { pub trait AsRef<T: ?Sized> {
/// Converts this type into a shared reference of the (usually inferred) input type. /// Converts this type into a shared reference of the (usually inferred) input type.
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
@ -365,7 +365,7 @@ pub trait AsRef<T: ?Sized> {
/// Note, however, that APIs don't need to be generic. In many cases taking a `&mut [u8]` or /// Note, however, that APIs don't need to be generic. In many cases taking a `&mut [u8]` or
/// `&mut Vec<u8>`, for example, is the better choice (callers need to pass the correct type then). /// `&mut Vec<u8>`, for example, is the better choice (callers need to pass the correct type then).
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "AsMut")] #[rustc_diagnostic_item = "AsMut"]
pub trait AsMut<T: ?Sized> { pub trait AsMut<T: ?Sized> {
/// Converts this type into a mutable reference of the (usually inferred) input type. /// Converts this type into a mutable reference of the (usually inferred) input type.
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]

View file

@ -101,7 +101,7 @@ use crate::ascii::Char as AsciiChar;
/// bar: f32, /// bar: f32,
/// } /// }
/// ``` /// ```
#[cfg_attr(not(test), rustc_diagnostic_item = "Default")] #[rustc_diagnostic_item = "Default"]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[rustc_trivial_field_reads] #[rustc_trivial_field_reads]
pub trait Default: Sized { pub trait Default: Sized {

View file

@ -47,7 +47,7 @@ use crate::fmt::{self, Debug, Display, Formatter};
/// impl Error for ReadConfigError {} /// impl Error for ReadConfigError {}
/// ``` /// ```
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "Error")] #[rustc_diagnostic_item = "Error"]
#[rustc_has_incoherent_inherent_impls] #[rustc_has_incoherent_inherent_impls]
#[allow(multiple_supertrait_upcastable)] #[allow(multiple_supertrait_upcastable)]
pub trait Error: Debug + Display { pub trait Error: Debug + Display {

View file

@ -18,7 +18,7 @@ mod num;
mod rt; mod rt;
#[stable(feature = "fmt_flags_align", since = "1.28.0")] #[stable(feature = "fmt_flags_align", since = "1.28.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "Alignment")] #[rustc_diagnostic_item = "Alignment"]
/// Possible alignments returned by `Formatter::align` /// Possible alignments returned by `Formatter::align`
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Alignment { pub enum Alignment {

View file

@ -1774,10 +1774,14 @@ pub fn ptr_mask<T>(ptr: *const T, mask: usize) -> *const T;
/// a size of `count` * `size_of::<T>()` and an alignment of /// a size of `count` * `size_of::<T>()` and an alignment of
/// `min_align_of::<T>()` /// `min_align_of::<T>()`
/// ///
/// The volatile parameter is set to `true`, so it will not be optimized out
/// unless size is equal to zero.
///
/// This intrinsic does not have a stable counterpart. /// This intrinsic does not have a stable counterpart.
/// # Safety
///
/// The safety requirements are consistent with [`copy_nonoverlapping`]
/// while the read and write behaviors are volatile,
/// which means it will not be optimized out unless `_count` or `size_of::<T>()` is equal to zero.
///
/// [`copy_nonoverlapping`]: ptr::copy_nonoverlapping
#[rustc_intrinsic] #[rustc_intrinsic]
#[rustc_nounwind] #[rustc_nounwind]
pub unsafe fn volatile_copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T, count: usize); pub unsafe fn volatile_copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T, count: usize);
@ -1796,10 +1800,13 @@ pub unsafe fn volatile_copy_memory<T>(dst: *mut T, src: *const T, count: usize);
/// size of `count * size_of::<T>()` and an alignment of /// size of `count * size_of::<T>()` and an alignment of
/// `min_align_of::<T>()`. /// `min_align_of::<T>()`.
/// ///
/// The volatile parameter is set to `true`, so it will not be optimized out
/// unless size is equal to zero.
///
/// This intrinsic does not have a stable counterpart. /// This intrinsic does not have a stable counterpart.
/// # Safety
///
/// The safety requirements are consistent with [`write_bytes`] while the write behavior is volatile,
/// which means it will not be optimized out unless `_count` or `size_of::<T>()` is equal to zero.
///
/// [`write_bytes`]: ptr::write_bytes
#[rustc_intrinsic] #[rustc_intrinsic]
#[rustc_nounwind] #[rustc_nounwind]
pub unsafe fn volatile_set_memory<T>(dst: *mut T, val: u8, count: usize); pub unsafe fn volatile_set_memory<T>(dst: *mut T, val: u8, count: usize);
@ -3341,8 +3348,18 @@ pub const fn is_val_statically_known<T: Copy>(_arg: T) -> bool {
/// The stabilized form of this intrinsic is [`crate::mem::swap`]. /// The stabilized form of this intrinsic is [`crate::mem::swap`].
/// ///
/// # Safety /// # Safety
/// Behavior is undefined if any of the following conditions are violated:
/// ///
/// `x` and `y` are readable and writable as `T`, and non-overlapping. /// * Both `x` and `y` must be [valid] for both reads and writes.
///
/// * Both `x` and `y` must be properly aligned.
///
/// * The region of memory beginning at `x` must *not* overlap with the region of memory
/// beginning at `y`.
///
/// * The memory pointed by `x` and `y` must both contain values of type `T`.
///
/// [valid]: crate::ptr#safety
#[rustc_nounwind] #[rustc_nounwind]
#[inline] #[inline]
#[rustc_intrinsic] #[rustc_intrinsic]

View file

@ -14,7 +14,7 @@ use crate::ops::Try;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
#[must_use = "iterators are lazy and do nothing unless consumed"] #[must_use = "iterators are lazy and do nothing unless consumed"]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "Enumerate")] #[rustc_diagnostic_item = "Enumerate"]
pub struct Enumerate<I> { pub struct Enumerate<I> {
iter: I, iter: I,
count: usize, count: usize,

View file

@ -56,7 +56,7 @@ use crate::num::NonZero;
/// ``` /// ```
#[inline] #[inline]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "iter_repeat")] #[rustc_diagnostic_item = "iter_repeat"]
pub fn repeat<T: Clone>(elt: T) -> Repeat<T> { pub fn repeat<T: Clone>(elt: T) -> Repeat<T> {
Repeat { element: elt } Repeat { element: elt }
} }

View file

@ -37,7 +37,7 @@ use crate::ops::{ControlFlow, Try};
/// assert_eq!(None, iter.next_back()); /// assert_eq!(None, iter.next_back());
/// ``` /// ```
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "DoubleEndedIterator")] #[rustc_diagnostic_item = "DoubleEndedIterator"]
pub trait DoubleEndedIterator: Iterator { pub trait DoubleEndedIterator: Iterator {
/// Removes and returns an element from the end of the iterator. /// Removes and returns an element from the end of the iterator.
/// ///

View file

@ -862,7 +862,7 @@ pub trait Iterator {
/// Note that `iter.filter(f).next()` is equivalent to `iter.find(f)`. /// Note that `iter.filter(f).next()` is equivalent to `iter.find(f)`.
#[inline] #[inline]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "iter_filter")] #[rustc_diagnostic_item = "iter_filter"]
fn filter<P>(self, predicate: P) -> Filter<Self, P> fn filter<P>(self, predicate: P) -> Filter<Self, P>
where where
Self: Sized, Self: Sized,
@ -954,7 +954,7 @@ pub trait Iterator {
/// ``` /// ```
#[inline] #[inline]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "enumerate_method")] #[rustc_diagnostic_item = "enumerate_method"]
fn enumerate(self) -> Enumerate<Self> fn enumerate(self) -> Enumerate<Self>
where where
Self: Sized, Self: Sized,
@ -1972,11 +1972,20 @@ pub trait Iterator {
#[inline] #[inline]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[must_use = "if you really need to exhaust the iterator, consider `.for_each(drop)` instead"] #[must_use = "if you really need to exhaust the iterator, consider `.for_each(drop)` instead"]
#[cfg_attr(not(test), rustc_diagnostic_item = "iterator_collect_fn")] #[rustc_diagnostic_item = "iterator_collect_fn"]
fn collect<B: FromIterator<Self::Item>>(self) -> B fn collect<B: FromIterator<Self::Item>>(self) -> B
where where
Self: Sized, Self: Sized,
{ {
// This is too aggressive to turn on for everything all the time, but PR#137908
// accidentally noticed that some rustc iterators had malformed `size_hint`s,
// so this will help catch such things in debug-assertions-std runners,
// even if users won't actually ever see it.
if cfg!(debug_assertions) {
let hint = self.size_hint();
assert!(hint.1.is_none_or(|high| high >= hint.0), "Malformed size_hint {hint:?}");
}
FromIterator::from_iter(self) FromIterator::from_iter(self)
} }
@ -3367,7 +3376,7 @@ pub trait Iterator {
/// assert_eq!(v_map, vec![1, 2, 3]); /// assert_eq!(v_map, vec![1, 2, 3]);
/// ``` /// ```
#[stable(feature = "iter_copied", since = "1.36.0")] #[stable(feature = "iter_copied", since = "1.36.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "iter_copied")] #[rustc_diagnostic_item = "iter_copied"]
fn copied<'a, T: 'a>(self) -> Copied<Self> fn copied<'a, T: 'a>(self) -> Copied<Self>
where where
Self: Sized + Iterator<Item = &'a T>, Self: Sized + Iterator<Item = &'a T>,
@ -3415,7 +3424,7 @@ pub trait Iterator {
/// assert_eq!(&[vec![23]], &faster[..]); /// assert_eq!(&[vec![23]], &faster[..]);
/// ``` /// ```
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "iter_cloned")] #[rustc_diagnostic_item = "iter_cloned"]
fn cloned<'a, T: 'a>(self) -> Cloned<Self> fn cloned<'a, T: 'a>(self) -> Cloned<Self>
where where
Self: Sized + Iterator<Item = &'a T>, Self: Sized + Iterator<Item = &'a T>,

View file

@ -43,18 +43,6 @@
//! which do not trigger a panic can be assured that this function is never //! which do not trigger a panic can be assured that this function is never
//! called. The `lang` attribute is called `eh_personality`. //! called. The `lang` attribute is called `eh_personality`.
// Since core defines many fundamental lang items, all tests live in a
// separate crate, coretests (library/coretests), to avoid bizarre issues.
//
// Here we explicitly #[cfg]-out this whole crate when testing. If we don't do
// this, both the generated test artifact and the linked libtest (which
// transitively includes core) will both define the same set of lang items,
// and this will cause the E0152 "found duplicate lang item" error. See
// discussion in #50466 for details.
//
// This cfg won't affect doc tests.
#![cfg(not(test))]
//
#![stable(feature = "core", since = "1.6.0")] #![stable(feature = "core", since = "1.6.0")]
#![doc( #![doc(
html_playground_url = "https://play.rust-lang.org/", html_playground_url = "https://play.rust-lang.org/",
@ -64,7 +52,6 @@
)] )]
#![doc(rust_logo)] #![doc(rust_logo)]
#![doc(cfg_hide( #![doc(cfg_hide(
not(test),
no_fp_fmt_parse, no_fp_fmt_parse,
target_pointer_width = "16", target_pointer_width = "16",
target_pointer_width = "32", target_pointer_width = "32",
@ -228,13 +215,9 @@ extern crate self as core;
#[allow(unused)] #[allow(unused)]
use prelude::rust_2024::*; use prelude::rust_2024::*;
#[cfg(not(test))] // See #65860
#[macro_use] #[macro_use]
mod macros; mod macros;
// We don't export this through #[macro_export] for now, to avoid breakage.
// See https://github.com/rust-lang/rust/issues/82913
#[cfg(not(test))]
#[unstable(feature = "assert_matches", issue = "82775")] #[unstable(feature = "assert_matches", issue = "82775")]
/// Unstable module containing the unstable `assert_matches` macro. /// Unstable module containing the unstable `assert_matches` macro.
pub mod assert_matches { pub mod assert_matches {

View file

@ -37,7 +37,7 @@ macro_rules! panic {
/// ``` /// ```
#[macro_export] #[macro_export]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "assert_eq_macro")] #[rustc_diagnostic_item = "assert_eq_macro"]
#[allow_internal_unstable(panic_internals)] #[allow_internal_unstable(panic_internals)]
macro_rules! assert_eq { macro_rules! assert_eq {
($left:expr, $right:expr $(,)?) => { ($left:expr, $right:expr $(,)?) => {
@ -93,7 +93,7 @@ macro_rules! assert_eq {
/// ``` /// ```
#[macro_export] #[macro_export]
#[stable(feature = "assert_ne", since = "1.13.0")] #[stable(feature = "assert_ne", since = "1.13.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "assert_ne_macro")] #[rustc_diagnostic_item = "assert_ne_macro"]
#[allow_internal_unstable(panic_internals)] #[allow_internal_unstable(panic_internals)]
macro_rules! assert_ne { macro_rules! assert_ne {
($left:expr, $right:expr $(,)?) => { ($left:expr, $right:expr $(,)?) => {
@ -331,7 +331,7 @@ macro_rules! debug_assert {
/// ``` /// ```
#[macro_export] #[macro_export]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "debug_assert_eq_macro")] #[rustc_diagnostic_item = "debug_assert_eq_macro"]
macro_rules! debug_assert_eq { macro_rules! debug_assert_eq {
($($arg:tt)*) => { ($($arg:tt)*) => {
if $crate::cfg!(debug_assertions) { if $crate::cfg!(debug_assertions) {
@ -361,7 +361,7 @@ macro_rules! debug_assert_eq {
/// ``` /// ```
#[macro_export] #[macro_export]
#[stable(feature = "assert_ne", since = "1.13.0")] #[stable(feature = "assert_ne", since = "1.13.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "debug_assert_ne_macro")] #[rustc_diagnostic_item = "debug_assert_ne_macro"]
macro_rules! debug_assert_ne { macro_rules! debug_assert_ne {
($($arg:tt)*) => { ($($arg:tt)*) => {
if $crate::cfg!(debug_assertions) { if $crate::cfg!(debug_assertions) {
@ -442,7 +442,7 @@ pub macro debug_assert_matches($($arg:tt)*) {
/// ``` /// ```
#[macro_export] #[macro_export]
#[stable(feature = "matches_macro", since = "1.42.0")] #[stable(feature = "matches_macro", since = "1.42.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "matches_macro")] #[rustc_diagnostic_item = "matches_macro"]
macro_rules! matches { macro_rules! matches {
($expression:expr, $pattern:pat $(if $guard:expr)? $(,)?) => { ($expression:expr, $pattern:pat $(if $guard:expr)? $(,)?) => {
match $expression { match $expression {
@ -617,7 +617,7 @@ macro_rules! r#try {
/// ``` /// ```
#[macro_export] #[macro_export]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "write_macro")] #[rustc_diagnostic_item = "write_macro"]
macro_rules! write { macro_rules! write {
($dst:expr, $($arg:tt)*) => { ($dst:expr, $($arg:tt)*) => {
$dst.write_fmt($crate::format_args!($($arg)*)) $dst.write_fmt($crate::format_args!($($arg)*))
@ -651,7 +651,7 @@ macro_rules! write {
/// ``` /// ```
#[macro_export] #[macro_export]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "writeln_macro")] #[rustc_diagnostic_item = "writeln_macro"]
#[allow_internal_unstable(format_args_nl)] #[allow_internal_unstable(format_args_nl)]
macro_rules! writeln { macro_rules! writeln {
($dst:expr $(,)?) => { ($dst:expr $(,)?) => {
@ -718,7 +718,7 @@ macro_rules! writeln {
#[rustc_builtin_macro(unreachable)] #[rustc_builtin_macro(unreachable)]
#[allow_internal_unstable(edition_panic)] #[allow_internal_unstable(edition_panic)]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "unreachable_macro")] #[rustc_diagnostic_item = "unreachable_macro"]
macro_rules! unreachable { macro_rules! unreachable {
// Expands to either `$crate::panic::unreachable_2015` or `$crate::panic::unreachable_2021` // Expands to either `$crate::panic::unreachable_2015` or `$crate::panic::unreachable_2021`
// depending on the edition of the caller. // depending on the edition of the caller.
@ -803,7 +803,7 @@ macro_rules! unreachable {
/// ``` /// ```
#[macro_export] #[macro_export]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "unimplemented_macro")] #[rustc_diagnostic_item = "unimplemented_macro"]
#[allow_internal_unstable(panic_internals)] #[allow_internal_unstable(panic_internals)]
macro_rules! unimplemented { macro_rules! unimplemented {
() => { () => {
@ -883,7 +883,7 @@ macro_rules! unimplemented {
/// ``` /// ```
#[macro_export] #[macro_export]
#[stable(feature = "todo_macro", since = "1.40.0")] #[stable(feature = "todo_macro", since = "1.40.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "todo_macro")] #[rustc_diagnostic_item = "todo_macro"]
#[allow_internal_unstable(panic_internals)] #[allow_internal_unstable(panic_internals)]
macro_rules! todo { macro_rules! todo {
() => { () => {
@ -995,7 +995,7 @@ pub(crate) mod builtin {
/// and cannot be stored for later use. /// and cannot be stored for later use.
/// This is a known limitation, see [#92698](https://github.com/rust-lang/rust/issues/92698). /// This is a known limitation, see [#92698](https://github.com/rust-lang/rust/issues/92698).
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "format_args_macro")] #[rustc_diagnostic_item = "format_args_macro"]
#[allow_internal_unsafe] #[allow_internal_unsafe]
#[allow_internal_unstable(fmt_internals)] #[allow_internal_unstable(fmt_internals)]
#[rustc_builtin_macro] #[rustc_builtin_macro]
@ -1342,7 +1342,7 @@ pub(crate) mod builtin {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[rustc_builtin_macro] #[rustc_builtin_macro]
#[macro_export] #[macro_export]
#[cfg_attr(not(test), rustc_diagnostic_item = "include_str_macro")] #[rustc_diagnostic_item = "include_str_macro"]
macro_rules! include_str { macro_rules! include_str {
($file:expr $(,)?) => {{ /* compiler built-in */ }}; ($file:expr $(,)?) => {{ /* compiler built-in */ }};
} }
@ -1382,7 +1382,7 @@ pub(crate) mod builtin {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[rustc_builtin_macro] #[rustc_builtin_macro]
#[macro_export] #[macro_export]
#[cfg_attr(not(test), rustc_diagnostic_item = "include_bytes_macro")] #[rustc_diagnostic_item = "include_bytes_macro"]
macro_rules! include_bytes { macro_rules! include_bytes {
($file:expr $(,)?) => {{ /* compiler built-in */ }}; ($file:expr $(,)?) => {{ /* compiler built-in */ }};
} }

View file

@ -82,7 +82,7 @@ macro marker_impls {
/// [arc]: ../../std/sync/struct.Arc.html /// [arc]: ../../std/sync/struct.Arc.html
/// [ub]: ../../reference/behavior-considered-undefined.html /// [ub]: ../../reference/behavior-considered-undefined.html
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "Send")] #[rustc_diagnostic_item = "Send"]
#[diagnostic::on_unimplemented( #[diagnostic::on_unimplemented(
message = "`{Self}` cannot be sent between threads safely", message = "`{Self}` cannot be sent between threads safely",
label = "`{Self}` cannot be sent between threads safely" label = "`{Self}` cannot be sent between threads safely"
@ -545,7 +545,7 @@ pub trait BikeshedGuaranteedNoDrop {}
/// [transmute]: crate::mem::transmute /// [transmute]: crate::mem::transmute
/// [nomicon-send-and-sync]: ../../nomicon/send-and-sync.html /// [nomicon-send-and-sync]: ../../nomicon/send-and-sync.html
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "Sync")] #[rustc_diagnostic_item = "Sync"]
#[lang = "sync"] #[lang = "sync"]
#[rustc_on_unimplemented( #[rustc_on_unimplemented(
on( on(
@ -1305,7 +1305,7 @@ pub trait FnPtr: Copy + Clone {
/// ``` /// ```
#[rustc_builtin_macro(CoercePointee, attributes(pointee))] #[rustc_builtin_macro(CoercePointee, attributes(pointee))]
#[allow_internal_unstable(dispatch_from_dyn, coerce_unsized, unsize, coerce_pointee_validated)] #[allow_internal_unstable(dispatch_from_dyn, coerce_unsized, unsize, coerce_pointee_validated)]
#[cfg_attr(not(test), rustc_diagnostic_item = "CoercePointee")] #[rustc_diagnostic_item = "CoercePointee"]
#[unstable(feature = "derive_coerce_pointee", issue = "123430")] #[unstable(feature = "derive_coerce_pointee", issue = "123430")]
pub macro CoercePointee($item:item) { pub macro CoercePointee($item:item) {
/* compiler built-in */ /* compiler built-in */

View file

@ -140,7 +140,7 @@ pub use crate::intrinsics::transmute;
#[inline] #[inline]
#[rustc_const_stable(feature = "const_forget", since = "1.46.0")] #[rustc_const_stable(feature = "const_forget", since = "1.46.0")]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "mem_forget")] #[rustc_diagnostic_item = "mem_forget"]
pub const fn forget<T>(t: T) { pub const fn forget<T>(t: T) {
let _ = ManuallyDrop::new(t); let _ = ManuallyDrop::new(t);
} }
@ -300,7 +300,7 @@ pub fn forget_unsized<T: ?Sized>(t: T) {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[rustc_promotable] #[rustc_promotable]
#[rustc_const_stable(feature = "const_mem_size_of", since = "1.24.0")] #[rustc_const_stable(feature = "const_mem_size_of", since = "1.24.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "mem_size_of")] #[rustc_diagnostic_item = "mem_size_of"]
pub const fn size_of<T>() -> usize { pub const fn size_of<T>() -> usize {
intrinsics::size_of::<T>() intrinsics::size_of::<T>()
} }
@ -328,7 +328,7 @@ pub const fn size_of<T>() -> usize {
#[must_use] #[must_use]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_size_of_val", since = "1.85.0")] #[rustc_const_stable(feature = "const_size_of_val", since = "1.85.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "mem_size_of_val")] #[rustc_diagnostic_item = "mem_size_of_val"]
pub const fn size_of_val<T: ?Sized>(val: &T) -> usize { pub const fn size_of_val<T: ?Sized>(val: &T) -> usize {
// SAFETY: `val` is a reference, so it's a valid raw pointer // SAFETY: `val` is a reference, so it's a valid raw pointer
unsafe { intrinsics::size_of_val(val) } unsafe { intrinsics::size_of_val(val) }
@ -846,7 +846,7 @@ pub fn take<T: Default>(dest: &mut T) -> T {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[must_use = "if you don't need the old value, you can just assign the new value directly"] #[must_use = "if you don't need the old value, you can just assign the new value directly"]
#[rustc_const_stable(feature = "const_replace", since = "1.83.0")] #[rustc_const_stable(feature = "const_replace", since = "1.83.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "mem_replace")] #[rustc_diagnostic_item = "mem_replace"]
pub const fn replace<T>(dest: &mut T, src: T) -> T { pub const fn replace<T>(dest: &mut T, src: T) -> T {
// It may be tempting to use `swap` to avoid `unsafe` here. Don't! // It may be tempting to use `swap` to avoid `unsafe` here. Don't!
// The compiler optimizes the implementation below to two `memcpy`s // The compiler optimizes the implementation below to two `memcpy`s
@ -931,7 +931,7 @@ pub const fn replace<T>(dest: &mut T, src: T) -> T {
/// [`RefCell`]: crate::cell::RefCell /// [`RefCell`]: crate::cell::RefCell
#[inline] #[inline]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "mem_drop")] #[rustc_diagnostic_item = "mem_drop"]
pub fn drop<T>(_x: T) {} pub fn drop<T>(_x: T) {}
/// Bitwise-copies a value. /// Bitwise-copies a value.
@ -1154,7 +1154,7 @@ impl<T> fmt::Debug for Discriminant<T> {
/// ``` /// ```
#[stable(feature = "discriminant_value", since = "1.21.0")] #[stable(feature = "discriminant_value", since = "1.21.0")]
#[rustc_const_stable(feature = "const_discriminant", since = "1.75.0")] #[rustc_const_stable(feature = "const_discriminant", since = "1.75.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "mem_discriminant")] #[rustc_diagnostic_item = "mem_discriminant"]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
pub const fn discriminant<T>(v: &T) -> Discriminant<T> { pub const fn discriminant<T>(v: &T) -> Discriminant<T> {
Discriminant(intrinsics::discriminant_value(v)) Discriminant(intrinsics::discriminant_value(v))
@ -1254,42 +1254,56 @@ impl<T> SizedTypeProperties for T {}
/// Expands to the offset in bytes of a field from the beginning of the given type. /// Expands to the offset in bytes of a field from the beginning of the given type.
/// ///
/// Structs, enums, unions and tuples are supported. /// The type may be a `struct`, `enum`, `union`, or tuple.
/// ///
/// Nested field accesses may be used, but not array indexes. /// The field may be a nested field (`field1.field2`), but not an array index.
/// The field must be visible to the call site.
/// ///
/// If the nightly-only feature `offset_of_enum` is enabled, /// The offset is returned as a [`usize`].
/// variants may be traversed as if they were fields.
/// Variants themselves do not have an offset.
/// ///
/// Visibility is respected - all types and fields must be visible to the call site: /// # Offsets of, and in, dynamically sized types
/// ///
/// ``` /// The fields type must be [`Sized`], but it may be located in a [dynamically sized] container.
/// mod nested { /// If the field type is dynamically sized, then you cannot use `offset_of!` (since the field's
/// #[repr(C)] /// alignment, and therefore its offset, may also be dynamic) and must take the offset from an
/// pub struct Struct { /// actual pointer to the container instead.
/// private: u8,
/// }
/// }
/// ///
/// // assert_eq!(mem::offset_of!(nested::Struct, private), 0);
/// // ^^^ error[E0616]: field `private` of struct `Struct` is private
/// ```
///
/// Only [`Sized`] fields are supported, but the container may be unsized:
/// ``` /// ```
/// # use core::mem; /// # use core::mem;
/// # use core::fmt::Debug;
/// #[repr(C)] /// #[repr(C)]
/// pub struct Struct { /// pub struct Struct<T: ?Sized> {
/// a: u8, /// a: u8,
/// b: [u8], /// b: T,
/// } /// }
/// ///
/// assert_eq!(mem::offset_of!(Struct, a), 0); // OK /// #[derive(Debug)]
/// // assert_eq!(mem::offset_of!(Struct, b), 1); /// #[repr(C, align(4))]
/// // ^^^ error[E0277]: doesn't have a size known at compile-time /// struct Align4(u32);
///
/// assert_eq!(mem::offset_of!(Struct<dyn Debug>, a), 0); // OK — Sized field
/// assert_eq!(mem::offset_of!(Struct<Align4>, b), 4); // OK — not DST
///
/// // assert_eq!(mem::offset_of!(Struct<dyn Debug>, b), 1);
/// // ^^^ error[E0277]: ... cannot be known at compilation time
///
/// // To obtain the offset of a !Sized field, examine a concrete value
/// // instead of using offset_of!.
/// let value: Struct<Align4> = Struct { a: 1, b: Align4(2) };
/// let ref_unsized: &Struct<dyn Debug> = &value;
/// let offset_of_b = unsafe {
/// (&raw const ref_unsized.b).byte_offset_from_unsigned(ref_unsized)
/// };
/// assert_eq!(offset_of_b, 4);
/// ``` /// ```
/// ///
/// If you need to obtain the offset of a field of a `!Sized` type, then, since the offset may
/// depend on the particular value being stored (in particular, `dyn Trait` values have a
/// dynamically-determined alignment), you must retrieve the offset from a specific reference
/// or pointer, and so you cannot use `offset_of!` to work without one.
///
/// # Layout is subject to change
///
/// Note that type layout is, in general, [subject to change and /// Note that type layout is, in general, [subject to change and
/// platform-specific](https://doc.rust-lang.org/reference/type-layout.html). If /// platform-specific](https://doc.rust-lang.org/reference/type-layout.html). If
/// layout stability is required, consider using an [explicit `repr` attribute]. /// layout stability is required, consider using an [explicit `repr` attribute].
@ -1325,11 +1339,16 @@ impl<T> SizedTypeProperties for T {}
/// ///
/// [explicit `repr` attribute]: https://doc.rust-lang.org/reference/type-layout.html#representations /// [explicit `repr` attribute]: https://doc.rust-lang.org/reference/type-layout.html#representations
/// ///
/// # Unstable features
///
/// The following unstable features expand the functionality of `offset_of!`:
///
/// * [`offset_of_enum`] — allows `enum` variants to be traversed as if they were fields.
/// * [`offset_of_slice`] — allows getting the offset of a field of type `[T]`.
///
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// #![feature(offset_of_enum)]
///
/// use std::mem; /// use std::mem;
/// #[repr(C)] /// #[repr(C)]
/// struct FieldStruct { /// struct FieldStruct {
@ -1351,18 +1370,11 @@ impl<T> SizedTypeProperties for T {}
/// struct NestedB(u8); /// struct NestedB(u8);
/// ///
/// assert_eq!(mem::offset_of!(NestedA, b.0), 0); /// assert_eq!(mem::offset_of!(NestedA, b.0), 0);
///
/// #[repr(u8)]
/// enum Enum {
/// A(u8, u16),
/// B { one: u8, two: u16 },
/// }
///
/// assert_eq!(mem::offset_of!(Enum, A.0), 1);
/// assert_eq!(mem::offset_of!(Enum, B.two), 2);
///
/// assert_eq!(mem::offset_of!(Option<&u8>, Some.0), 0);
/// ``` /// ```
///
/// [dynamically sized]: https://doc.rust-lang.org/reference/dynamically-sized-types.html
/// [`offset_of_enum`]: https://doc.rust-lang.org/nightly/unstable-book/language-features/offset-of-enum.html
/// [`offset_of_slice`]: https://doc.rust-lang.org/nightly/unstable-book/language-features/offset-of-slice.html
#[stable(feature = "offset_of", since = "1.77.0")] #[stable(feature = "offset_of", since = "1.77.0")]
#[allow_internal_unstable(builtin_syntax)] #[allow_internal_unstable(builtin_syntax)]
pub macro offset_of($Container:ty, $($fields:expr)+ $(,)?) { pub macro offset_of($Container:ty, $($fields:expr)+ $(,)?) {

View file

@ -25,7 +25,7 @@ use crate::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, Not};
/// assert_eq!(localhost_v4.is_ipv6(), false); /// assert_eq!(localhost_v4.is_ipv6(), false);
/// assert_eq!(localhost_v4.is_ipv4(), true); /// assert_eq!(localhost_v4.is_ipv4(), true);
/// ``` /// ```
#[cfg_attr(not(test), rustc_diagnostic_item = "IpAddr")] #[rustc_diagnostic_item = "IpAddr"]
#[stable(feature = "ip_addr", since = "1.7.0")] #[stable(feature = "ip_addr", since = "1.7.0")]
#[derive(Copy, Clone, Eq, PartialEq, Hash, PartialOrd, Ord)] #[derive(Copy, Clone, Eq, PartialEq, Hash, PartialOrd, Ord)]
pub enum IpAddr { pub enum IpAddr {

View file

@ -12,11 +12,9 @@
#![unstable(feature = "f128", issue = "116909")] #![unstable(feature = "f128", issue = "116909")]
use crate::convert::FloatToInt; use crate::convert::FloatToInt;
#[cfg(not(test))]
use crate::intrinsics;
use crate::mem;
use crate::num::FpCategory; use crate::num::FpCategory;
use crate::panic::const_assert; use crate::panic::const_assert;
use crate::{intrinsics, mem};
/// Basic mathematical constants. /// Basic mathematical constants.
#[unstable(feature = "f128", issue = "116909")] #[unstable(feature = "f128", issue = "116909")]
@ -138,7 +136,6 @@ pub mod consts {
pub const LN_10: f128 = 2.30258509299404568401799145468436420760110148862877297603333_f128; pub const LN_10: f128 = 2.30258509299404568401799145468436420760110148862877297603333_f128;
} }
#[cfg(not(test))]
impl f128 { impl f128 {
// FIXME(f16_f128): almost all methods in this `impl` are missing examples and a const // FIXME(f16_f128): almost all methods in this `impl` are missing examples and a const
// implementation. Add these once we can run code on all platforms and have f16/f128 in CTFE. // implementation. Add these once we can run code on all platforms and have f16/f128 in CTFE.

View file

@ -12,11 +12,9 @@
#![unstable(feature = "f16", issue = "116909")] #![unstable(feature = "f16", issue = "116909")]
use crate::convert::FloatToInt; use crate::convert::FloatToInt;
#[cfg(not(test))]
use crate::intrinsics;
use crate::mem;
use crate::num::FpCategory; use crate::num::FpCategory;
use crate::panic::const_assert; use crate::panic::const_assert;
use crate::{intrinsics, mem};
/// Basic mathematical constants. /// Basic mathematical constants.
#[unstable(feature = "f16", issue = "116909")] #[unstable(feature = "f16", issue = "116909")]
@ -133,7 +131,6 @@ pub mod consts {
pub const LN_10: f16 = 2.30258509299404568401799145468436421_f16; pub const LN_10: f16 = 2.30258509299404568401799145468436421_f16;
} }
#[cfg(not(test))]
impl f16 { impl f16 {
// FIXME(f16_f128): almost all methods in this `impl` are missing examples and a const // FIXME(f16_f128): almost all methods in this `impl` are missing examples and a const
// implementation. Add these once we can run code on all platforms and have f16/f128 in CTFE. // implementation. Add these once we can run code on all platforms and have f16/f128 in CTFE.

View file

@ -12,11 +12,9 @@
#![stable(feature = "rust1", since = "1.0.0")] #![stable(feature = "rust1", since = "1.0.0")]
use crate::convert::FloatToInt; use crate::convert::FloatToInt;
#[cfg(not(test))]
use crate::intrinsics;
use crate::mem;
use crate::num::FpCategory; use crate::num::FpCategory;
use crate::panic::const_assert; use crate::panic::const_assert;
use crate::{intrinsics, mem};
/// The radix or base of the internal representation of `f32`. /// The radix or base of the internal representation of `f32`.
/// Use [`f32::RADIX`] instead. /// Use [`f32::RADIX`] instead.
@ -386,7 +384,6 @@ pub mod consts {
pub const LN_10: f32 = 2.30258509299404568401799145468436421_f32; pub const LN_10: f32 = 2.30258509299404568401799145468436421_f32;
} }
#[cfg(not(test))]
impl f32 { impl f32 {
/// The radix or base of the internal representation of `f32`. /// The radix or base of the internal representation of `f32`.
#[stable(feature = "assoc_int_consts", since = "1.43.0")] #[stable(feature = "assoc_int_consts", since = "1.43.0")]
@ -416,7 +413,7 @@ impl f32 {
/// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon /// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon
/// [`MANTISSA_DIGITS`]: f32::MANTISSA_DIGITS /// [`MANTISSA_DIGITS`]: f32::MANTISSA_DIGITS
#[stable(feature = "assoc_int_consts", since = "1.43.0")] #[stable(feature = "assoc_int_consts", since = "1.43.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "f32_epsilon")] #[rustc_diagnostic_item = "f32_epsilon"]
pub const EPSILON: f32 = 1.19209290e-07_f32; pub const EPSILON: f32 = 1.19209290e-07_f32;
/// Smallest finite `f32` value. /// Smallest finite `f32` value.

View file

@ -12,11 +12,9 @@
#![stable(feature = "rust1", since = "1.0.0")] #![stable(feature = "rust1", since = "1.0.0")]
use crate::convert::FloatToInt; use crate::convert::FloatToInt;
#[cfg(not(test))]
use crate::intrinsics;
use crate::mem;
use crate::num::FpCategory; use crate::num::FpCategory;
use crate::panic::const_assert; use crate::panic::const_assert;
use crate::{intrinsics, mem};
/// The radix or base of the internal representation of `f64`. /// The radix or base of the internal representation of `f64`.
/// Use [`f64::RADIX`] instead. /// Use [`f64::RADIX`] instead.
@ -386,7 +384,6 @@ pub mod consts {
pub const LN_10: f64 = 2.30258509299404568401799145468436421_f64; pub const LN_10: f64 = 2.30258509299404568401799145468436421_f64;
} }
#[cfg(not(test))]
impl f64 { impl f64 {
/// The radix or base of the internal representation of `f64`. /// The radix or base of the internal representation of `f64`.
#[stable(feature = "assoc_int_consts", since = "1.43.0")] #[stable(feature = "assoc_int_consts", since = "1.43.0")]
@ -415,7 +412,7 @@ impl f64 {
/// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon /// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon
/// [`MANTISSA_DIGITS`]: f64::MANTISSA_DIGITS /// [`MANTISSA_DIGITS`]: f64::MANTISSA_DIGITS
#[stable(feature = "assoc_int_consts", since = "1.43.0")] #[stable(feature = "assoc_int_consts", since = "1.43.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "f64_epsilon")] #[rustc_diagnostic_item = "f64_epsilon"]
pub const EPSILON: f64 = 2.2204460492503131e-16_f64; pub const EPSILON: f64 = 2.2204460492503131e-16_f64;
/// Smallest finite `f64` value. /// Smallest finite `f64` value.

View file

@ -79,7 +79,7 @@ use crate::{convert, ops};
/// [`Break`]: ControlFlow::Break /// [`Break`]: ControlFlow::Break
/// [`Continue`]: ControlFlow::Continue /// [`Continue`]: ControlFlow::Continue
#[stable(feature = "control_flow_enum_type", since = "1.55.0")] #[stable(feature = "control_flow_enum_type", since = "1.55.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "ControlFlow")] #[rustc_diagnostic_item = "ControlFlow"]
// ControlFlow should not implement PartialOrd or Ord, per RFC 3058: // ControlFlow should not implement PartialOrd or Ord, per RFC 3058:
// https://rust-lang.github.io/rfcs/3058-try-trait-v2.html#traits-for-controlflow // https://rust-lang.github.io/rfcs/3058-try-trait-v2.html#traits-for-controlflow
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]

View file

@ -924,7 +924,7 @@ impl<T> Option<T> {
#[inline] #[inline]
#[track_caller] #[track_caller]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "option_expect")] #[rustc_diagnostic_item = "option_expect"]
#[rustc_allow_const_fn_unstable(const_precise_live_drops)] #[rustc_allow_const_fn_unstable(const_precise_live_drops)]
#[rustc_const_stable(feature = "const_option", since = "1.83.0")] #[rustc_const_stable(feature = "const_option", since = "1.83.0")]
pub const fn expect(self, msg: &str) -> T { pub const fn expect(self, msg: &str) -> T {
@ -969,7 +969,7 @@ impl<T> Option<T> {
#[inline(always)] #[inline(always)]
#[track_caller] #[track_caller]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "option_unwrap")] #[rustc_diagnostic_item = "option_unwrap"]
#[rustc_allow_const_fn_unstable(const_precise_live_drops)] #[rustc_allow_const_fn_unstable(const_precise_live_drops)]
#[rustc_const_stable(feature = "const_option", since = "1.83.0")] #[rustc_const_stable(feature = "const_option", since = "1.83.0")]
pub const fn unwrap(self) -> T { pub const fn unwrap(self) -> T {

View file

@ -82,7 +82,7 @@ use crate::task::{Context, Poll};
/// [`AssertUnwindSafe`] wrapper struct can be used to force this trait to be /// [`AssertUnwindSafe`] wrapper struct can be used to force this trait to be
/// implemented for any closed over variables passed to `catch_unwind`. /// implemented for any closed over variables passed to `catch_unwind`.
#[stable(feature = "catch_unwind", since = "1.9.0")] #[stable(feature = "catch_unwind", since = "1.9.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "unwind_safe_trait")] #[rustc_diagnostic_item = "unwind_safe_trait"]
#[diagnostic::on_unimplemented( #[diagnostic::on_unimplemented(
message = "the type `{Self}` may not be safely transferred across an unwind boundary", message = "the type `{Self}` may not be safely transferred across an unwind boundary",
label = "`{Self}` may not be safely transferred across an unwind boundary" label = "`{Self}` may not be safely transferred across an unwind boundary"
@ -98,7 +98,7 @@ pub auto trait UnwindSafe {}
/// This is a "helper marker trait" used to provide impl blocks for the /// This is a "helper marker trait" used to provide impl blocks for the
/// [`UnwindSafe`] trait, for more information see that documentation. /// [`UnwindSafe`] trait, for more information see that documentation.
#[stable(feature = "catch_unwind", since = "1.9.0")] #[stable(feature = "catch_unwind", since = "1.9.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "ref_unwind_safe_trait")] #[rustc_diagnostic_item = "ref_unwind_safe_trait"]
#[diagnostic::on_unimplemented( #[diagnostic::on_unimplemented(
message = "the type `{Self}` may contain interior mutability and a reference may not be safely \ message = "the type `{Self}` may contain interior mutability and a reference may not be safely \
transferrable across a catch_unwind boundary", transferrable across a catch_unwind boundary",

View file

@ -654,7 +654,7 @@ impl<T, E> Result<T, E> {
/// ``` /// ```
#[inline] #[inline]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "result_ok_method")] #[rustc_diagnostic_item = "result_ok_method"]
pub fn ok(self) -> Option<T> { pub fn ok(self) -> Option<T> {
match self { match self {
Ok(x) => Some(x), Ok(x) => Some(x),

View file

@ -7,7 +7,6 @@ use crate::fmt::{self, Write};
use crate::intrinsics::const_eval_select; use crate::intrinsics::const_eval_select;
use crate::{ascii, iter, ops}; use crate::{ascii, iter, ops};
#[cfg(not(test))]
impl [u8] { impl [u8] {
/// Checks if all bytes in this slice are within the ASCII range. /// Checks if all bytes in this slice are within the ASCII range.
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")] #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]

View file

@ -97,7 +97,6 @@ enum Direction {
Back, Back,
} }
#[cfg(not(test))]
impl<T> [T] { impl<T> [T] {
/// Returns the number of elements in the slice. /// Returns the number of elements in the slice.
/// ///
@ -1045,7 +1044,7 @@ impl<T> [T] {
/// ``` /// ```
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[inline] #[inline]
#[cfg_attr(not(test), rustc_diagnostic_item = "slice_iter")] #[rustc_diagnostic_item = "slice_iter"]
pub fn iter(&self) -> Iter<'_, T> { pub fn iter(&self) -> Iter<'_, T> {
Iter::new(self) Iter::new(self)
} }
@ -4844,7 +4843,6 @@ impl<T, const N: usize> [[T; N]] {
} }
} }
#[cfg(not(test))]
impl [f32] { impl [f32] {
/// Sorts the slice of floats. /// Sorts the slice of floats.
/// ///
@ -4873,7 +4871,6 @@ impl [f32] {
} }
} }
#[cfg(not(test))]
impl [f64] { impl [f64] {
/// Sorts the slice of floats. /// Sorts the slice of floats.
/// ///

View file

@ -114,7 +114,6 @@ fn slice_error_fail_rt(s: &str, begin: usize, end: usize) -> ! {
); );
} }
#[cfg(not(test))]
impl str { impl str {
/// Returns the length of `self`. /// Returns the length of `self`.
/// ///
@ -134,7 +133,7 @@ impl str {
/// ``` /// ```
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_str_len", since = "1.39.0")] #[rustc_const_stable(feature = "const_str_len", since = "1.39.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "str_len")] #[rustc_diagnostic_item = "str_len"]
#[must_use] #[must_use]
#[inline] #[inline]
pub const fn len(&self) -> usize { pub const fn len(&self) -> usize {
@ -1029,7 +1028,7 @@ impl str {
/// ``` /// ```
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[inline] #[inline]
#[cfg_attr(not(test), rustc_diagnostic_item = "str_chars")] #[rustc_diagnostic_item = "str_chars"]
pub fn chars(&self) -> Chars<'_> { pub fn chars(&self) -> Chars<'_> {
Chars { iter: self.as_bytes().iter() } Chars { iter: self.as_bytes().iter() }
} }
@ -1160,7 +1159,7 @@ impl str {
#[must_use = "this returns the split string as an iterator, \ #[must_use = "this returns the split string as an iterator, \
without modifying the original"] without modifying the original"]
#[stable(feature = "split_whitespace", since = "1.1.0")] #[stable(feature = "split_whitespace", since = "1.1.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "str_split_whitespace")] #[rustc_diagnostic_item = "str_split_whitespace"]
#[inline] #[inline]
pub fn split_whitespace(&self) -> SplitWhitespace<'_> { pub fn split_whitespace(&self) -> SplitWhitespace<'_> {
SplitWhitespace { inner: self.split(IsWhitespace).filter(IsNotEmpty) } SplitWhitespace { inner: self.split(IsWhitespace).filter(IsNotEmpty) }
@ -1355,7 +1354,7 @@ impl str {
/// assert!(bananas.starts_with(&['a', 'b', 'c', 'd'])); /// assert!(bananas.starts_with(&['a', 'b', 'c', 'd']));
/// ``` /// ```
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "str_starts_with")] #[rustc_diagnostic_item = "str_starts_with"]
pub fn starts_with<P: Pattern>(&self, pat: P) -> bool { pub fn starts_with<P: Pattern>(&self, pat: P) -> bool {
pat.is_prefix_of(self) pat.is_prefix_of(self)
} }
@ -1380,7 +1379,7 @@ impl str {
/// assert!(!bananas.ends_with("nana")); /// assert!(!bananas.ends_with("nana"));
/// ``` /// ```
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "str_ends_with")] #[rustc_diagnostic_item = "str_ends_with"]
pub fn ends_with<P: Pattern>(&self, pat: P) -> bool pub fn ends_with<P: Pattern>(&self, pat: P) -> bool
where where
for<'a> P::Searcher<'a>: ReverseSearcher<'a>, for<'a> P::Searcher<'a>: ReverseSearcher<'a>,
@ -2114,7 +2113,7 @@ impl str {
#[must_use = "this returns the trimmed string as a slice, \ #[must_use = "this returns the trimmed string as a slice, \
without modifying the original"] without modifying the original"]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "str_trim")] #[rustc_diagnostic_item = "str_trim"]
pub fn trim(&self) -> &str { pub fn trim(&self) -> &str {
self.trim_matches(|c: char| c.is_whitespace()) self.trim_matches(|c: char| c.is_whitespace())
} }
@ -2153,7 +2152,7 @@ impl str {
#[must_use = "this returns the trimmed string as a new slice, \ #[must_use = "this returns the trimmed string as a new slice, \
without modifying the original"] without modifying the original"]
#[stable(feature = "trim_direction", since = "1.30.0")] #[stable(feature = "trim_direction", since = "1.30.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "str_trim_start")] #[rustc_diagnostic_item = "str_trim_start"]
pub fn trim_start(&self) -> &str { pub fn trim_start(&self) -> &str {
self.trim_start_matches(|c: char| c.is_whitespace()) self.trim_start_matches(|c: char| c.is_whitespace())
} }
@ -2192,7 +2191,7 @@ impl str {
#[must_use = "this returns the trimmed string as a new slice, \ #[must_use = "this returns the trimmed string as a new slice, \
without modifying the original"] without modifying the original"]
#[stable(feature = "trim_direction", since = "1.30.0")] #[stable(feature = "trim_direction", since = "1.30.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "str_trim_end")] #[rustc_diagnostic_item = "str_trim_end"]
pub fn trim_end(&self) -> &str { pub fn trim_end(&self) -> &str {
self.trim_end_matches(|c: char| c.is_whitespace()) self.trim_end_matches(|c: char| c.is_whitespace())
} }

View file

@ -295,7 +295,7 @@ unsafe impl Sync for AtomicBool {}
/// loads and stores of pointers. Its size depends on the target pointer's size. /// loads and stores of pointers. Its size depends on the target pointer's size.
#[cfg(target_has_atomic_load_store = "ptr")] #[cfg(target_has_atomic_load_store = "ptr")]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "AtomicPtr")] #[rustc_diagnostic_item = "AtomicPtr"]
#[cfg_attr(target_pointer_width = "16", repr(C, align(2)))] #[cfg_attr(target_pointer_width = "16", repr(C, align(2)))]
#[cfg_attr(target_pointer_width = "32", repr(C, align(4)))] #[cfg_attr(target_pointer_width = "32", repr(C, align(4)))]
#[cfg_attr(target_pointer_width = "64", repr(C, align(8)))] #[cfg_attr(target_pointer_width = "64", repr(C, align(8)))]
@ -3446,7 +3446,7 @@ atomic_int! {
stable(feature = "integer_atomics_stable", since = "1.34.0"), stable(feature = "integer_atomics_stable", since = "1.34.0"),
rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"),
rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0"), rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0"),
cfg_attr(not(test), rustc_diagnostic_item = "AtomicI8"), rustc_diagnostic_item = "AtomicI8",
"i8", "i8",
"", "",
atomic_min, atomic_max, atomic_min, atomic_max,
@ -3465,7 +3465,7 @@ atomic_int! {
stable(feature = "integer_atomics_stable", since = "1.34.0"), stable(feature = "integer_atomics_stable", since = "1.34.0"),
rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"),
rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0"), rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0"),
cfg_attr(not(test), rustc_diagnostic_item = "AtomicU8"), rustc_diagnostic_item = "AtomicU8",
"u8", "u8",
"", "",
atomic_umin, atomic_umax, atomic_umin, atomic_umax,
@ -3484,7 +3484,7 @@ atomic_int! {
stable(feature = "integer_atomics_stable", since = "1.34.0"), stable(feature = "integer_atomics_stable", since = "1.34.0"),
rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"),
rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0"), rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0"),
cfg_attr(not(test), rustc_diagnostic_item = "AtomicI16"), rustc_diagnostic_item = "AtomicI16",
"i16", "i16",
"", "",
atomic_min, atomic_max, atomic_min, atomic_max,
@ -3503,7 +3503,7 @@ atomic_int! {
stable(feature = "integer_atomics_stable", since = "1.34.0"), stable(feature = "integer_atomics_stable", since = "1.34.0"),
rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"),
rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0"), rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0"),
cfg_attr(not(test), rustc_diagnostic_item = "AtomicU16"), rustc_diagnostic_item = "AtomicU16",
"u16", "u16",
"", "",
atomic_umin, atomic_umax, atomic_umin, atomic_umax,
@ -3522,7 +3522,7 @@ atomic_int! {
stable(feature = "integer_atomics_stable", since = "1.34.0"), stable(feature = "integer_atomics_stable", since = "1.34.0"),
rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"),
rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0"), rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0"),
cfg_attr(not(test), rustc_diagnostic_item = "AtomicI32"), rustc_diagnostic_item = "AtomicI32",
"i32", "i32",
"", "",
atomic_min, atomic_max, atomic_min, atomic_max,
@ -3541,7 +3541,7 @@ atomic_int! {
stable(feature = "integer_atomics_stable", since = "1.34.0"), stable(feature = "integer_atomics_stable", since = "1.34.0"),
rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"),
rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0"), rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0"),
cfg_attr(not(test), rustc_diagnostic_item = "AtomicU32"), rustc_diagnostic_item = "AtomicU32",
"u32", "u32",
"", "",
atomic_umin, atomic_umax, atomic_umin, atomic_umax,
@ -3560,7 +3560,7 @@ atomic_int! {
stable(feature = "integer_atomics_stable", since = "1.34.0"), stable(feature = "integer_atomics_stable", since = "1.34.0"),
rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"),
rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0"), rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0"),
cfg_attr(not(test), rustc_diagnostic_item = "AtomicI64"), rustc_diagnostic_item = "AtomicI64",
"i64", "i64",
"", "",
atomic_min, atomic_max, atomic_min, atomic_max,
@ -3579,7 +3579,7 @@ atomic_int! {
stable(feature = "integer_atomics_stable", since = "1.34.0"), stable(feature = "integer_atomics_stable", since = "1.34.0"),
rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"),
rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0"), rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0"),
cfg_attr(not(test), rustc_diagnostic_item = "AtomicU64"), rustc_diagnostic_item = "AtomicU64",
"u64", "u64",
"", "",
atomic_umin, atomic_umax, atomic_umin, atomic_umax,
@ -3598,7 +3598,7 @@ atomic_int! {
unstable(feature = "integer_atomics", issue = "99069"), unstable(feature = "integer_atomics", issue = "99069"),
rustc_const_unstable(feature = "integer_atomics", issue = "99069"), rustc_const_unstable(feature = "integer_atomics", issue = "99069"),
rustc_const_unstable(feature = "integer_atomics", issue = "99069"), rustc_const_unstable(feature = "integer_atomics", issue = "99069"),
cfg_attr(not(test), rustc_diagnostic_item = "AtomicI128"), rustc_diagnostic_item = "AtomicI128",
"i128", "i128",
"#![feature(integer_atomics)]\n\n", "#![feature(integer_atomics)]\n\n",
atomic_min, atomic_max, atomic_min, atomic_max,
@ -3617,7 +3617,7 @@ atomic_int! {
unstable(feature = "integer_atomics", issue = "99069"), unstable(feature = "integer_atomics", issue = "99069"),
rustc_const_unstable(feature = "integer_atomics", issue = "99069"), rustc_const_unstable(feature = "integer_atomics", issue = "99069"),
rustc_const_unstable(feature = "integer_atomics", issue = "99069"), rustc_const_unstable(feature = "integer_atomics", issue = "99069"),
cfg_attr(not(test), rustc_diagnostic_item = "AtomicU128"), rustc_diagnostic_item = "AtomicU128",
"u128", "u128",
"#![feature(integer_atomics)]\n\n", "#![feature(integer_atomics)]\n\n",
atomic_umin, atomic_umax, atomic_umin, atomic_umax,
@ -3640,7 +3640,7 @@ macro_rules! atomic_int_ptr_sized {
stable(feature = "atomic_nand", since = "1.27.0"), stable(feature = "atomic_nand", since = "1.27.0"),
rustc_const_stable(feature = "const_ptr_sized_atomics", since = "1.24.0"), rustc_const_stable(feature = "const_ptr_sized_atomics", since = "1.24.0"),
rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0"), rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0"),
cfg_attr(not(test), rustc_diagnostic_item = "AtomicIsize"), rustc_diagnostic_item = "AtomicIsize",
"isize", "isize",
"", "",
atomic_min, atomic_max, atomic_min, atomic_max,
@ -3659,7 +3659,7 @@ macro_rules! atomic_int_ptr_sized {
stable(feature = "atomic_nand", since = "1.27.0"), stable(feature = "atomic_nand", since = "1.27.0"),
rustc_const_stable(feature = "const_ptr_sized_atomics", since = "1.24.0"), rustc_const_stable(feature = "const_ptr_sized_atomics", since = "1.24.0"),
rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0"), rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0"),
cfg_attr(not(test), rustc_diagnostic_item = "AtomicUsize"), rustc_diagnostic_item = "AtomicUsize",
"usize", "usize",
"", "",
atomic_umin, atomic_umax, atomic_umin, atomic_umax,

View file

@ -402,7 +402,7 @@ impl<'a> ContextBuilder<'a> {
/// [`Wake`]: ../../alloc/task/trait.Wake.html /// [`Wake`]: ../../alloc/task/trait.Wake.html
#[repr(transparent)] #[repr(transparent)]
#[stable(feature = "futures_api", since = "1.36.0")] #[stable(feature = "futures_api", since = "1.36.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "Waker")] #[rustc_diagnostic_item = "Waker"]
pub struct Waker { pub struct Waker {
waker: RawWaker, waker: RawWaker,
} }

View file

@ -77,7 +77,7 @@ const DAYS_PER_WEEK: u64 = 7;
/// crate to do so. /// crate to do so.
#[stable(feature = "duration", since = "1.3.0")] #[stable(feature = "duration", since = "1.3.0")]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
#[cfg_attr(not(test), rustc_diagnostic_item = "Duration")] #[rustc_diagnostic_item = "Duration"]
pub struct Duration { pub struct Duration {
secs: u64, secs: u64,
nanos: Nanoseconds, // Always 0 <= nanos < NANOS_PER_SEC nanos: Nanoseconds, // Always 0 <= nanos < NANOS_PER_SEC

View file

@ -109,9 +109,13 @@ impl<R: Read + ?Sized> BufReader<R> {
/// ///
/// `n` must be less than or equal to `capacity`. /// `n` must be less than or equal to `capacity`.
/// ///
/// the returned slice may be less than `n` bytes long if /// The returned slice may be less than `n` bytes long if
/// end of file is reached. /// end of file is reached.
/// ///
/// After calling this method, you may call [`consume`](BufRead::consume)
/// with a value less than or equal to `n` to advance over some or all of
/// the returned bytes.
///
/// ## Examples /// ## Examples
/// ///
/// ```rust /// ```rust

View file

@ -666,6 +666,8 @@ pub mod arch {
pub use std_detect::is_loongarch_feature_detected; pub use std_detect::is_loongarch_feature_detected;
#[unstable(feature = "is_riscv_feature_detected", issue = "111192")] #[unstable(feature = "is_riscv_feature_detected", issue = "111192")]
pub use std_detect::is_riscv_feature_detected; pub use std_detect::is_riscv_feature_detected;
#[unstable(feature = "stdarch_s390x_feature_detection", issue = "135413")]
pub use std_detect::is_s390x_feature_detected;
#[stable(feature = "simd_x86", since = "1.27.0")] #[stable(feature = "simd_x86", since = "1.27.0")]
pub use std_detect::is_x86_feature_detected; pub use std_detect::is_x86_feature_detected;
#[unstable(feature = "stdarch_mips_feature_detection", issue = "111188")] #[unstable(feature = "stdarch_mips_feature_detection", issue = "111188")]

View file

@ -8,6 +8,10 @@
all(target_arch = "aarch64", any(target_os = "linux", target_os = "android")), all(target_arch = "aarch64", any(target_os = "linux", target_os = "android")),
feature(stdarch_aarch64_feature_detection) feature(stdarch_aarch64_feature_detection)
)] )]
#![cfg_attr(
all(target_arch = "s390x", target_os = "linux"),
feature(stdarch_s390x_feature_detection)
)]
#![cfg_attr( #![cfg_attr(
all(target_arch = "powerpc", target_os = "linux"), all(target_arch = "powerpc", target_os = "linux"),
feature(stdarch_powerpc_feature_detection) feature(stdarch_powerpc_feature_detection)
@ -132,6 +136,32 @@ fn powerpc64_linux() {
// tidy-alphabetical-end // tidy-alphabetical-end
} }
#[test]
#[cfg(all(target_arch = "s390x", target_os = "linux"))]
fn s390x_linux() {
use std::arch::is_s390x_feature_detected;
// tidy-alphabetical-start
println!("deflate-conversion: {}", is_s390x_feature_detected!("deflate-conversion"));
println!("enhanced-sort: {}", is_s390x_feature_detected!("enhanced-sort"));
println!("guarded-storage: {}", is_s390x_feature_detected!("guarded-storage"));
println!("high-word: {}", is_s390x_feature_detected!("high-word"));
println!("nnp-assist: {}", is_s390x_feature_detected!("nnp-assist"));
println!("transactional-execution: {}", is_s390x_feature_detected!("transactional-execution"));
println!("vector-enhancements-1: {}", is_s390x_feature_detected!("vector-enhancements-1"));
println!("vector-enhancements-2: {}", is_s390x_feature_detected!("vector-enhancements-2"));
println!(
"vector-packed-decimal-enhancement-2: {}",
is_s390x_feature_detected!("vector-packed-decimal-enhancement-2")
);
println!(
"vector-packed-decimal-enhancement: {}",
is_s390x_feature_detected!("vector-packed-decimal-enhancement")
);
println!("vector-packed-decimal: {}", is_s390x_feature_detected!("vector-packed-decimal"));
println!("vector: {}", is_s390x_feature_detected!("vector"));
// tidy-alphabetical-end
}
#[test] #[test]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn x86_all() { fn x86_all() {

View file

@ -959,6 +959,7 @@ define_config! {
jobs: Option<u32> = "jobs", jobs: Option<u32> = "jobs",
compiletest_diff_tool: Option<String> = "compiletest-diff-tool", compiletest_diff_tool: Option<String> = "compiletest-diff-tool",
ccache: Option<StringOrBool> = "ccache", ccache: Option<StringOrBool> = "ccache",
exclude: Option<Vec<PathBuf>> = "exclude",
} }
} }
@ -1397,22 +1398,6 @@ impl Config {
"flags.exclude" = ?flags.exclude "flags.exclude" = ?flags.exclude
); );
config.skip = flags
.skip
.into_iter()
.chain(flags.exclude)
.map(|p| {
// Never return top-level path here as it would break `--skip`
// logic on rustc's internal test framework which is utilized
// by compiletest.
if cfg!(windows) {
PathBuf::from(p.to_str().unwrap().replace('/', "\\"))
} else {
p
}
})
.collect();
#[cfg(feature = "tracing")] #[cfg(feature = "tracing")]
span!( span!(
target: "CONFIG_HANDLING", target: "CONFIG_HANDLING",
@ -1658,8 +1643,29 @@ impl Config {
jobs, jobs,
compiletest_diff_tool, compiletest_diff_tool,
mut ccache, mut ccache,
exclude,
} = toml.build.unwrap_or_default(); } = toml.build.unwrap_or_default();
let mut paths: Vec<PathBuf> = flags.skip.into_iter().chain(flags.exclude).collect();
if let Some(exclude) = exclude {
paths.extend(exclude);
}
config.skip = paths
.into_iter()
.map(|p| {
// Never return top-level path here as it would break `--skip`
// logic on rustc's internal test framework which is utilized
// by compiletest.
if cfg!(windows) {
PathBuf::from(p.to_str().unwrap().replace('/', "\\"))
} else {
p
}
})
.collect();
config.jobs = Some(threads_from_config(flags.jobs.unwrap_or(jobs.unwrap_or(0)))); config.jobs = Some(threads_from_config(flags.jobs.unwrap_or(jobs.unwrap_or(0))));
if let Some(file_build) = build { if let Some(file_build) = build {

View file

@ -515,3 +515,18 @@ fn test_explicit_stage() {
assert!(!config.explicit_stage_from_config); assert!(!config.explicit_stage_from_config);
assert!(!config.is_explicit_stage()); assert!(!config.is_explicit_stage());
} }
#[test]
fn test_exclude() {
let exclude_path = "compiler";
let config = parse(&format!("build.exclude=[\"{}\"]", exclude_path));
let first_excluded = config
.skip
.first()
.expect("Expected at least one excluded path")
.to_str()
.expect("Failed to convert excluded path to string");
assert_eq!(first_excluded, exclude_path);
}

View file

@ -380,4 +380,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
severity: ChangeSeverity::Warning, severity: ChangeSeverity::Warning,
summary: "Removed `src/tools/rls` tool as it was deprecated long time ago.", summary: "Removed `src/tools/rls` tool as it was deprecated long time ago.",
}, },
ChangeInfo {
change_id: 137147,
severity: ChangeSeverity::Info,
summary: "New option `build.exclude` that adds support for excluding test.",
},
]; ];

View file

@ -0,0 +1,29 @@
# `offset_of_slice`
The tracking issue for this feature is: [#120141]
[#120141]: https://github.com/rust-lang/rust/issues/120141
------------------------
When the `offset_of_enum` feature is enabled, the [`offset_of!`] macro may be used to obtain the
offsets of fields of `enum`s; to express this, `enum` variants may be traversed as if they were
fields. Variants themselves do not have an offset, so they cannot appear as the last path component.
```rust
#![feature(offset_of_enum)]
use std::mem;
#[repr(u8)]
enum Enum {
A(u8, u16),
B { one: u8, two: u16 },
}
assert_eq!(mem::offset_of!(Enum, A.0), 1);
assert_eq!(mem::offset_of!(Enum, B.two), 2);
assert_eq!(mem::offset_of!(Option<&u8>, Some.0), 0);
```
[`offset_of!`]: ../../std/mem/macro.offset_of.html

View file

@ -0,0 +1,30 @@
# `offset_of_slice`
The tracking issue for this feature is: [#126151]
[#126151]: https://github.com/rust-lang/rust/issues/126151
------------------------
When the `offset_of_slice` feature is enabled, the [`offset_of!`] macro may be used to determine
the offset of fields whose type is `[T]`, that is, a slice of dynamic size.
In general, fields whose type is dynamically sized do not have statically known offsets because
they do not have statically known alignments. However, `[T]` has the same alignment as `T`, so
it specifically may be allowed.
```rust
#![feature(offset_of_slice)]
#[repr(C)]
pub struct Struct {
head: u32,
tail: [u8],
}
fn main() {
assert_eq!(std::mem::offset_of!(Struct, tail), 4);
}
```
[`offset_of!`]: ../../std/mem/macro.offset_of.html

View file

@ -40,7 +40,7 @@ def print_debug(s):
def normalize_whitespace(s): def normalize_whitespace(s):
"""Replace newlines, tabs, multiple spaces, etc with exactly one space""" """Replace newlines, tabs, multiple spaces, etc with exactly one space"""
return re.sub("\s+", " ", s) return re.sub(r"\s+", " ", s)
def breakpoint_callback(frame, bp_loc, dict): def breakpoint_callback(frame, bp_loc, dict):
@ -234,7 +234,7 @@ try:
if ( if (
command == "run" command == "run"
or command == "r" or command == "r"
or re.match("^process\s+launch.*", command) or re.match(r"^process\s+launch.*", command)
): ):
# Before starting to run the program, let the thread sleep a bit, so all # Before starting to run the program, let the thread sleep a bit, so all
# breakpoint added events can be processed # breakpoint added events can be processed

View file

@ -1488,6 +1488,9 @@ pub(crate) fn clean_middle_assoc_item(assoc_item: &ty::AssocItem, cx: &mut DocCo
// The only time this happens is if we're inside the rustdoc for Fn(), // The only time this happens is if we're inside the rustdoc for Fn(),
// which only has one associated type, which is not a GAT, so whatever. // which only has one associated type, which is not a GAT, so whatever.
} }
GenericArgs::ReturnTypeNotation => {
// Never move these.
}
} }
bounds.extend(mem::take(pred_bounds)); bounds.extend(mem::take(pred_bounds));
false false
@ -2553,36 +2556,42 @@ fn clean_generic_args<'tcx>(
generic_args: &hir::GenericArgs<'tcx>, generic_args: &hir::GenericArgs<'tcx>,
cx: &mut DocContext<'tcx>, cx: &mut DocContext<'tcx>,
) -> GenericArgs { ) -> GenericArgs {
// FIXME(return_type_notation): Fix RTN parens rendering match generic_args.parenthesized {
if let Some((inputs, output)) = generic_args.paren_sugar_inputs_output() { hir::GenericArgsParentheses::No => {
let inputs = inputs.iter().map(|x| clean_ty(x, cx)).collect(); let args = generic_args
let output = match output.kind { .args
hir::TyKind::Tup(&[]) => None, .iter()
_ => Some(Box::new(clean_ty(output, cx))), .map(|arg| match arg {
}; hir::GenericArg::Lifetime(lt) if !lt.is_anonymous() => {
GenericArgs::Parenthesized { inputs, output } GenericArg::Lifetime(clean_lifetime(lt, cx))
} else { }
let args = generic_args hir::GenericArg::Lifetime(_) => GenericArg::Lifetime(Lifetime::elided()),
.args hir::GenericArg::Type(ty) => GenericArg::Type(clean_ty(ty.as_unambig_ty(), cx)),
.iter() hir::GenericArg::Const(ct) => {
.map(|arg| match arg { GenericArg::Const(Box::new(clean_const(ct.as_unambig_ct(), cx)))
hir::GenericArg::Lifetime(lt) if !lt.is_anonymous() => { }
GenericArg::Lifetime(clean_lifetime(lt, cx)) hir::GenericArg::Infer(_inf) => GenericArg::Infer,
} })
hir::GenericArg::Lifetime(_) => GenericArg::Lifetime(Lifetime::elided()), .collect();
hir::GenericArg::Type(ty) => GenericArg::Type(clean_ty(ty.as_unambig_ty(), cx)), let constraints = generic_args
hir::GenericArg::Const(ct) => { .constraints
GenericArg::Const(Box::new(clean_const(ct.as_unambig_ct(), cx))) .iter()
} .map(|c| clean_assoc_item_constraint(c, cx))
hir::GenericArg::Infer(_inf) => GenericArg::Infer, .collect::<ThinVec<_>>();
}) GenericArgs::AngleBracketed { args, constraints }
.collect(); }
let constraints = generic_args hir::GenericArgsParentheses::ParenSugar => {
.constraints let Some((inputs, output)) = generic_args.paren_sugar_inputs_output() else {
.iter() bug!();
.map(|c| clean_assoc_item_constraint(c, cx)) };
.collect::<ThinVec<_>>(); let inputs = inputs.iter().map(|x| clean_ty(x, cx)).collect();
GenericArgs::AngleBracketed { args, constraints } let output = match output.kind {
hir::TyKind::Tup(&[]) => None,
_ => Some(Box::new(clean_ty(output, cx))),
};
GenericArgs::Parenthesized { inputs, output }
}
hir::GenericArgsParentheses::ReturnTypeNotation => GenericArgs::ReturnTypeNotation,
} }
} }

View file

@ -102,6 +102,10 @@ pub(crate) fn merge_bounds(
} }
} }
}, },
PP::ReturnTypeNotation => {
// Cannot merge bounds with RTN.
return false;
}
}; };
true true
}) })

View file

@ -2259,8 +2259,12 @@ impl GenericArg {
#[derive(Clone, PartialEq, Eq, Debug, Hash)] #[derive(Clone, PartialEq, Eq, Debug, Hash)]
pub(crate) enum GenericArgs { pub(crate) enum GenericArgs {
/// `<args, constraints = ..>`
AngleBracketed { args: ThinVec<GenericArg>, constraints: ThinVec<AssocItemConstraint> }, AngleBracketed { args: ThinVec<GenericArg>, constraints: ThinVec<AssocItemConstraint> },
/// `(inputs) -> output`
Parenthesized { inputs: ThinVec<Type>, output: Option<Box<Type>> }, Parenthesized { inputs: ThinVec<Type>, output: Option<Box<Type>> },
/// `(..)`
ReturnTypeNotation,
} }
impl GenericArgs { impl GenericArgs {
@ -2270,6 +2274,7 @@ impl GenericArgs {
args.is_empty() && constraints.is_empty() args.is_empty() && constraints.is_empty()
} }
GenericArgs::Parenthesized { inputs, output } => inputs.is_empty() && output.is_none(), GenericArgs::Parenthesized { inputs, output } => inputs.is_empty() && output.is_none(),
GenericArgs::ReturnTypeNotation => false,
} }
} }
pub(crate) fn constraints(&self) -> Box<dyn Iterator<Item = AssocItemConstraint> + '_> { pub(crate) fn constraints(&self) -> Box<dyn Iterator<Item = AssocItemConstraint> + '_> {
@ -2294,6 +2299,7 @@ impl GenericArgs {
}) })
.into_iter(), .into_iter(),
), ),
GenericArgs::ReturnTypeNotation => Box::new([].into_iter()),
} }
} }
} }
@ -2305,8 +2311,10 @@ impl<'a> IntoIterator for &'a GenericArgs {
match self { match self {
GenericArgs::AngleBracketed { args, .. } => Box::new(args.iter().cloned()), GenericArgs::AngleBracketed { args, .. } => Box::new(args.iter().cloned()),
GenericArgs::Parenthesized { inputs, .. } => { GenericArgs::Parenthesized { inputs, .. } => {
// FIXME: This isn't really right, since `Fn(A, B)` is `Fn<(A, B)>`
Box::new(inputs.iter().cloned().map(GenericArg::Type)) Box::new(inputs.iter().cloned().map(GenericArg::Type))
} }
GenericArgs::ReturnTypeNotation => Box::new([].into_iter()),
} }
} }
} }

View file

@ -332,6 +332,9 @@ impl clean::GenericArgs {
} }
} }
} }
clean::GenericArgs::ReturnTypeNotation => {
f.write_str("(..)")?;
}
} }
Ok(()) Ok(())
}) })

View file

@ -176,6 +176,7 @@ impl FromClean<clean::GenericArgs> for GenericArgs {
inputs: inputs.into_json(renderer), inputs: inputs.into_json(renderer),
output: output.map(|a| (*a).into_json(renderer)), output: output.map(|a| (*a).into_json(renderer)),
}, },
ReturnTypeNotation => GenericArgs::ReturnTypeNotation,
} }
} }
} }

View file

@ -30,7 +30,7 @@ pub type FxHashMap<K, V> = HashMap<K, V>; // re-export for use in src/librustdoc
/// This integer is incremented with every breaking change to the API, /// This integer is incremented with every breaking change to the API,
/// and is returned along with the JSON blob as [`Crate::format_version`]. /// and is returned along with the JSON blob as [`Crate::format_version`].
/// Consuming code should assert that this value matches the format version(s) that it supports. /// Consuming code should assert that this value matches the format version(s) that it supports.
pub const FORMAT_VERSION: u32 = 41; pub const FORMAT_VERSION: u32 = 42;
/// The root of the emitted JSON blob. /// The root of the emitted JSON blob.
/// ///
@ -229,6 +229,8 @@ pub enum GenericArgs {
/// The output type provided after the `->`, if present. /// The output type provided after the `->`, if present.
output: Option<Type>, output: Option<Type>,
}, },
/// `T::method(..)`
ReturnTypeNotation,
} }
/// One argument in a list of generic arguments to a path segment. /// One argument in a list of generic arguments to a path segment.

View file

@ -326,6 +326,7 @@ impl<'a> Validator<'a> {
self.check_type(o); self.check_type(o);
} }
} }
GenericArgs::ReturnTypeNotation => {}
} }
} }

View file

@ -9,4 +9,4 @@ path = "main.rs"
[dependencies] [dependencies]
regex = "1" regex = "1"
html5ever = "0.27.0" html5ever = "0.29.0"

View file

@ -16,7 +16,7 @@
//! A few exceptions are allowed as there's known bugs in rustdoc, but this //! A few exceptions are allowed as there's known bugs in rustdoc, but this
//! should catch the majority of "broken link" cases. //! should catch the majority of "broken link" cases.
use std::cell::RefCell; use std::cell::{Cell, RefCell};
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::io::ErrorKind; use std::io::ErrorKind;
use std::path::{Component, Path, PathBuf}; use std::path::{Component, Path, PathBuf};
@ -544,7 +544,7 @@ fn parse_html<Sink: TokenSink>(source: &str, sink: Sink) -> Sink {
let mut input = BufferQueue::default(); let mut input = BufferQueue::default();
input.push_back(tendril.try_reinterpret().unwrap()); input.push_back(tendril.try_reinterpret().unwrap());
let mut tok = Tokenizer::new(sink, TokenizerOpts::default()); let tok = Tokenizer::new(sink, TokenizerOpts::default());
let _ = tok.feed(&mut input); let _ = tok.feed(&mut input);
assert!(input.is_empty()); assert!(input.is_empty());
tok.end(); tok.end();
@ -554,8 +554,8 @@ fn parse_html<Sink: TokenSink>(source: &str, sink: Sink) -> Sink {
#[derive(Default)] #[derive(Default)]
struct AttrCollector { struct AttrCollector {
attr_name: &'static [u8], attr_name: &'static [u8],
base: Option<String>, base: Cell<Option<String>>,
found_attrs: Vec<(u64, String)>, found_attrs: RefCell<Vec<(u64, String)>>,
/// Tracks whether or not it is inside a <script> tag. /// Tracks whether or not it is inside a <script> tag.
/// ///
/// A lot of our sources have JSON script tags which have HTML embedded /// A lot of our sources have JSON script tags which have HTML embedded
@ -564,13 +564,13 @@ struct AttrCollector {
/// `TokenSinkResult::Script(…)` (and then maybe switch parser?), but I /// `TokenSinkResult::Script(…)` (and then maybe switch parser?), but I
/// don't fully understand the best way to use that, and this seems good /// don't fully understand the best way to use that, and this seems good
/// enough for now. /// enough for now.
in_script: bool, in_script: Cell<bool>,
} }
impl TokenSink for AttrCollector { impl TokenSink for AttrCollector {
type Handle = (); type Handle = ();
fn process_token(&mut self, token: Token, line_number: u64) -> TokenSinkResult<()> { fn process_token(&self, token: Token, line_number: u64) -> TokenSinkResult<()> {
match token { match token {
TagToken(tag) => { TagToken(tag) => {
let tag_name = tag.name.as_bytes(); let tag_name = tag.name.as_bytes();
@ -578,20 +578,20 @@ impl TokenSink for AttrCollector {
if let Some(href) = if let Some(href) =
tag.attrs.iter().find(|attr| attr.name.local.as_bytes() == b"href") tag.attrs.iter().find(|attr| attr.name.local.as_bytes() == b"href")
{ {
self.base = Some(href.value.to_string()); self.base.set(Some(href.value.to_string()));
} }
return TokenSinkResult::Continue; return TokenSinkResult::Continue;
} else if tag_name == b"script" { } else if tag_name == b"script" {
self.in_script = !self.in_script; self.in_script.set(!self.in_script.get());
} }
if self.in_script { if self.in_script.get() {
return TokenSinkResult::Continue; return TokenSinkResult::Continue;
} }
for attr in tag.attrs.iter() { for attr in tag.attrs.iter() {
let name = attr.name.local.as_bytes(); let name = attr.name.local.as_bytes();
if name == self.attr_name { if name == self.attr_name {
let url = attr.value.to_string(); let url = attr.value.to_string();
self.found_attrs.push((line_number, url)); self.found_attrs.borrow_mut().push((line_number, url));
} }
} }
} }
@ -607,7 +607,7 @@ impl TokenSink for AttrCollector {
fn get_urls(source: &str) -> (Option<String>, Vec<(u64, String)>) { fn get_urls(source: &str) -> (Option<String>, Vec<(u64, String)>) {
let collector = AttrCollector { attr_name: b"href", ..AttrCollector::default() }; let collector = AttrCollector { attr_name: b"href", ..AttrCollector::default() };
let sink = parse_html(source, collector); let sink = parse_html(source, collector);
(sink.base, sink.found_attrs) (sink.base.into_inner(), sink.found_attrs.into_inner())
} }
/// Retrieves id="..." attributes from HTML elements. /// Retrieves id="..." attributes from HTML elements.
@ -619,7 +619,7 @@ fn parse_ids(ids: &mut HashSet<String>, file: &str, source: &str, report: &mut R
let collector = AttrCollector { attr_name: b"id", ..AttrCollector::default() }; let collector = AttrCollector { attr_name: b"id", ..AttrCollector::default() };
let sink = parse_html(source, collector); let sink = parse_html(source, collector);
for (line_number, id) in sink.found_attrs { for (line_number, id) in sink.found_attrs.into_inner() {
let encoded = small_url_encode(&id); let encoded = small_url_encode(&id);
if let Some(id) = ids.replace(id) { if let Some(id) = ids.replace(id) {
report.errors += 1; report.errors += 1;

View file

@ -0,0 +1,17 @@
//@ compile-flags: -Copt-level=3
//@ min-llvm-version: 20
#![crate_type = "lib"]
// Ensure that a modulo operation with an operand that is known to be
// a power-of-two is properly optimized.
// CHECK-LABEL: @modulo_with_power_of_two_divisor
// CHECK: add i64 %divisor, -1
// CHECK-NEXT: and i64
// CHECK-NEXT: ret i64
#[no_mangle]
pub fn modulo_with_power_of_two_divisor(dividend: u64, divisor: u64) -> u64 {
assert!(divisor.is_power_of_two());
// should be optimized to (dividend & (divisor - 1))
dividend % divisor
}

View file

@ -0,0 +1,35 @@
- // MIR for `propagate` before GVN
+ // MIR for `propagate` after GVN
fn propagate() -> unsafe<> i32 {
let mut _0: unsafe<> i32;
let _1: i32;
let mut _3: i32;
scope 1 {
debug x => _1;
let _2: unsafe<> i32;
scope 2 {
debug binder => _2;
}
}
bb0: {
- StorageLive(_1);
+ nop;
_1 = const 1_i32;
StorageLive(_2);
StorageLive(_3);
- _3 = copy _1;
- _2 = wrap_binder!(move _3; unsafe<> i32);
+ _3 = const 1_i32;
+ _2 = const {transmute(0x00000001): unsafe<> i32};
StorageDead(_3);
- _0 = move _2;
+ _0 = const {transmute(0x00000001): unsafe<> i32};
StorageDead(_2);
- StorageDead(_1);
+ nop;
return;
}
}

View file

@ -0,0 +1,29 @@
// skip-filecheck
//@ test-mir-pass: GVN
// EMIT_MIR gvn_on_unsafe_binder.test.GVN.diff
// EMIT_MIR gvn_on_unsafe_binder.propagate.GVN.diff
#![feature(unsafe_binders)]
use std::unsafe_binder::wrap_binder;
// Test for ICE <https://github.com/rust-lang/rust/issues/137846>.
fn test() {
unsafe {
let x = 1;
let binder: unsafe<'a> &'a i32 = wrap_binder!(&x);
}
}
// Test that GVN propagates const values through unsafe binders.
//
// The lifetime `'a` is redundant (and doesn't print when we print out the type).
// However, we need it so that rustfmt doesn't rip out the `unsafe<>` part for now.
fn propagate() -> unsafe<'a> i32 {
unsafe {
let x = 1;
let binder: unsafe<'a> i32 = wrap_binder!(x);
binder
}
}

View file

@ -0,0 +1,30 @@
- // MIR for `test` before GVN
+ // MIR for `test` after GVN
fn test() -> () {
let mut _0: ();
let _1: i32;
let mut _3: &i32;
scope 1 {
debug x => _1;
let _2: unsafe<'a> &'a i32;
scope 2 {
debug binder => _2;
}
}
bb0: {
StorageLive(_1);
_1 = const 1_i32;
StorageLive(_2);
StorageLive(_3);
_3 = &_1;
_2 = wrap_binder!(move _3; unsafe<'a> &'a i32);
StorageDead(_3);
_0 = const ();
StorageDead(_2);
StorageDead(_1);
return;
}
}

View file

@ -0,0 +1,18 @@
//@ edition: 2021
// ignore-tidy-linelength
#![crate_type = "lib"]
#![feature(return_type_notation)]
pub trait Foo {
async fn bar();
}
//@ is "$.index[*][?(@.name=='foo')].inner.function.generics.params[0].kind.type.bounds[0].trait_bound.trait.args.angle_bracketed.constraints[0].args" '"return_type_notation"'
//@ ismany "$.index[*][?(@.name=='foo')].inner.function.generics.where_predicates[*].bound_predicate.type.qualified_path.args" '"return_type_notation"' '"return_type_notation"'
pub fn foo<T: Foo<bar(..): Send>>()
where
<T as Foo>::bar(..): 'static,
T::bar(..): Sync,
{
}

View file

@ -0,0 +1,18 @@
//@ edition: 2021
#![crate_type = "lib"]
#![feature(return_type_notation)]
pub trait Foo {
async fn bar();
}
//@ has "return_type_notation/fn.foo.html"
//@ has - '//pre[@class="rust item-decl"]' "pub fn foo<T: Foo<bar(..): Send>>()"
//@ has - '//pre[@class="rust item-decl"]' "where <T as Foo>::bar(..): 'static, T::bar(..): Sync"
pub fn foo<T: Foo<bar(..): Send>>()
where
<T as Foo>::bar(..): 'static,
T::bar(..): Sync,
{
}

View file

@ -0,0 +1,16 @@
//! Regression test to check that outer attributes applied to the first module item is applied to
//! its attached module item only, and not also to other subsequent module items
//!
//! Commit: <https://github.com/rust-lang/rust/commit/7aee9f7b56f8d96f9444ebb1d06e32e024b81974>
//@ check-pass
//@ compile-flags: --cfg=first
//@ no-auto-check-cfg
#[cfg(first)]
mod hello {}
#[cfg(not_set)]
mod hello {}
fn main() {}

View file

@ -0,0 +1,6 @@
//@ run-rustfix
#![allow(unused_parens)]
fn main() {
let _x: u8 = (4u8); //~ ERROR: mismatched types
let _y: u8 = (4u8); //~ ERROR: mismatched types
}

View file

@ -0,0 +1,6 @@
//@ run-rustfix
#![allow(unused_parens)]
fn main() {
let _x: u8 = (4i32); //~ ERROR: mismatched types
let _y: u8 = (4.0f32); //~ ERROR: mismatched types
}

View file

@ -0,0 +1,31 @@
error[E0308]: mismatched types
--> $DIR/cast_lit_suffix-issue-138392.rs:4:18
|
LL | let _x: u8 = (4i32);
| -- ^^^^^^ expected `u8`, found `i32`
| |
| expected due to this
|
help: change the type of the numeric literal from `i32` to `u8`
|
LL - let _x: u8 = (4i32);
LL + let _x: u8 = (4u8);
|
error[E0308]: mismatched types
--> $DIR/cast_lit_suffix-issue-138392.rs:5:18
|
LL | let _y: u8 = (4.0f32);
| -- ^^^^^^^^ expected `u8`, found `f32`
| |
| expected due to this
|
help: change the type of the numeric literal from `f32` to `u8`
|
LL - let _y: u8 = (4.0f32);
LL + let _y: u8 = (4u8);
|
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0308`.

View file

@ -1,25 +0,0 @@
//@ run-pass
// Regression test for a problem with the first mod attribute
// being applied to every mod
#[cfg(target_os = "linux")]
mod hello {}
#[cfg(target_os = "macos")]
mod hello {}
#[cfg(target_os = "windows")]
mod hello {}
#[cfg(target_os = "freebsd")]
mod hello {}
#[cfg(target_os = "dragonfly")]
mod hello {}
#[cfg(target_os = "android")]
mod hello {}
fn main() {}

View file

@ -1,18 +0,0 @@
//@ normalize-stderr: "loaded from .*libstd-.*.rlib" -> "loaded from SYSROOT/libstd-*.rlib"
// note-pattern: first defined in crate `std`.
// Test for issue #31788 and E0152
#![feature(lang_items)]
extern crate core;
use core::panic::PanicInfo;
#[lang = "panic_impl"]
fn panic_impl(info: &PanicInfo) -> ! {
//~^ ERROR: found duplicate lang item `panic_impl`
loop {}
}
fn main() {}

View file

@ -0,0 +1,20 @@
//! Validates the correct printing of E0152 in the case of duplicate "lang_item" function
//! definitions.
//!
//! Issue: <https://github.com/rust-lang/rust/issues/31788>
//@ error-pattern: first defined in crate `std`
//@ normalize-stderr: "loaded from .*libstd-.*.rlib" -> "loaded from SYSROOT/libstd-*.rlib"
#![feature(lang_items)]
extern crate core;
use core::panic::PanicInfo;
#[lang = "panic_impl"]
fn panic_impl(info: &PanicInfo) -> ! {
//~^ ERROR: found duplicate lang item `panic_impl`
loop {}
}
fn main() {}

View file

@ -1,5 +1,5 @@
error[E0152]: found duplicate lang item `panic_impl` error[E0152]: found duplicate lang item `panic_impl`
--> $DIR/duplicate_entry_error.rs:13:1 --> $DIR/E0152-duplicate-lang-items.rs:15:1
| |
LL | / fn panic_impl(info: &PanicInfo) -> ! { LL | / fn panic_impl(info: &PanicInfo) -> ! {
LL | | LL | |
@ -7,9 +7,9 @@ LL | | loop {}
LL | | } LL | | }
| |_^ | |_^
| |
= note: the lang item is first defined in crate `std` (which `duplicate_entry_error` depends on) = note: the lang item is first defined in crate `std` (which `E0152_duplicate_lang_items` depends on)
= note: first definition in `std` loaded from SYSROOT/libstd-*.rlib = note: first definition in `std` loaded from SYSROOT/libstd-*.rlib
= note: second definition in the local crate (`duplicate_entry_error`) = note: second definition in the local crate (`E0152_duplicate_lang_items`)
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -1,3 +1,6 @@
//! Regression test for duplicated label in E0381 error message.
//!
//! Issue: <https://github.com/rust-lang/rust/issues/129274>
fn main() { fn main() {
fn test() { fn test() {
loop { loop {

View file

@ -1,5 +1,5 @@
error[E0381]: used binding `blah` is possibly-uninitialized error[E0381]: used binding `blah` is possibly-uninitialized
--> $DIR/duplicate-label-E0381-issue-129274.rs:8:33 --> $DIR/E0381-duplicated-label.rs:11:33
| |
LL | let blah: Option<String>; LL | let blah: Option<String>;
| ---- binding declared here but left uninitialized | ---- binding declared here but left uninitialized