Skip to content

Commit e928a46

Browse files
committed
Auto merge of rust-lang#103105 - JohnTitor:rollup-x4ivrix, r=JohnTitor
Rollup of 6 pull requests Successful merges: - rust-lang#101717 (Add documentation about the memory layout of `UnsafeCell<T>`) - rust-lang#102023 (Add MaybeUninit array transpose From impls) - rust-lang#103033 (Update pkg-config) - rust-lang#103080 (pretty: fix to print some lifetimes on HIR pretty-print) - rust-lang#103082 (Surround type with backticks) - rust-lang#103088 (Fix settings page) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 75dbd5b + 66a2bba commit e928a46

File tree

9 files changed

+137
-7
lines changed

9 files changed

+137
-7
lines changed

Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -2652,9 +2652,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
26522652

26532653
[[package]]
26542654
name = "pkg-config"
2655-
version = "0.3.18"
2655+
version = "0.3.25"
26562656
source = "registry+https://github.com/rust-lang/crates.io-index"
2657-
checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33"
2657+
checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae"
26582658

26592659
[[package]]
26602660
name = "polonius-engine"

compiler/rustc_const_eval/src/transform/validate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
284284
this.fail(
285285
location,
286286
format!(
287-
"Field projection `{:?}.{:?}` specified type `{:?}`, but actual type is {:?}",
287+
"Field projection `{:?}.{:?}` specified type `{:?}`, but actual type is `{:?}`",
288288
parent, f, ty, f_ty
289289
)
290290
)

