Skip to content

Commit

Permalink
Auto merge of #91486 - matthiaskrgr:rollup-699fo18, r=matthiaskrgr
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Dec 3, 2021
2 parents 190367b + a216060 commit 3e21768
Show file tree
Hide file tree
Showing 63 changed files with 1,949 additions and 455 deletions.
22 changes: 13 additions & 9 deletions compiler/rustc_ast_lowering/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,19 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
if let Ok(snippet) = self.sess.source_map().span_to_snippet(data.span) {
// Do not suggest going from `Trait()` to `Trait<>`
if !data.inputs.is_empty() {
if let Some(split) = snippet.find('(') {
let trait_name = &snippet[0..split];
let args = &snippet[split + 1..snippet.len() - 1];
err.span_suggestion(
data.span,
"use angle brackets instead",
format!("{}<{}>", trait_name, args),
Applicability::MaybeIncorrect,
);
// Suggest replacing `(` and `)` with `<` and `>`
// The snippet may be missing the closing `)`, skip that case
if snippet.ends_with(')') {
if let Some(split) = snippet.find('(') {
let trait_name = &snippet[0..split];
let args = &snippet[split + 1..snippet.len() - 1];
err.span_suggestion(
data.span,
"use angle brackets instead",
format!("{}<{}>", trait_name, args),
Applicability::MaybeIncorrect,
);
}
}
}
};
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_data_structures/src/functor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ impl<T> IdFunctor for Box<T> {
let value = raw.read();
// SAFETY: Converts `Box<T>` to `Box<MaybeUninit<T>>` which is the
// inverse of `Box::assume_init()` and should be safe.
let mut raw: Box<mem::MaybeUninit<T>> = Box::from_raw(raw.cast());
let raw: Box<mem::MaybeUninit<T>> = Box::from_raw(raw.cast());
// SAFETY: Write the mapped value back into the `Box`.
raw.write(f(value)?);
// SAFETY: We just initialized `raw`.
raw.assume_init()
Box::write(raw, f(value)?)
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
}
}

if sized && fields.iter().any(|f| f.abi.is_uninhabited()) {
if fields.iter().any(|f| f.abi.is_uninhabited()) {
abi = Abi::Uninhabited;
}

Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_middle/src/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,10 +788,14 @@ impl<'tcx> ty::TyS<'tcx> {
[component_ty] => component_ty,
_ => self,
};

// This doesn't depend on regions, so try to minimize distinct
// query keys used.
let erased = tcx.normalize_erasing_regions(param_env, query_ty);
tcx.needs_drop_raw(param_env.and(erased))
// If normalization fails, we just use `query_ty`.
let query_ty =
tcx.try_normalize_erasing_regions(param_env, query_ty).unwrap_or(query_ty);

tcx.needs_drop_raw(param_env.and(query_ty))
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_ty_utils/src/needs_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,10 @@ where
Ok(tys) => tys,
};
for required_ty in tys {
let required =
tcx.normalize_erasing_regions(self.param_env, required_ty);
let required = tcx
.try_normalize_erasing_regions(self.param_env, required_ty)
.unwrap_or(required_ty);

queue_type(self, required);
}
}
Expand Down
36 changes: 36 additions & 0 deletions library/alloc/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,42 @@ impl<T, A: Allocator> Box<mem::MaybeUninit<T>, A> {
let (raw, alloc) = Box::into_raw_with_allocator(self);
unsafe { Box::from_raw_in(raw as *mut T, alloc) }
}

/// Writes the value and converts to `Box<T, A>`.
///
/// This method converts the box similarly to [`Box::assume_init`] but
/// writes `value` into it before conversion thus guaranteeing safety.
/// In some scenarios use of this method may improve performance because
/// the compiler may be able to optimize copying from stack.
///
/// # Examples
///
/// ```
/// #![feature(new_uninit)]
///
/// let big_box = Box::<[usize; 1024]>::new_uninit();
///
/// let mut array = [0; 1024];
/// for (i, place) in array.iter_mut().enumerate() {
/// *place = i;
/// }
///
/// // The optimizer may be able to elide this copy, so previous code writes
/// // to heap directly.
/// let big_box = Box::write(big_box, array);
///
/// for (i, x) in big_box.iter().enumerate() {
/// assert_eq!(*x, i);
/// }
/// ```
#[unstable(feature = "new_uninit", issue = "63291")]
#[inline]
pub fn write(mut boxed: Self, value: T) -> Box<T, A> {
unsafe {
(*boxed).write(value);
boxed.assume_init()
}
}
}

