Skip to content

Commit 3e21768

Browse files
committed
Auto merge of rust-lang#91486 - matthiaskrgr:rollup-699fo18, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - rust-lang#88906 (Implement write() method for Box<MaybeUninit<T>>) - rust-lang#90269 (Make `Option::expect` unstably const) - rust-lang#90854 (Type can be unsized and uninhabited) - rust-lang#91170 (rustdoc: preload fonts) - rust-lang#91273 (Fix ICE rust-lang#91268 by checking that the snippet ends with a `)`) - rust-lang#91381 (Android: -ldl must appear after -lgcc when linking) - rust-lang#91453 (Document Windows TLS drop behaviour) - rust-lang#91462 (Use try_normalize_erasing_regions in needs_drop) - rust-lang#91474 (suppress warning about set_errno being unused on DragonFly) - rust-lang#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

+13-9
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

+2-4
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

+1-1
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

+6-2
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

+4-2
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

+36
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

+3-2
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

+1
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

+14
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

+3
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") {

src/librustdoc/html/templates/page.html

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
<meta name="description" content="{{page.description}}"> {#- -#}
88
<meta name="keywords" content="{{page.keywords}}"> {#- -#}
99
<title>{{page.title}}</title> {#- -#}
10+
<link rel="preload" as="font" type="font/woff2" crossorigin href="{{static_root_path | safe}}SourceSerif4-Regular.ttf.woff2"> {#- -#}
11+
<link rel="preload" as="font" type="font/woff2" crossorigin href="{{static_root_path | safe}}FiraSans-Regular.woff2"> {#- -#}
12+
<link rel="preload" as="font" type="font/woff2" crossorigin href="{{static_root_path | safe}}FiraSans-Medium.woff2"> {#- -#}
13+
<link rel="preload" as="font" type="font/woff2" crossorigin href="{{static_root_path | safe}}SourceCodePro-Regular.ttf.woff2"> {#- -#}
14+
<link rel="preload" as="font" type="font/woff2" crossorigin href="{{static_root_path | safe}}SourceSerif4-Bold.ttf.woff2"> {#- -#}
15+
<link rel="preload" as="font" type="font/woff2" crossorigin href="{{static_root_path | safe}}SourceCodePro-Semibold.ttf.woff2"> {#- -#}
1016
<link rel="stylesheet" type="text/css" {# -#}
1117
href="{{static_root_path | safe}}normalize{{page.resource_suffix}}.css"> {#- -#}
1218
<link rel="stylesheet" type="text/css" {# -#}

src/test/ui/issues/issue-88150.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// run-pass
2+
// compile-flags:-C debuginfo=2
3+
// edition:2018
4+
5+
use core::marker::PhantomData;
6+
7+
pub struct Foo<T: ?Sized, A>(
8+
PhantomData<(A, T)>,
9+
);
10+
11+
enum Never {}
12+
13+
impl<T: ?Sized> Foo<T, Never> {
14+
fn new_foo() -> Foo<T, Never> {
15+
Foo(PhantomData)
16+
}
17+
}
18+
19+
fn main() {
20+
let _ = Foo::<[()], Never>::new_foo();
21+
}

src/test/ui/type/issue-91268.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// error-pattern: this file contains an unclosed delimiter
2+
// error-pattern: cannot find type `ţ` in this scope
3+
// error-pattern: parenthesized type parameters may only be used with a `Fn` trait
4+
// error-pattern: type arguments are not allowed for this type
5+
// error-pattern: mismatched types
6+
// ignore-tidy-trailing-newlines
7+
// `ţ` must be the last character in this file, it cannot be followed by a newline
8+
fn main() {
9+
0: u8(ţ

src/test/ui/type/issue-91268.stderr

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
error: this file contains an unclosed delimiter
2+
--> $DIR/issue-91268.rs:9:12
3+
|
4+
LL | fn main() {
5+
| - unclosed delimiter
6+
LL | 0: u8(ţ
7+
| - ^
8+
| |
9+
| unclosed delimiter
10+
11+
error: this file contains an unclosed delimiter
12+
--> $DIR/issue-91268.rs:9:12
13+
|
14+
LL | fn main() {
15+
| - unclosed delimiter
16+
LL | 0: u8(ţ
17+
| - ^
18+
| |
19+
| unclosed delimiter
20+
21+
error[E0412]: cannot find type `ţ` in this scope
22+
--> $DIR/issue-91268.rs:9:11
23+
|
24+
LL | 0: u8(ţ
25+
| ^ expecting a type here because of type ascription
26+
27+
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
28+
--> $DIR/issue-91268.rs:9:8
29+
|
30+
LL | 0: u8(ţ
31+
| ^^^^ only `Fn` traits may use parentheses
32+
33+
error[E0109]: type arguments are not allowed for this type
34+
--> $DIR/issue-91268.rs:9:11
35+
|
36+
LL | 0: u8(ţ
37+
| ^ type argument not allowed
38+
39+
error[E0308]: mismatched types
40+
--> $DIR/issue-91268.rs:9:5
41+
|
42+
LL | fn main() {
43+
| - expected `()` because of default return type
44+
LL | 0: u8(ţ
45+
| ^^^^^^^ expected `()`, found `u8`
46+
47+
error: aborting due to 6 previous errors
48+
49+
Some errors have detailed explanations: E0109, E0214, E0308, E0412.
50+
For more information about an error, try `rustc --explain E0109`.

src/test/ui/union/issue-81199.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#[repr(C)]
2+
union PtrRepr<T: ?Sized> {
3+
const_ptr: *const T,
4+
mut_ptr: *mut T,
5+
components: PtrComponents<T>,
6+
//~^ ERROR the trait bound
7+
}
8+
9+
#[repr(C)]
10+
struct PtrComponents<T: Pointee + ?Sized> {
11+
data_address: *const (),
12+
metadata: <T as Pointee>::Metadata,
13+
}
14+
15+
16+
17+
pub trait Pointee {
18+
type Metadata;
19+
}
20+
21+
fn main() {}

src/test/ui/union/issue-81199.stderr

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
error[E0277]: the trait bound `T: Pointee` is not satisfied in `PtrComponents<T>`
2+
--> $DIR/issue-81199.rs:5:17
3+
|
4+
LL | components: PtrComponents<T>,
5+
| ^^^^^^^^^^^^^^^^ within `PtrComponents<T>`, the trait `Pointee` is not implemented for `T`
6+
|
7+
note: required because it appears within the type `PtrComponents<T>`
8+
--> $DIR/issue-81199.rs:10:8
9+
|
10+
LL | struct PtrComponents<T: Pointee + ?Sized> {
11+
| ^^^^^^^^^^^^^
12+
= note: no field of a union may have a dynamically sized type
13+
= help: change the field's type to have a statically known size
14+
help: consider further restricting this bound
15+
|
16+
LL | union PtrRepr<T: ?Sized + Pointee> {
17+
| +++++++++
18+
help: borrowed types always have a statically known size
19+
|
20+
LL | components: &PtrComponents<T>,
21+
| +
22+
help: the `Box` type always has a statically known size and allocates its contents in the heap
23+
|
24+
LL | components: Box<PtrComponents<T>>,
25+
| ++++ +
26+
27+
error: aborting due to previous error
28+
29+
For more information about this error, try `rustc --explain E0277`.

src/tools/rustfmt/.github/workflows/linux.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ on:
88
jobs:
99
test:
1010
runs-on: ubuntu-latest
11-
name: (${{ matrix.target }}, nightly)
11+
name: (${{ matrix.target }}, ${{ matrix.cfg_release_channel }})
12+
env:
13+
CFG_RELEASE_CHANNEL: ${{ matrix.cfg_release_channel }}
1214
strategy:
1315
# https://help.github.com/en/actions/getting-started-with-github-actions/about-github-actions#usage-limits
1416
# There's a limit of 60 concurrent jobs across all repos in the rust-lang organization.
@@ -20,6 +22,7 @@ jobs:
2022
target: [
2123
x86_64-unknown-linux-gnu,
2224
]
25+
cfg_release_channel: [nightly, stable]
2326

2427
steps:
2528
- name: checkout

src/tools/rustfmt/.github/workflows/mac.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ jobs:
1010
# https://help.github.com/en/actions/automating-your-workflow-with-github-actions/virtual-environments-for-github-hosted-runners#supported-runners-and-hardware-resources
1111
# macOS Catalina 10.15
1212
runs-on: macos-latest
13-
name: (${{ matrix.target }}, nightly)
13+
name: (${{ matrix.target }}, ${{ matrix.cfg_release_channel }})
14+
env:
15+
CFG_RELEASE_CHANNEL: ${{ matrix.cfg_release_channel }}
1416
strategy:
1517
fail-fast: false
1618
matrix:
1719
target: [
1820
x86_64-apple-darwin,
1921
]
22+
cfg_release_channel: [nightly, stable]
2023

2124
steps:
2225
- name: checkout

src/tools/rustfmt/.github/workflows/windows.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ on:
88
jobs:
99
test:
1010
runs-on: windows-latest
11-
name: (${{ matrix.target }}, nightly)
11+
name: (${{ matrix.target }}, ${{ matrix.cfg_release_channel }})
12+
env:
13+
CFG_RELEASE_CHANNEL: ${{ matrix.cfg_release_channel }}
1214
strategy:
1315
# https://help.github.com/en/actions/getting-started-with-github-actions/about-github-actions#usage-limits
1416
# There's a limit of 60 concurrent jobs across all repos in the rust-lang organization.
@@ -23,6 +25,7 @@ jobs:
2325
x86_64-pc-windows-gnu,
2426
x86_64-pc-windows-msvc,
2527
]
28+
cfg_release_channel: [nightly, stable]
2629

2730
steps:
2831
# The Windows runners have autocrlf enabled by default

0 commit comments

Comments
 (0)