Skip to content

Commit 1a43c8e

Browse files
borsgitbot
authored and
gitbot
committed
Auto merge of rust-lang#134666 - matthiaskrgr:rollup-whe0chp, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#130289 (docs: Permissions.readonly() also ignores root user special permissions) - rust-lang#134583 (docs: `transmute<&mut T, &mut MaybeUninit<T>>` is unsound when exposed to safe code) - rust-lang#134611 (Align `{i686,x86_64}-win7-windows-msvc` to their parent targets) - rust-lang#134629 (compiletest: Allow using a specific debugger when running debuginfo tests) - rust-lang#134642 (Implement `PointerLike` for `isize`, `NonNull`, `Cell`, `UnsafeCell`, and `SyncUnsafeCell`.) - rust-lang#134660 (Fix spacing of markdown code block fences in compiler rustdoc) r? `@ghost` `@rustbot` modify labels: rollup
2 parents aa5298b + ace863d commit 1a43c8e

File tree

5 files changed

+46
-7
lines changed

5 files changed

+46
-7
lines changed

core/src/cell.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@
252252

253253
use crate::cmp::Ordering;
254254
use crate::fmt::{self, Debug, Display};
255-
use crate::marker::{PhantomData, Unsize};
255+
use crate::marker::{PhantomData, PointerLike, Unsize};
256256
use crate::mem;
257257
use crate::ops::{CoerceUnsized, Deref, DerefMut, DerefPure, DispatchFromDyn};
258258
use crate::pin::PinCoerceUnsized;
@@ -677,6 +677,9 @@ impl<T: CoerceUnsized<U>, U> CoerceUnsized<Cell<U>> for Cell<T> {}
677677
#[unstable(feature = "dispatch_from_dyn", issue = "none")]
678678
impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<Cell<U>> for Cell<T> {}
679679

680+
#[unstable(feature = "pointer_like_trait", issue = "none")]
681+
impl<T: PointerLike> PointerLike for Cell<T> {}
682+
680683
impl<T> Cell<[T]> {
681684
/// Returns a `&[Cell<T>]` from a `&Cell<[T]>`
682685
///
@@ -2258,6 +2261,9 @@ impl<T: CoerceUnsized<U>, U> CoerceUnsized<UnsafeCell<U>> for UnsafeCell<T> {}
22582261
#[unstable(feature = "dispatch_from_dyn", issue = "none")]
22592262
impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<UnsafeCell<U>> for UnsafeCell<T> {}
22602263

2264+
#[unstable(feature = "pointer_like_trait", issue = "none")]
2265+
impl<T: PointerLike> PointerLike for UnsafeCell<T> {}
2266+
22612267
/// [`UnsafeCell`], but [`Sync`].
22622268
///
22632269
/// This is just an `UnsafeCell`, except it implements `Sync`
@@ -2364,6 +2370,9 @@ impl<T: CoerceUnsized<U>, U> CoerceUnsized<SyncUnsafeCell<U>> for SyncUnsafeCell
23642370
//#[unstable(feature = "sync_unsafe_cell", issue = "95439")]
23652371
impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<SyncUnsafeCell<U>> for SyncUnsafeCell<T> {}
23662372

2373+
#[unstable(feature = "pointer_like_trait", issue = "none")]
2374+
impl<T: PointerLike> PointerLike for SyncUnsafeCell<T> {}
2375+
23672376
#[allow(unused)]
23682377
fn assert_coerce_unsized(
23692378
a: UnsafeCell<&i32>,

core/src/marker.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,7 @@ pub trait PointerLike {}
10031003
marker_impls! {
10041004
#[unstable(feature = "pointer_like_trait", issue = "none")]
10051005
PointerLike for
1006+
isize,
10061007
usize,
10071008
{T} &T,
10081009
{T} &mut T,

core/src/mem/maybe_uninit.rs

+20
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,26 @@ use crate::{fmt, intrinsics, ptr, slice};
232232
/// remain `#[repr(transparent)]`. That said, `MaybeUninit<T>` will *always* guarantee that it has
233233
/// the same size, alignment, and ABI as `T`; it's just that the way `MaybeUninit` implements that
234234
/// guarantee may evolve.
235+
///
236+
/// Note that even though `T` and `MaybeUninit<T>` are ABI compatible it is still unsound to
237+
/// transmute `&mut T` to `&mut MaybeUninit<T>` and expose that to safe code because it would allow
238+
/// safe code to access uninitialized memory:
239+
///
240+
/// ```rust,no_run
241+
/// use core::mem::MaybeUninit;
242+
///
243+
/// fn unsound_transmute<T>(val: &mut T) -> &mut MaybeUninit<T> {
244+
/// unsafe { core::mem::transmute(val) }
245+
/// }
246+
///
247+
/// fn main() {
248+
/// let mut code = 0;
249+
/// let code = &mut code;
250+
/// let code2 = unsound_transmute(code);
251+
/// *code2 = MaybeUninit::uninit();
252+
/// std::process::exit(*code); // UB! Accessing uninitialized memory.
253+
/// }
254+
/// ```
235255
#[stable(feature = "maybe_uninit", since = "1.36.0")]
236256
// Lang item so we can wrap other types in it. This is useful for coroutines.
237257
#[lang = "maybe_uninit"]

core/src/ptr/non_null.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1555,6 +1555,10 @@ impl<T: ?Sized, U: ?Sized> DispatchFromDyn<NonNull<U>> for NonNull<T> where T: U
15551555
#[stable(feature = "pin", since = "1.33.0")]
15561556
unsafe impl<T: ?Sized> PinCoerceUnsized for NonNull<T> {}
15571557

1558+
#[unstable(feature = "pointer_like_trait", issue = "none")]
1559+
#[cfg(not(bootstrap))]
1560+
impl<T> core::marker::PointerLike for NonNull<T> {}
1561+
15581562
#[stable(feature = "nonnull", since = "1.25.0")]
15591563
impl<T: ?Sized> fmt::Debug for NonNull<T> {
15601564
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

std/src/fs.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -1869,8 +1869,10 @@ impl Permissions {
18691869
///
18701870
/// # Note
18711871
///
1872-
/// This function does not take Access Control Lists (ACLs) or Unix group
1873-
/// membership into account.
1872+
/// This function does not take Access Control Lists (ACLs), Unix group
1873+
/// membership and other nuances into account.
1874+
/// Therefore the return value of this function cannot be relied upon
1875+
/// to predict whether attempts to read or write the file will actually succeed.
18741876
///
18751877
/// # Windows
18761878
///
@@ -1885,10 +1887,13 @@ impl Permissions {
18851887
/// # Unix (including macOS)
18861888
///
18871889
/// On Unix-based platforms this checks if *any* of the owner, group or others
1888-
/// write permission bits are set. It does not check if the current
1889-
/// user is in the file's assigned group. It also does not check ACLs.
1890-
/// Therefore the return value of this function cannot be relied upon
1891-
/// to predict whether attempts to read or write the file will actually succeed.
1890+
/// write permission bits are set. It does not consider anything else, including:
1891+
///
1892+
/// * Whether the current user is in the file's assigned group.
1893+
/// * Permissions granted by ACL.
1894+
/// * That `root` user can write to files that do not have any write bits set.
1895+
/// * Writable files on a filesystem that is mounted read-only.
1896+
///
18921897
/// The [`PermissionsExt`] trait gives direct access to the permission bits but
18931898
/// also does not read ACLs.
18941899
///

0 commit comments

Comments
 (0)