impl<T, A: Allocator> Box<[mem::MaybeUninit<T>], A> {
Expand Down
5 changes: 3 additions & 2 deletions library/core/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,8 @@ impl<T> Option<T> {
#[inline]
#[track_caller]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn expect(self, msg: &str) -> T {
#[rustc_const_unstable(feature = "const_option", issue = "67441")]
pub const fn expect(self, msg: &str) -> T {
match self {
Some(val) => val,
None => expect_failed(msg),
Expand Down Expand Up @@ -1658,7 +1659,7 @@ impl<T, E> Option<Result<T, E>> {
#[inline(never)]
#[cold]
#[track_caller]
fn expect_failed(msg: &str) -> ! {
const fn expect_failed(msg: &str) -> ! {
panic!("{}", msg)
}

Expand Down
1 change: 1 addition & 0 deletions library/std/src/sys/unix/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ pub fn errno() -> i32 {
}

#[cfg(target_os = "dragonfly")]
#[allow(dead_code)]
pub fn set_errno(e: i32) {
extern "C" {
#[thread_local]
Expand Down
14 changes: 14 additions & 0 deletions library/std/src/thread/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,21 @@ use crate::fmt;
/// destroyed, but not all platforms have this guard. Those platforms that do
/// not guard typically have a synthetic limit after which point no more
/// destructors are run.
/// 3. When the process exits on Windows systems, TLS destructors may only be
/// run on the thread that causes the process to exit. This is because the
/// other threads may be forcibly terminated.
///
/// ## Synchronization in thread-local destructors
///
/// On Windows, synchronization operations (such as [`JoinHandle::join`]) in
/// thread local destructors are prone to deadlocks and so should be avoided.
/// This is because the [loader lock] is held while a destructor is run. The
/// lock is acquired whenever a thread starts or exits or when a DLL is loaded
/// or unloaded. Therefore these events are blocked for as long as a thread
/// local destructor is running.
///
/// [loader lock]: https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-best-practices
/// [`JoinHandle::join`]: crate::thread::JoinHandle::join
/// [`with`]: LocalKey::with
#[stable(feature = "rust1", since = "1.0.0")]
pub struct LocalKey<T: 'static> {
Expand Down
3 changes: 3 additions & 0 deletions library/unwind/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ fn main() {
} else {
println!("cargo:rustc-link-lib=gcc");
}

// Android's unwinding library depends on dl_iterate_phdr in `libdl`.
println!("cargo:rustc-link-lib=dl");
} else if target.contains("freebsd") {
println!("cargo:rustc-link-lib=gcc_s");
} else if target.contains("netbsd") {
Expand Down
6 changes: 6 additions & 0 deletions src/librustdoc/html/templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
<meta name="description" content="{{page.description}}"> {#- -#}
<meta name="keywords" content="{{page.keywords}}"> {#- -#}
<title>{{page.title}}</title> {#- -#}
<link rel="preload" as="font" type="font/woff2" crossorigin href="{{static_root_path | safe}}SourceSerif4-Regular.ttf.woff2"> {#- -#}
<link rel="preload" as="font" type="font/woff2" crossorigin href="{{static_root_path | safe}}FiraSans-Regular.woff2"> {#- -#}
<link rel="preload" as="font" type="font/woff2" crossorigin href="{{static_root_path | safe}}FiraSans-Medium.woff2"> {#- -#}
<link rel="preload" as="font" type="font/woff2" crossorigin href="{{static_root_path | safe}}SourceCodePro-Regular.ttf.woff2"> {#- -#}
<link rel="preload" as="font" type="font/woff2" crossorigin href="{{static_root_path | safe}}SourceSerif4-Bold.ttf.woff2"> {#- -#}
<link rel="preload" as="font" type="font/woff2" crossorigin href="{{static_root_path | safe}}SourceCodePro-Semibold.ttf.woff2"> {#- -#}
<link rel="stylesheet" type="text/css" {# -#}
href="{{static_root_path | safe}}normalize{{page.resource_suffix}}.css"> {#- -#}
<link rel="stylesheet" type="text/css" {# -#}
Expand Down
21 changes: 21 additions & 0 deletions src/test/ui/issues/issue-88150.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// run-pass
// compile-flags:-C debuginfo=2
// edition:2018

use core::marker::PhantomData;

pub struct Foo<T: ?Sized, A>(
PhantomData<(A, T)>,
);

enum Never {}

impl<T: ?Sized> Foo<T, Never> {
fn new_foo() -> Foo<T, Never> {
Foo(PhantomData)
}
}

fn main() {
let _ = Foo::<[()], Never>::new_foo();
}
9 changes: 9 additions & 0 deletions src/test/ui/type/issue-91268.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// error-pattern: this file contains an unclosed delimiter
// error-pattern: cannot find type `ţ` in this scope
// error-pattern: parenthesized type parameters may only be used with a `Fn` trait
// error-pattern: type arguments are not allowed for this type
// error-pattern: mismatched types
// ignore-tidy-trailing-newlines
// `ţ` must be the last character in this file, it cannot be followed by a newline
fn main() {
0: u8(ţ
50 changes: 50 additions & 0 deletions src/test/ui/type/issue-91268.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
error: this file contains an unclosed delimiter
--> $DIR/issue-91268.rs:9:12
|
LL | fn main() {
| - unclosed delimiter
LL | 0: u8(ţ
| - ^
| |
| unclosed delimiter

error: this file contains an unclosed delimiter
--> $DIR/issue-91268.rs:9:12
|
LL | fn main() {
| - unclosed delimiter
LL | 0: u8(ţ
| - ^
| |
| unclosed delimiter

error[E0412]: cannot find type `ţ` in this scope
--> $DIR/issue-91268.rs:9:11
|
LL | 0: u8(ţ
| ^ expecting a type here because of type ascription

error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
--> $DIR/issue-91268.rs:9:8
|
LL | 0: u8(ţ
| ^^^^ only `Fn` traits may use parentheses

error[E0109]: type arguments are not allowed for this type
--> $DIR/issue-91268.rs:9:11
|
LL | 0: u8(ţ
| ^ type argument not allowed

error[E0308]: mismatched types
--> $DIR/issue-91268.rs:9:5
|
LL | fn main() {
| - expected `()` because of default return type
LL | 0: u8(ţ
| ^^^^^^^ expected `()`, found `u8`

error: aborting due to 6 previous errors

Some errors have detailed explanations: E0109, E0214, E0308, E0412.
For more information about an error, try `rustc --explain E0109`.
21 changes: 21 additions & 0 deletions src/test/ui/union/issue-81199.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#[repr(C)]
union PtrRepr<T: ?Sized> {
const_ptr: *const T,
mut_ptr: *mut T,
components: PtrComponents<T>,
//~^ ERROR the trait bound
}

#[repr(C)]
struct PtrComponents<T: Pointee + ?Sized> {
data_address: *const (),
metadata: <T as Pointee>::Metadata,
}



pub trait Pointee {
type Metadata;
}

fn main() {}
29 changes: 29 additions & 0 deletions src/test/ui/union/issue-81199.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
error[E0277]: the trait bound `T: Pointee` is not satisfied in `PtrComponents<T>`
--> $DIR/issue-81199.rs:5:17
|
LL | components: PtrComponents<T>,
| ^^^^^^^^^^^^^^^^ within `PtrComponents<T>`, the trait `Pointee` is not implemented for `T`
|
note: required because it appears within the type `PtrComponents<T>`
--> $DIR/issue-81199.rs:10:8
|
LL | struct PtrComponents<T: Pointee + ?Sized> {
| ^^^^^^^^^^^^^
= note: no field of a union may have a dynamically sized type
= help: change the field's type to have a statically known size
help: consider further restricting this bound
|
LL | union PtrRepr<T: ?Sized + Pointee> {
| +++++++++
help: borrowed types always have a statically known size
|
LL | components: &PtrComponents<T>,
| +
help: the `Box` type always has a statically known size and allocates its contents in the heap
|
LL | components: Box<PtrComponents<T>>,
| ++++ +

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
5 changes: 4 additions & 1 deletion src/tools/rustfmt/.github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ on:
jobs:
test:
runs-on: ubuntu-latest
name: (${{ matrix.target }}, nightly)
name: (${{ matrix.target }}, ${{ matrix.cfg_release_channel }})
env:
CFG_RELEASE_CHANNEL: ${{ matrix.cfg_release_channel }}
strategy:
# https://help.github.com/en/actions/getting-started-with-github-actions/about-github-actions#usage-limits
# There's a limit of 60 concurrent jobs across all repos in the rust-lang organization.
Expand All @@ -20,6 +22,7 @@ jobs:
target: [
x86_64-unknown-linux-gnu,
]
cfg_release_channel: [nightly, stable]

steps:
- name: checkout
Expand Down
5 changes: 4 additions & 1 deletion src/tools/rustfmt/.github/workflows/mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ jobs:
# https://help.github.com/en/actions/automating-your-workflow-with-github-actions/virtual-environments-for-github-hosted-runners#supported-runners-and-hardware-resources
# macOS Catalina 10.15
runs-on: macos-latest
name: (${{ matrix.target }}, nightly)
name: (${{ matrix.target }}, ${{ matrix.cfg_release_channel }})
env:
CFG_RELEASE_CHANNEL: ${{ matrix.cfg_release_channel }}
strategy:
fail-fast: false
matrix:
target: [
x86_64-apple-darwin,
]
cfg_release_channel: [nightly, stable]

steps:
- name: checkout
Expand Down
5 changes: 4 additions & 1 deletion src/tools/rustfmt/.github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ on:
jobs:
test:
runs-on: windows-latest
name: (${{ matrix.target }}, nightly)
name: (${{ matrix.target }}, ${{ matrix.cfg_release_channel }})
env:
CFG_RELEASE_CHANNEL: ${{ matrix.cfg_release_channel }}
strategy:
# https://help.github.com/en/actions/getting-started-with-github-actions/about-github-actions#usage-limits
# There's a limit of 60 concurrent jobs across all repos in the rust-lang organization.
Expand All @@ -23,6 +25,7 @@ jobs:
x86_64-pc-windows-gnu,
x86_64-pc-windows-msvc,
]
cfg_release_channel: [nightly, stable]

steps:
# The Windows runners have autocrlf enabled by default
Expand Down
Loading

0 comments on commit 3e21768

Please sign in to comment.