Skip to content

Commit b1a56b5

Browse files
committed
Auto merge of rust-lang#129691 - matthiaskrgr:rollup-owlcr3m, r=matthiaskrgr
Rollup of 11 pull requests Successful merges: - rust-lang#129421 (add repr to the allowlist for naked functions) - rust-lang#129480 (docs: correct panic conditions for rem_euclid and similar functions) - rust-lang#129551 (ub_checks intrinsics: fall back to cfg(ub_checks)) - rust-lang#129608 (const-eval: do not make UbChecks behavior depend on current crate's flags) - rust-lang#129613 (interpret: do not make const-eval query result depend on tcx.sess) - rust-lang#129641 (rustdoc: fix missing resource suffix on `crates.js`) - rust-lang#129657 (Rename `BikeshedIntrinsicFrom` to `TransmuteFrom`) - rust-lang#129666 (interpret: add missing alignment check in raw_eq) - rust-lang#129667 (Rustc driver cleanup) - rust-lang#129668 (Fix Pin::set bounds regression) - rust-lang#129686 (coverage: Rename `CodeRegion` to `SourceRegion`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents bfbe13e + 39ad6a9 commit b1a56b5

File tree

6 files changed

+82
-76
lines changed

6 files changed

+82
-76
lines changed

core/src/intrinsics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2949,15 +2949,15 @@ pub const unsafe fn typed_swap<T>(x: *mut T, y: *mut T) {
29492949
/// sysroot which is built without ub_checks but with `#[rustc_preserve_ub_checks]`.
29502950
/// For code that gets monomorphized in the user crate (i.e., generic functions and functions with
29512951
/// `#[inline]`), gating assertions on `ub_checks()` rather than `cfg!(ub_checks)` means that
2952-
/// assertions are enabled whenever the *user crate* has UB checks enabled. However if the
2952+
/// assertions are enabled whenever the *user crate* has UB checks enabled. However, if the
29532953
/// user has UB checks disabled, the checks will still get optimized out. This intrinsic is
29542954
/// primarily used by [`ub_checks::assert_unsafe_precondition`].
29552955
#[rustc_const_unstable(feature = "const_ub_checks", issue = "none")]
29562956
#[unstable(feature = "core_intrinsics", issue = "none")]
29572957
#[inline(always)]
29582958
#[rustc_intrinsic]
29592959
pub const fn ub_checks() -> bool {
2960-
cfg!(debug_assertions)
2960+
cfg!(ub_checks)
29612961
}
29622962

29632963
/// Allocates a block of memory at compile time.

core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@
203203
#![feature(cfg_sanitize)]
204204
#![feature(cfg_target_has_atomic)]
205205
#![feature(cfg_target_has_atomic_equal_alignment)]
206+
#![feature(cfg_ub_checks)]
206207
#![feature(const_for)]
207208
#![feature(const_mut_refs)]
208209
#![feature(const_precise_live_drops)]

core/src/mem/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub use maybe_uninit::MaybeUninit;
1919

2020
mod transmutability;
2121
#[unstable(feature = "transmutability", issue = "99571")]
22-
pub use transmutability::{Assume, BikeshedIntrinsicFrom};
22+
pub use transmutability::{Assume, TransmuteFrom};
2323

2424
#[stable(feature = "rust1", since = "1.0.0")]
2525
#[doc(inline)]

core/src/mem/transmutability.rs

+53-56
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ use crate::marker::{ConstParamTy_, UnsizedConstParamTy};
1111
///
1212
/// # Safety
1313
///
14-
/// If `Dst: BikeshedIntrinsicFrom<Src, ASSUMPTIONS>`, the compiler guarantees
15-
/// that `Src` is soundly *union-transmutable* into a value of type `Dst`,
16-
/// provided that the programmer has guaranteed that the given
17-
/// [`ASSUMPTIONS`](Assume) are satisfied.
14+
/// If `Dst: TransmuteFrom<Src, ASSUMPTIONS>`, the compiler guarantees that
15+
/// `Src` is soundly *union-transmutable* into a value of type `Dst`, provided
16+
/// that the programmer has guaranteed that the given [`ASSUMPTIONS`](Assume)
17+
/// are satisfied.
1818
///
1919
/// A union-transmute is any bit-reinterpretation conversion in the form of:
2020
///
@@ -47,15 +47,15 @@ use crate::marker::{ConstParamTy_, UnsizedConstParamTy};
4747
#[cfg_attr(not(bootstrap), doc = "```rust")]
4848
/// #![feature(transmutability)]
4949
///
50-
/// use core::mem::{Assume, BikeshedIntrinsicFrom};
50+
/// use core::mem::{Assume, TransmuteFrom};
5151
///
5252
/// let src = 42u8; // size = 1
5353
///
5454
/// #[repr(C, align(2))]
5555
/// struct Dst(u8); // size = 2
5656
//
5757
/// let _ = unsafe {
58-
/// <Dst as BikeshedIntrinsicFrom<u8, { Assume::SAFETY }>>::transmute(src)
58+
/// <Dst as TransmuteFrom<u8, { Assume::SAFETY }>>::transmute(src)
5959
/// };
6060
/// ```
6161
///
@@ -87,7 +87,7 @@ use crate::marker::{ConstParamTy_, UnsizedConstParamTy};
8787
#[lang = "transmute_trait"]
8888
#[rustc_deny_explicit_impl(implement_via_object = false)]
8989
#[rustc_coinductive]
90-
pub unsafe trait BikeshedIntrinsicFrom<Src, const ASSUME: Assume = { Assume::NOTHING }>
90+
pub unsafe trait TransmuteFrom<Src, const ASSUME: Assume = { Assume::NOTHING }>
9191
where
9292
Src: ?Sized,
9393
{
@@ -140,23 +140,21 @@ where
140140
}
141141
}
142142

