Skip to content

Commit 3e21768

Browse files
committed
Auto merge of #91486 - matthiaskrgr:rollup-699fo18, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - #88906 (Implement write() method for Box<MaybeUninit<T>>) - #90269 (Make `Option::expect` unstably const) - #90854 (Type can be unsized and uninhabited) - #91170 (rustdoc: preload fonts) - #91273 (Fix ICE #91268 by checking that the snippet ends with a `)`) - #91381 (Android: -ldl must appear after -lgcc when linking) - #91453 (Document Windows TLS drop behaviour) - #91462 (Use try_normalize_erasing_regions in needs_drop) - #91474 (suppress warning about set_errno being unused on DragonFly) - #91483 (Sync rustfmt subtree) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 190367b + a216060 commit 3e21768

File tree

63 files changed

+1949
-455
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1949
-455
lines changed

compiler/rustc_ast_lowering/src/path.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,19 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
229229
if let Ok(snippet) = self.sess.source_map().span_to_snippet(data.span) {
230230
// Do not suggest going from `Trait()` to `Trait<>`
231231
if !data.inputs.is_empty() {
232-
if let Some(split) = snippet.find('(') {
233-
let trait_name = &snippet[0..split];
234-
let args = &snippet[split + 1..snippet.len() - 1];
235-
err.span_suggestion(
236-
data.span,
237-
"use angle brackets instead",
238-
format!("{}<{}>", trait_name, args),
239-
Applicability::MaybeIncorrect,
240-
);
232+
// Suggest replacing `(` and `)` with `<` and `>`
233+
// The snippet may be missing the closing `)`, skip that case
234+
if snippet.ends_with(')') {
235+
if let Some(split) = snippet.find('(') {
236+
let trait_name = &snippet[0..split];
237+
let args = &snippet[split + 1..snippet.len() - 1];
238+
err.span_suggestion(
239+
data.span,
240+
"use angle brackets instead",
241+
format!("{}<{}>", trait_name, args),
242+
Applicability::MaybeIncorrect,
243+
);
244+
}
241245
}
242246
}
243247
};

compiler/rustc_data_structures/src/functor.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@ impl<T> IdFunctor for Box<T> {
2323
let value = raw.read();
2424
// SAFETY: Converts `Box<T>` to `Box<MaybeUninit<T>>` which is the
2525
// inverse of `Box::assume_init()` and should be safe.
26-
let mut raw: Box<mem::MaybeUninit<T>> = Box::from_raw(raw.cast());
26+
let raw: Box<mem::MaybeUninit<T>> = Box::from_raw(raw.cast());
2727
// SAFETY: Write the mapped value back into the `Box`.
28-
raw.write(f(value)?);
29-
// SAFETY: We just initialized `raw`.
30-
raw.assume_init()
28+
Box::write(raw, f(value)?)
3129
})
3230
}
3331
}

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
533533
}
534534
}
535535

536-
if sized && fields.iter().any(|f| f.abi.is_uninhabited()) {
536+
if fields.iter().any(|f| f.abi.is_uninhabited()) {
537537
abi = Abi::Uninhabited;
538538
}
539539

compiler/rustc_middle/src/ty/util.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,10 +788,14 @@ impl<'tcx> ty::TyS<'tcx> {
788788
[component_ty] => component_ty,
789789
_ => self,
790790
};
791+
791792
// This doesn't depend on regions, so try to minimize distinct
792793
// query keys used.
793-
let erased = tcx.normalize_erasing_regions(param_env, query_ty);
794-
tcx.needs_drop_raw(param_env.and(erased))
794+
// If normalization fails, we just use `query_ty`.
795+
let query_ty =
796+
tcx.try_normalize_erasing_regions(param_env, query_ty).unwrap_or(query_ty);
797+
798+
tcx.needs_drop_raw(param_env.and(query_ty))
795799
}
796800
}
797801
}

compiler/rustc_ty_utils/src/needs_drop.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,10 @@ where
147147
Ok(tys) => tys,
148148
};
149149
for required_ty in tys {
150-
let required =
151-
tcx.normalize_erasing_regions(self.param_env, required_ty);
150+
let required = tcx
151+
.try_normalize_erasing_regions(self.param_env, required_ty)
152+
.unwrap_or(required_ty);
153+
152154
queue_type(self, required);
153155
}
154156
}