compiler/rustc_hir_pretty/src/lib.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1687,7 +1687,11 @@ impl<'a> State<'a> {
16871687

16881688
let mut nonelided_generic_args: bool = false;
16891689
let elide_lifetimes = generic_args.args.iter().all(|arg| match arg {
1690-
GenericArg::Lifetime(lt) => lt.is_elided(),
1690+
GenericArg::Lifetime(lt) if lt.is_elided() => true,
1691+
GenericArg::Lifetime(_) => {
1692+
nonelided_generic_args = true;
1693+
false
1694+
}
16911695
_ => {
16921696
nonelided_generic_args = true;
16931697
true

library/core/src/cell.rs

+44
Original file line numberDiff line numberDiff line change
@@ -1816,6 +1816,50 @@ impl<T: ?Sized + fmt::Display> fmt::Display for RefMut<'_, T> {
18161816
///
18171817
/// [`.get_mut()`]: `UnsafeCell::get_mut`
18181818
///
1819+
/// `UnsafeCell<T>` has the same in-memory representation as its inner type `T`. A consequence
1820+
/// of this guarantee is that it is possible to convert between `T` and `UnsafeCell<T>`.
1821+
/// Special care has to be taken when converting a nested `T` inside of an `Outer<T>` type
1822+
/// to an `Outer<UnsafeCell<T>>` type: this is not sound when the `Outer<T>` type enables [niche]
1823+
/// optimizations. For example, the type `Option<NonNull<u8>>` is typically 8 bytes large on
1824+
/// 64-bit platforms, but the type `Option<UnsafeCell<NonNull<u8>>>` takes up 16 bytes of space.
1825+
/// Therefore this is not a valid conversion, despite `NonNull<u8>` and `UnsafeCell<NonNull<u8>>>`
1826+
/// having the same memory layout. This is because `UnsafeCell` disables niche optimizations in
1827+
/// order to avoid its interior mutability property from spreading from `T` into the `Outer` type,
1828+
/// thus this can cause distortions in the type size in these cases. Furthermore, it is only valid
1829+
/// to obtain a `*mut T` pointer to the contents of a _shared_ `UnsafeCell<T>` through [`.get()`]
1830+
/// or [`.raw_get()`]. A `&mut T` reference can be obtained by either dereferencing this pointer or
1831+
/// by calling [`.get_mut()`] on an _exclusive_ `UnsafeCell<T>`, e.g.:
1832+
///
1833+
/// ```rust
1834+
/// use std::cell::UnsafeCell;
1835+
///
1836+
/// let mut x: UnsafeCell<u32> = UnsafeCell::new(5);
1837+
/// let shared: &UnsafeCell<u32> = &x;
1838+
/// // using `.get()` is okay:
1839+
/// unsafe {
1840+
/// // SAFETY: there exist no other references to the contents of `x`
1841+
/// let exclusive: &mut u32 = &mut *shared.get();
1842+
/// };
1843+
/// // using `.raw_get()` is also okay:
1844+
/// unsafe {
1845+
/// // SAFETY: there exist no other references to the contents of `x` in this scope
1846+
/// let exclusive: &mut u32 = &mut *UnsafeCell::raw_get(shared as *const _);
1847+
/// };
1848+
/// // using `.get_mut()` is always safe:
1849+
/// let exclusive: &mut u32 = x.get_mut();
1850+
///
1851+
/// // when we have exclusive access, we can convert it to a shared `&UnsafeCell`:
1852+
/// unsafe {
1853+
/// // SAFETY: `u32` has no niche, therefore it has the same layout as `UnsafeCell<u32>`
1854+
/// let shared: &UnsafeCell<u32> = &*(exclusive as *mut _ as *const UnsafeCell<u32>);
1855+
/// // SAFETY: there exist no other *active* references to the contents of `x` in this scope
1856+
/// let exclusive: &mut u32 = &mut *shared.get();
1857+
/// }
1858+
/// ```
1859+
///
1860+
/// [niche]: https://rust-lang.github.io/unsafe-code-guidelines/glossary.html#niche
1861+
/// [`.raw_get()`]: `UnsafeCell::raw_get`
1862+
///
18191863
/// # Examples
18201864
///
18211865
/// Here is an example showcasing how to soundly mutate the contents of an `UnsafeCell<_>` despite

library/core/src/mem/maybe_uninit.rs

+37
Original file line numberDiff line numberDiff line change
@@ -1284,3 +1284,40 @@ impl<T> MaybeUninit<T> {
12841284
}
12851285
}
12861286
}
1287+
1288+
impl<T, const N: usize> MaybeUninit<[T; N]> {
1289+
/// Transposes a `MaybeUninit<[T; N]>` into a `[MaybeUninit<T>; N]`.
1290+
///
1291+
/// # Examples
1292+
///
1293+
/// ```
1294+
/// #![feature(maybe_uninit_uninit_array_transpose)]
1295+
/// # use std::mem::MaybeUninit;
1296+
///
1297+
/// let data: [MaybeUninit<u8>; 1000] = MaybeUninit::uninit().transpose();
1298+
/// ```
1299+
#[unstable(feature = "maybe_uninit_uninit_array_transpose", issue = "96097")]
1300+
pub fn transpose(self) -> [MaybeUninit<T>; N] {
1301+
// SAFETY: T and MaybeUninit<T> have the same layout
1302+
unsafe { super::transmute_copy(&ManuallyDrop::new(self)) }
1303+
}
1304+
}
1305+
1306+
impl<T, const N: usize> [MaybeUninit<T>; N] {
1307+
/// Transposes a `[MaybeUninit<T>; N]` into a `MaybeUninit<[T; N]>`.
1308+
///
1309+
/// # Examples
1310+
///
1311+
/// ```
1312+
/// #![feature(maybe_uninit_uninit_array_transpose)]
1313+
/// # use std::mem::MaybeUninit;
1314+
///
1315+
/// let data = [MaybeUninit::<u8>::uninit(); 1000];
1316+
/// let data: MaybeUninit<[u8; 1000]> = data.transpose();
1317+
/// ```
1318+
#[unstable(feature = "maybe_uninit_uninit_array_transpose", issue = "96097")]
1319+
pub fn transpose(self) -> MaybeUninit<[T; N]> {
1320+
// SAFETY: T and MaybeUninit<T> have the same layout
1321+
unsafe { super::transmute_copy(&ManuallyDrop::new(self)) }
1322+
}
1323+
}

src/librustdoc/html/static/js/settings.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,9 @@
216216
const innerHTML = `<div class="settings">${buildSettingsPageSections(settings)}</div>`;
217217
const el = document.createElement(elementKind);
218218
el.id = "settings";
219-
el.className = "popover";
219+
if (!isSettingsPage) {
220+
el.className = "popover";
221+
}
220222
el.innerHTML = innerHTML;
221223

222224
if (isSettingsPage) {

src/test/pretty/issue-85089.pp

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#[prelude_import]
2+
use ::std::prelude::rust_2015::*;
3+
#[macro_use]
4+
extern crate std;
5+
// Test to print lifetimes on HIR pretty-printing.
6+
7+
// pretty-compare-only
8+
// pretty-mode:hir
9+
// pp-exact:issue-85089.pp
10+
11+
trait A<'x> { }
12+
trait B<'x> { }
13+
14+
struct Foo<'b> {
15+
bar: &'b dyn for<'a> A<'a>,
16+
}
17+
18+
impl <'a> B<'a> for dyn for<'b> A<'b> { }
19+
20+
impl <'a> A<'a> for Foo<'a> { }

src/test/pretty/issue-85089.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Test to print lifetimes on HIR pretty-printing.
2+
3+
// pretty-compare-only
4+
// pretty-mode:hir
5+
// pp-exact:issue-85089.pp
6+
7+
trait A<'x> {}
8+
trait B<'x> {}
9+
10+
struct Foo<'b> {
11+
pub bar: &'b dyn for<'a> A<'a>,
12+
}
13+
14+
impl<'a> B<'a> for dyn for<'b> A<'b> {}
15+
16+
impl<'a> A<'a> for Foo<'a> {}

src/test/rustdoc-gui/settings.goml

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// This test ensures that the settings menu display is working as expected.
1+
// This test ensures that the settings menu display is working as expected and that
2+
// the settings page is also rendered as expected.
23
goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
34
show-text: true // needed when we check for colors below.
45
// First, we check that the settings page doesn't exist.
@@ -140,7 +141,13 @@ assert-css: ("#settings-menu .popover", {"display": "none"})
140141
// Now we go to the settings page to check that the CSS is loaded as expected.
141142
goto: "file://" + |DOC_PATH| + "/settings.html"
142143
wait-for: "#settings"
143-
assert-css: (".setting-line .toggle .slider", {"width": "45px", "margin-right": "20px"})
144+
assert-css: (
145+
".setting-line .toggle .slider",
146+
{"width": "45px", "margin-right": "20px", "border": "0px none rgb(0, 0, 0)"},
147+
)
148+
149+
assert-attribute-false: ("#settings", {"class": "popover"}, CONTAINS)
150+
compare-elements-position: (".sub-container", "#settings", ("x"))
144151

145152
// We now check the display with JS disabled.
146153
assert-false: "noscript section"

0 commit comments

Comments
 (0)