143-
/// Configurable proof assumptions of [`BikeshedIntrinsicFrom`].
143+
/// Configurable proof assumptions of [`TransmuteFrom`].
144144
///
145145
/// When `false`, the respective proof obligation belongs to the compiler. When
146146
/// `true`, the onus of the safety proof belongs to the programmer.
147-
/// [`BikeshedIntrinsicFrom`].
148147
#[unstable(feature = "transmutability", issue = "99571")]
149148
#[lang = "transmute_opts"]
150149
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
151150
pub struct Assume {
152-
/// When `false`, [`BikeshedIntrinsicFrom`] is not implemented for
153-
/// transmutations that might violate the the alignment requirements of
154-
/// references; e.g.:
151+
/// When `false`, [`TransmuteFrom`] is not implemented for transmutations
152+
/// that might violate the the alignment requirements of references; e.g.:
155153
///
156154
#[cfg_attr(bootstrap, doc = "```rust,ignore not runnable on bootstrap")]
157155
#[cfg_attr(not(bootstrap), doc = "```compile_fail,E0277")]
158156
/// #![feature(transmutability)]
159-
/// use core::mem::{align_of, BikeshedIntrinsicFrom};
157+
/// use core::mem::{align_of, TransmuteFrom};
160158
///
161159
/// assert_eq!(align_of::<[u8; 2]>(), 1);
162160
/// assert_eq!(align_of::<u16>(), 2);
@@ -165,26 +163,26 @@ pub struct Assume {
165163
///
166164
/// // SAFETY: No safety obligations.
167165
/// let dst: &u16 = unsafe {
168-
/// <_ as BikeshedIntrinsicFrom<_>>::transmute(src)
166+
/// <_ as TransmuteFrom<_>>::transmute(src)
169167
/// };
170168
/// ```
171169
///
172-
/// When `true`, [`BikeshedIntrinsicFrom`] assumes that *you* have ensured
170+
/// When `true`, [`TransmuteFrom`] assumes that *you* have ensured
173171
/// that references in the transmuted value satisfy the alignment
174172
/// requirements of their referent types; e.g.:
175173
///
176174
#[cfg_attr(bootstrap, doc = "```rust,ignore not runnable on bootstrap")]
177175
#[cfg_attr(not(bootstrap), doc = "```rust")]
178176
/// #![feature(pointer_is_aligned_to, transmutability)]
179-
/// use core::mem::{align_of, Assume, BikeshedIntrinsicFrom};
177+
/// use core::mem::{align_of, Assume, TransmuteFrom};
180178
///
181179
/// let src: &[u8; 2] = &[0xFF, 0xFF];
182180
///
183181
/// let maybe_dst: Option<&u16> = if <*const _>::is_aligned_to(src, align_of::<u16>()) {
184182
/// // SAFETY: We have checked above that the address of `src` satisfies the
185183
/// // alignment requirements of `u16`.
186184
/// Some(unsafe {
187-
/// <_ as BikeshedIntrinsicFrom<_, { Assume::ALIGNMENT }>>::transmute(src)
185+
/// <_ as TransmuteFrom<_, { Assume::ALIGNMENT }>>::transmute(src)
188186
/// })
189187
/// } else {
190188
/// None
@@ -194,21 +192,21 @@ pub struct Assume {
194192
/// ```
195193
pub alignment: bool,
196194

197-
/// When `false`, [`BikeshedIntrinsicFrom`] is not implemented for
198-
/// transmutations that extend the lifetimes of references.
195+
/// When `false`, [`TransmuteFrom`] is not implemented for transmutations
196+
/// that extend the lifetimes of references.
199197
///
200-
/// When `true`, [`BikeshedIntrinsicFrom`] assumes that *you* have ensured
201-
/// that references in the transmuted value do not outlive their referents.
198+
/// When `true`, [`TransmuteFrom`] assumes that *you* have ensured that
199+
/// references in the transmuted value do not outlive their referents.
202200
pub lifetimes: bool,
203201

204-
/// When `false`, [`BikeshedIntrinsicFrom`] is not implemented for
205-
/// transmutations that might violate the library safety invariants of the
206-
/// destination type; e.g.:
202+
/// When `false`, [`TransmuteFrom`] is not implemented for transmutations
203+
/// that might violate the library safety invariants of the destination
204+
/// type; e.g.:
207205
///
208206
#[cfg_attr(bootstrap, doc = "```rust,ignore not runnable on bootstrap")]
209207
#[cfg_attr(not(bootstrap), doc = "```compile_fail,E0277")]
210208
/// #![feature(transmutability)]
211-
/// use core::mem::BikeshedIntrinsicFrom;
209+
/// use core::mem::TransmuteFrom;
212210
///
213211
/// let src: u8 = 3;
214212
///
@@ -219,18 +217,18 @@ pub struct Assume {
219217
///
220218
/// // SAFETY: No safety obligations.
221219
/// let dst: EvenU8 = unsafe {
222-
/// <_ as BikeshedIntrinsicFrom<_>>::transmute(src)
220+
/// <_ as TransmuteFrom<_>>::transmute(src)
223221
/// };
224222
/// ```
225223
///
226-
/// When `true`, [`BikeshedIntrinsicFrom`] assumes that *you* have ensured
224+
/// When `true`, [`TransmuteFrom`] assumes that *you* have ensured
227225
/// that undefined behavior does not arise from using the transmuted value;
228226
/// e.g.:
229227
///
230228
#[cfg_attr(bootstrap, doc = "```rust,ignore not runnable on bootstrap")]
231229
#[cfg_attr(not(bootstrap), doc = "```rust")]
232230
/// #![feature(transmutability)]
233-
/// use core::mem::{Assume, BikeshedIntrinsicFrom};
231+
/// use core::mem::{Assume, TransmuteFrom};
234232
///
235233
/// let src: u8 = 42;
236234
///
@@ -242,7 +240,7 @@ pub struct Assume {
242240
/// let maybe_dst: Option<EvenU8> = if src % 2 == 0 {
243241
/// // SAFETY: We have checked above that the value of `src` is even.
244242
/// Some(unsafe {
245-
/// <_ as BikeshedIntrinsicFrom<_, { Assume::SAFETY }>>::transmute(src)
243+
/// <_ as TransmuteFrom<_, { Assume::SAFETY }>>::transmute(src)
246244
/// })
247245
/// } else {
248246
/// None
@@ -252,39 +250,39 @@ pub struct Assume {
252250
/// ```
253251
pub safety: bool,
254252

255-
/// When `false`, [`BikeshedIntrinsicFrom`] is not implemented for
256-
/// transmutations that might violate the language-level bit-validity
257-
/// invariant of the destination type; e.g.:
253+
/// When `false`, [`TransmuteFrom`] is not implemented for transmutations
254+
/// that might violate the language-level bit-validity invariant of the
255+
/// destination type; e.g.:
258256
///
259257
#[cfg_attr(bootstrap, doc = "```rust,ignore not runnable on bootstrap")]
260258
#[cfg_attr(not(bootstrap), doc = "```compile_fail,E0277")]
261259
/// #![feature(transmutability)]
262-
/// use core::mem::BikeshedIntrinsicFrom;
260+
/// use core::mem::TransmuteFrom;
263261
///
264262
/// let src: u8 = 3;
265263
///
266264
/// // SAFETY: No safety obligations.
267265
/// let dst: bool = unsafe {
268-
/// <_ as BikeshedIntrinsicFrom<_>>::transmute(src)
266+
/// <_ as TransmuteFrom<_>>::transmute(src)
269267
/// };
270268
/// ```
271269
///
272-
/// When `true`, [`BikeshedIntrinsicFrom`] assumes that *you* have ensured
270+
/// When `true`, [`TransmuteFrom`] assumes that *you* have ensured
273271
/// that the value being transmuted is a bit-valid instance of the
274272
/// transmuted value; e.g.:
275273
///
276274
#[cfg_attr(bootstrap, doc = "```rust,ignore not runnable on bootstrap")]
277275
#[cfg_attr(not(bootstrap), doc = "```rust")]
278276
/// #![feature(transmutability)]
279-
/// use core::mem::{Assume, BikeshedIntrinsicFrom};
277+
/// use core::mem::{Assume, TransmuteFrom};
280278
///
281279
/// let src: u8 = 1;
282280
///
283281
/// let maybe_dst: Option<bool> = if src == 0 || src == 1 {
284282
/// // SAFETY: We have checked above that the value of `src` is a bit-valid
285283
/// // instance of `bool`.
286284
/// Some(unsafe {
287-
/// <_ as BikeshedIntrinsicFrom<_, { Assume::VALIDITY }>>::transmute(src)
285+
/// <_ as TransmuteFrom<_, { Assume::VALIDITY }>>::transmute(src)
288286
/// })
289287
/// } else {
290288
/// None
@@ -301,35 +299,34 @@ impl ConstParamTy_ for Assume {}
301299
impl UnsizedConstParamTy for Assume {}
302300

303301
impl Assume {
304-
/// With this, [`BikeshedIntrinsicFrom`] does not assume you have ensured
305-
/// any safety obligations are met, and relies only upon its own analysis to
306-
/// (dis)prove transmutability.
302+
/// With this, [`TransmuteFrom`] does not assume you have ensured any safety
303+
/// obligations are met, and relies only upon its own analysis to (dis)prove
304+
/// transmutability.
307305
#[unstable(feature = "transmutability", issue = "99571")]
308306
pub const NOTHING: Self =
309307
Self { alignment: false, lifetimes: false, safety: false, validity: false };
310308

311-
/// With this, [`BikeshedIntrinsicFrom`] assumes only that you have ensured
312-
/// that references in the transmuted value satisfy the alignment
313-
/// requirements of their referent types. See [`Assume::alignment`] for
314-
/// examples.
309+
/// With this, [`TransmuteFrom`] assumes only that you have ensured that
310+
/// references in the transmuted value satisfy the alignment requirements of
311+
/// their referent types. See [`Assume::alignment`] for examples.
315312
#[unstable(feature = "transmutability", issue = "99571")]
316313
pub const ALIGNMENT: Self = Self { alignment: true, ..Self::NOTHING };
317314

318-
/// With this, [`BikeshedIntrinsicFrom`] assumes only that you have ensured
319-
/// that references in the transmuted value do not outlive their referents.
320-
/// See [`Assume::lifetimes`] for examples.
315+
/// With this, [`TransmuteFrom`] assumes only that you have ensured that
316+
/// references in the transmuted value do not outlive their referents. See
317+
/// [`Assume::lifetimes`] for examples.
321318
#[unstable(feature = "transmutability", issue = "99571")]
322319
pub const LIFETIMES: Self = Self { lifetimes: true, ..Self::NOTHING };
323320

324-
/// With this, [`BikeshedIntrinsicFrom`] assumes only that you have ensured
325-
/// that undefined behavior does not arise from using the transmuted value.
326-
/// See [`Assume::safety`] for examples.
321+
/// With this, [`TransmuteFrom`] assumes only that you have ensured that
322+
/// undefined behavior does not arise from using the transmuted value. See
323+
/// [`Assume::safety`] for examples.
327324
#[unstable(feature = "transmutability", issue = "99571")]
328325
pub const SAFETY: Self = Self { safety: true, ..Self::NOTHING };
329326

330-
/// With this, [`BikeshedIntrinsicFrom`] assumes only that you have ensured
331-
/// that the value being transmuted is a bit-valid instance of the
332-
/// transmuted value. See [`Assume::validity`] for examples.
327+
/// With this, [`TransmuteFrom`] assumes only that you have ensured that the
328+
/// value being transmuted is a bit-valid instance of the transmuted value.
329+
/// See [`Assume::validity`] for examples.
333330
#[unstable(feature = "transmutability", issue = "99571")]
334331
pub const VALIDITY: Self = Self { validity: true, ..Self::NOTHING };
335332

@@ -348,7 +345,7 @@ impl Assume {
348345
/// transmutability,
349346
/// )]
350347
/// #![allow(incomplete_features)]
351-
/// use core::mem::{align_of, Assume, BikeshedIntrinsicFrom};
348+
/// use core::mem::{align_of, Assume, TransmuteFrom};
352349
///
353350
/// /// Attempts to transmute `src` to `&Dst`.
354351
/// ///
@@ -360,15 +357,15 @@ impl Assume {
360357
/// /// alignment, are satisfied.
361358
/// unsafe fn try_transmute_ref<'a, Src, Dst, const ASSUME: Assume>(src: &'a Src) -> Option<&'a Dst>
362359
/// where
363-
/// &'a Dst: BikeshedIntrinsicFrom<&'a Src, { ASSUME.and(Assume::ALIGNMENT) }>,
360+
/// &'a Dst: TransmuteFrom<&'a Src, { ASSUME.and(Assume::ALIGNMENT) }>,
364361
/// {
365362
/// if <*const _>::is_aligned_to(src, align_of::<Dst>()) {
366363
/// // SAFETY: By the above dynamic check, we have ensured that the address
367364
/// // of `src` satisfies the alignment requirements of `&Dst`. By contract
368365
/// // on the caller, the safety obligations required by `ASSUME` have also
369366
/// // been satisfied.
370367
/// Some(unsafe {
371-
/// <_ as BikeshedIntrinsicFrom<_, { ASSUME.and(Assume::ALIGNMENT) }>>::transmute(src)
368+
/// <_ as TransmuteFrom<_, { ASSUME.and(Assume::ALIGNMENT) }>>::transmute(src)
372369
/// })
373370
/// } else {
374371
/// None

core/src/num/int_macros.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -2888,8 +2888,8 @@ macro_rules! int_impl {
28882888
///
28892889
/// # Panics
28902890
///
2891-
/// This function will panic if `rhs` is 0 or if `self` is -1 and `rhs` is
2892-
/// `Self::MIN`. This behavior is not affected by the `overflow-checks` flag.
2891+
/// This function will panic if `rhs` is 0 or if `self` is `Self::MIN`
2892+
/// and `rhs` is -1. This behavior is not affected by the `overflow-checks` flag.
28932893
///
28942894
/// # Examples
28952895
///
@@ -2927,8 +2927,8 @@ macro_rules! int_impl {
29272927
///
29282928
/// # Panics
29292929
///
2930-
/// This function will panic if `rhs` is 0 or if `self` is -1 and `rhs` is
2931-
/// `Self::MIN`. This behavior is not affected by the `overflow-checks` flag.
2930+
/// This function will panic if `rhs` is 0 or if `self` is `Self::MIN` and
2931+
/// `rhs` is -1. This behavior is not affected by the `overflow-checks` flag.
29322932
///
29332933
/// # Examples
29342934
///
@@ -2943,6 +2943,11 @@ macro_rules! int_impl {
29432943
/// assert_eq!(a.rem_euclid(-b), 3);
29442944
/// assert_eq!((-a).rem_euclid(-b), 1);
29452945
/// ```
2946+
///
2947+
/// This will panic:
2948+
/// ```should_panic
2949+
#[doc = concat!("let _ = ", stringify!($SelfT), "::MIN.rem_euclid(-1);")]
2950+
/// ```
29462951
#[doc(alias = "modulo", alias = "mod")]
29472952
#[stable(feature = "euclidean_division", since = "1.38.0")]
29482953
#[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.52.0")]
@@ -2971,8 +2976,8 @@ macro_rules! int_impl {
29712976
///
29722977
/// # Panics
29732978
///
2974-
/// This function will panic if `rhs` is 0 or if `self` is -1 and `rhs` is
2975-
/// `Self::MIN`. This behavior is not affected by the `overflow-checks` flag.
2979+
/// This function will panic if `rhs` is 0 or if `self` is `Self::MIN`
2980+
/// and `rhs` is -1. This behavior is not affected by the `overflow-checks` flag.
29762981
///
29772982
/// # Examples
29782983
///
@@ -3007,8 +3012,8 @@ macro_rules! int_impl {
30073012
///
30083013
/// # Panics
30093014
///
3010-
/// This function will panic if `rhs` is 0 or if `self` is -1 and `rhs` is
3011-
/// `Self::MIN`. This behavior is not affected by the `overflow-checks` flag.
3015+
/// This function will panic if `rhs` is 0 or if `self` is `Self::MIN`
3016+
/// and `rhs` is -1. This behavior is not affected by the `overflow-checks` flag.
30123017
///
30133018
/// # Examples
30143019
///

0 commit comments

Comments
 (0)