library/alloc/src/boxed.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,42 @@ impl<T, A: Allocator> Box<mem::MaybeUninit<T>, A> {
763763
let (raw, alloc) = Box::into_raw_with_allocator(self);
764764
unsafe { Box::from_raw_in(raw as *mut T, alloc) }
765765
}
766+
767+
/// Writes the value and converts to `Box<T, A>`.
768+
///
769+
/// This method converts the box similarly to [`Box::assume_init`] but
770+
/// writes `value` into it before conversion thus guaranteeing safety.
771+
/// In some scenarios use of this method may improve performance because
772+
/// the compiler may be able to optimize copying from stack.
773+
///
774+
/// # Examples
775+
///
776+
/// ```
777+
/// #![feature(new_uninit)]
778+
///
779+
/// let big_box = Box::<[usize; 1024]>::new_uninit();
780+
///
781+
/// let mut array = [0; 1024];
782+
/// for (i, place) in array.iter_mut().enumerate() {
783+
/// *place = i;
784+
/// }
785+
///
786+
/// // The optimizer may be able to elide this copy, so previous code writes
787+
/// // to heap directly.
788+
/// let big_box = Box::write(big_box, array);
789+
///
790+
/// for (i, x) in big_box.iter().enumerate() {
791+
/// assert_eq!(*x, i);
792+
/// }
793+
/// ```
794+
#[unstable(feature = "new_uninit", issue = "63291")]
795+
#[inline]
796+
pub fn write(mut boxed: Self, value: T) -> Box<T, A> {
797+
unsafe {
798+
(*boxed).write(value);
799+
boxed.assume_init()
800+
}
801+
}
766802
}
767803

768804
impl<T, A: Allocator> Box<[mem::MaybeUninit<T>], A> {

library/core/src/option.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,8 @@ impl<T> Option<T> {
703703
#[inline]
704704
#[track_caller]
705705
#[stable(feature = "rust1", since = "1.0.0")]
706-
pub fn expect(self, msg: &str) -> T {
706+
#[rustc_const_unstable(feature = "const_option", issue = "67441")]
707+
pub const fn expect(self, msg: &str) -> T {
707708
match self {
708709
Some(val) => val,
709710
None => expect_failed(msg),
@@ -1658,7 +1659,7 @@ impl<T, E> Option<Result<T, E>> {
16581659
#[inline(never)]
16591660
#[cold]
16601661
#[track_caller]
1661-
fn expect_failed(msg: &str) -> ! {
1662+
const fn expect_failed(msg: &str) -> ! {
16621663
panic!("{}", msg)
16631664
}
16641665

library/std/src/sys/unix/os.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ pub fn errno() -> i32 {
9797
}
9898

9999
#[cfg(target_os = "dragonfly")]
100+
#[allow(dead_code)]
100101
pub fn set_errno(e: i32) {
101102
extern "C" {
102103
#[thread_local]

library/std/src/thread/local.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,21 @@ use crate::fmt;
7676
/// destroyed, but not all platforms have this guard. Those platforms that do
7777
/// not guard typically have a synthetic limit after which point no more
7878
/// destructors are run.
79+
/// 3. When the process exits on Windows systems, TLS destructors may only be
80+
/// run on the thread that causes the process to exit. This is because the
81+
/// other threads may be forcibly terminated.
7982
///
83+
/// ## Synchronization in thread-local destructors
84+
///
85+
/// On Windows, synchronization operations (such as [`JoinHandle::join`]) in
86+
/// thread local destructors are prone to deadlocks and so should be avoided.
87+
/// This is because the [loader lock] is held while a destructor is run. The
88+
/// lock is acquired whenever a thread starts or exits or when a DLL is loaded
89+
/// or unloaded. Therefore these events are blocked for as long as a thread
90+
/// local destructor is running.
91+
///
92+
/// [loader lock]: https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-best-practices
93+
/// [`JoinHandle::join`]: crate::thread::JoinHandle::join
8094
/// [`with`]: LocalKey::with
8195
#[stable(feature = "rust1", since = "1.0.0")]
8296
pub struct LocalKey<T: 'static> {

library/unwind/build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ fn main() {
1717
} else {
1818
println!("cargo:rustc-link-lib=gcc");
1919
}
20+
21+
// Android's unwinding library depends on dl_iterate_phdr in `libdl`.
22+
println!("cargo:rustc-link-lib=dl");
2023
} else if target.contains("freebsd") {
2124
println!("cargo:rustc-link-lib=gcc_s");
2225
} else if target.contains("netbsd") {

0 commit comments

Comments
 (0)