Skip to content

Commit

Permalink
Auto merge of rust-lang#82982 - Dylan-DPC:rollup-mt497z7, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 9 pull requests

Successful merges:

 - rust-lang#81309 (always eagerly eval consts in Relate)
 - rust-lang#82217 (Edition-specific preludes)
 - rust-lang#82807 (rustdoc: Remove redundant enableSearchInput function)
 - rust-lang#82924 (WASI: Switch to crt1-command.o to enable support for new-style commands)
 - rust-lang#82949 (Do not attempt to unlock envlock in child process after a fork.)
 - rust-lang#82955 (fix: wrong word)
 - rust-lang#82962 (Treat header as first paragraph for shortened markdown descriptions)
 - rust-lang#82976 (fix error message for copy(_nonoverlapping) overflow)
 - rust-lang#82977 (Rename `Option::get_or_default` to `get_or_insert_default`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Mar 10, 2021
2 parents 17a07d7 + e583132 commit f98721f
Show file tree
Hide file tree
Showing 40 changed files with 228 additions and 104 deletions.
30 changes: 19 additions & 11 deletions compiler/rustc_builtin_macros/src/standard_library_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use rustc_ast as ast;
use rustc_expand::base::{ExtCtxt, ResolverExpand};
use rustc_expand::expand::ExpansionConfig;
use rustc_session::Session;
use rustc_span::edition::Edition;
use rustc_span::edition::Edition::*;
use rustc_span::hygiene::AstPass;
use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::DUMMY_SP;
Expand All @@ -13,7 +13,7 @@ pub fn inject(
sess: &Session,
alt_std_name: Option<Symbol>,
) -> ast::Crate {
let rust_2018 = sess.parse_sess.edition >= Edition::Edition2018;
let edition = sess.parse_sess.edition;

// the first name in this list is the crate name of the crate with the prelude
let names: &[Symbol] = if sess.contains_name(&krate.attrs, sym::no_core) {
Expand Down Expand Up @@ -42,7 +42,11 @@ pub fn inject(

// .rev() to preserve ordering above in combination with insert(0, ...)
for &name in names.iter().rev() {
let ident = if rust_2018 { Ident::new(name, span) } else { Ident::new(name, call_site) };
let ident = if edition >= Edition2018 {
Ident::new(name, span)
} else {
Ident::new(name, call_site)
};
krate.items.insert(
0,
cx.item(
Expand All @@ -58,14 +62,18 @@ pub fn inject(
// the one with the prelude.
let name = names[0];

let import_path = if rust_2018 {
[name, sym::prelude, sym::v1].iter().map(|symbol| Ident::new(*symbol, span)).collect()
} else {
[kw::PathRoot, name, sym::prelude, sym::v1]
.iter()
.map(|symbol| Ident::new(*symbol, span))
.collect()
};
let root = (edition == Edition2015).then(|| kw::PathRoot);

let import_path = root
.iter()
.chain(&[name, sym::prelude])
.chain(&[match edition {
Edition2015 => sym::rust_2015,
Edition2018 => sym::rust_2018,
Edition2021 => sym::rust_2021,
}])
.map(|&symbol| Ident::new(symbol, span))
.collect();

let use_item = cx.item(
span,
Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_middle/src/ty/relate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,12 +421,14 @@ pub fn super_relate_tys<R: TypeRelation<'tcx>>(
let t = relation.relate(a_t, b_t)?;
match relation.relate(sz_a, sz_b) {
Ok(sz) => Ok(tcx.mk_ty(ty::Array(t, sz))),
// FIXME(#72219) Implement improved diagnostics for mismatched array
// length?
Err(err) if relation.tcx().lazy_normalization() => Err(err),
Err(err) => {
// Check whether the lengths are both concrete/known values,
// but are unequal, for better diagnostics.
//
// It might seem dubious to eagerly evaluate these constants here,
// we however cannot end up with errors in `Relate` during both
// `type_of` and `predicates_of`. This means that evaluating the
// constants should not cause cycle errors here.
let sz_a = sz_a.try_eval_usize(tcx, relation.param_env());
let sz_b = sz_b.try_eval_usize(tcx, relation.param_env());
match (sz_a, sz_b) {
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_mir/src/interpret/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
let layout = self.layout_of(src.layout.ty.builtin_deref(true).unwrap().ty)?;
let (size, align) = (layout.size, layout.align.abi);
let size = size.checked_mul(count, self).ok_or_else(|| {
err_ub_format!("overflow computing total size of `copy_nonoverlapping`")
err_ub_format!(
"overflow computing total size of `{}`",
if nonoverlapping { "copy_nonoverlapping" } else { "copy" }
)
})?;

// Make sure we check both pointers for an access of the total size and aligment,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Rust MIR: a lowered representation of Rust.
#![feature(stmt_expr_attributes)]
#![feature(trait_alias)]
#![feature(option_expect_none)]
#![feature(option_get_or_default)]
#![feature(option_get_or_insert_default)]
#![feature(or_patterns)]
#![feature(once_cell)]
#![feature(control_flow_enum)]
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_mir/src/transform/coverage/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,8 @@ impl BasicCoverageBlockData {
}
}
let operand = counter_kind.as_operand_id();
if let Some(replaced) = self.edge_from_bcbs.get_or_default().insert(from_bcb, counter_kind)
if let Some(replaced) =
self.edge_from_bcbs.get_or_insert_default().insert(from_bcb, counter_kind)
{
Error::from_string(format!(
"attempt to set an edge counter more than once; from_bcb: \
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_span/src/edition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub enum Edition {
Edition2015,
/// The 2018 edition
Edition2018,
/// The 2021 ediiton
/// The 2021 edition
Edition2021,
}

Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -959,8 +959,11 @@ symbols! {
rt,
rtm_target_feature,
rust,
rust_2015,
rust_2015_preview,
rust_2018,
rust_2018_preview,
rust_2021,
rust_2021_preview,
rust_begin_unwind,
rust_eh_catch_typeinfo,
Expand Down
10 changes: 6 additions & 4 deletions compiler/rustc_target/src/spec/crt_objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,13 @@ pub(super) fn post_mingw() -> CrtObjects {
}

pub(super) fn pre_wasi_fallback() -> CrtObjects {
// Use crt1-command.o instead of crt1.o to enable support for new-style
// commands. See https://reviews.llvm.org/D81689 for more info.
new(&[
(LinkOutputKind::DynamicNoPicExe, &["crt1.o"]),
(LinkOutputKind::DynamicPicExe, &["crt1.o"]),
(LinkOutputKind::StaticNoPicExe, &["crt1.o"]),
(LinkOutputKind::StaticPicExe, &["crt1.o"]),
(LinkOutputKind::DynamicNoPicExe, &["crt1-command.o"]),
(LinkOutputKind::DynamicPicExe, &["crt1-command.o"]),
(LinkOutputKind::StaticNoPicExe, &["crt1-command.o"]),
(LinkOutputKind::StaticPicExe, &["crt1-command.o"]),
(LinkOutputKind::WasiReactorExe, &["crt1-reactor.o"]),
])
}
Expand Down
34 changes: 17 additions & 17 deletions library/core/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -854,55 +854,55 @@ impl<T> Option<T> {
// Entry-like operations to insert if None and return a reference
/////////////////////////////////////////////////////////////////////////

/// Inserts the default value into the option if it is [`None`], then
/// Inserts `value` into the option if it is [`None`], then
/// returns a mutable reference to the contained value.
///
/// # Examples
///
/// ```
/// #![feature(option_get_or_default)]
///
/// let mut x = None;
///
/// {
/// let y: &mut u32 = x.get_or_default();
/// assert_eq!(y, &0);
/// let y: &mut u32 = x.get_or_insert(5);
/// assert_eq!(y, &5);
///
/// *y = 7;
/// }
///
/// assert_eq!(x, Some(7));
/// ```
#[inline]
#[unstable(feature = "option_get_or_default", issue = "82901")]
pub fn get_or_default(&mut self) -> &mut T
where
T: Default,
{
self.get_or_insert_with(Default::default)
#[stable(feature = "option_entry", since = "1.20.0")]
pub fn get_or_insert(&mut self, value: T) -> &mut T {
self.get_or_insert_with(|| value)
}

/// Inserts `value` into the option if it is [`None`], then
/// Inserts the default value into the option if it is [`None`], then
/// returns a mutable reference to the contained value.
///
/// # Examples
///
/// ```
/// #![feature(option_get_or_insert_default)]
///
/// let mut x = None;
///
/// {
/// let y: &mut u32 = x.get_or_insert(5);
/// assert_eq!(y, &5);
/// let y: &mut u32 = x.get_or_insert_default();
/// assert_eq!(y, &0);
///
/// *y = 7;
/// }
///
/// assert_eq!(x, Some(7));
/// ```
#[inline]
#[stable(feature = "option_entry", since = "1.20.0")]
pub fn get_or_insert(&mut self, value: T) -> &mut T {
self.get_or_insert_with(|| value)
#[unstable(feature = "option_get_or_insert_default", issue = "82901")]
pub fn get_or_insert_default(&mut self) -> &mut T
where
T: Default,
{
self.get_or_insert_with(Default::default)
}

/// Inserts a value computed from `f` into the option if it is [`None`],
Expand Down
36 changes: 36 additions & 0 deletions library/core/src/prelude/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
//! The libcore prelude
//!
//! This module is intended for users of libcore which do not link to libstd as
//! well. This module is imported by default when `#![no_std]` is used in the
//! same manner as the standard library's prelude.

#![stable(feature = "core_prelude", since = "1.4.0")]

pub mod v1;

/// The 2015 version of the core prelude.
///
/// See the [module-level documentation](self) for more.
#[unstable(feature = "prelude_2015", issue = "none")]
pub mod rust_2015 {
#[unstable(feature = "prelude_2015", issue = "none")]
#[doc(no_inline)]
pub use super::v1::*;
}

/// The 2018 version of the core prelude.
///
/// See the [module-level documentation](self) for more.
#[unstable(feature = "prelude_2018", issue = "none")]
pub mod rust_2018 {
#[unstable(feature = "prelude_2018", issue = "none")]
#[doc(no_inline)]
pub use super::v1::*;
}

/// The 2021 version of the core prelude.
///
/// See the [module-level documentation](self) for more.
#[unstable(feature = "prelude_2021", issue = "none")]
pub mod rust_2021 {
#[unstable(feature = "prelude_2021", issue = "none")]
#[doc(no_inline)]
pub use super::v1::*;

// FIXME: Add more things.
}
6 changes: 2 additions & 4 deletions library/core/src/prelude/v1.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//! The core prelude
//! The first version of the core prelude.
//!
//! This module is intended for users of libcore which do not link to libstd as
//! well. This module is imported by default when `#![no_std]` is used in the
//! same manner as the standard library's prelude.
//! See the [module-level documentation](super) for more.

#![stable(feature = "core_prelude", since = "1.4.0")]

Expand Down
1 change: 1 addition & 0 deletions library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@
#![feature(panic_internals)]
#![feature(panic_unwind)]
#![feature(pin_static_ref)]
#![feature(prelude_2021)]
#![feature(prelude_import)]
#![feature(ptr_internals)]
#![feature(raw)]
Expand Down
34 changes: 34 additions & 0 deletions library/std/src/prelude/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,37 @@
#![stable(feature = "rust1", since = "1.0.0")]

pub mod v1;

/// The 2015 version of the prelude of The Rust Standard Library.
///
/// See the [module-level documentation](self) for more.
#[unstable(feature = "prelude_2015", issue = "none")]
pub mod rust_2015 {
#[unstable(feature = "prelude_2015", issue = "none")]
#[doc(no_inline)]
pub use super::v1::*;
}

/// The 2018 version of the prelude of The Rust Standard Library.
///
/// See the [module-level documentation](self) for more.
#[unstable(feature = "prelude_2018", issue = "none")]
pub mod rust_2018 {
#[unstable(feature = "prelude_2018", issue = "none")]
#[doc(no_inline)]
pub use super::v1::*;
}

/// The 2021 version of the prelude of The Rust Standard Library.
///
/// See the [module-level documentation](self) for more.
#[unstable(feature = "prelude_2021", issue = "none")]
pub mod rust_2021 {
#[unstable(feature = "prelude_2021", issue = "none")]
#[doc(no_inline)]
pub use super::v1::*;

#[unstable(feature = "prelude_2021", issue = "none")]
#[doc(no_inline)]
pub use core::prelude::rust_2021::*;
}
2 changes: 1 addition & 1 deletion library/std/src/prelude/v1.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! The first version of the prelude of The Rust Standard Library.
//!
//! See the [module-level documentation](../index.html) for more.
//! See the [module-level documentation](super) for more.

#![stable(feature = "rust1", since = "1.0.0")]

Expand Down
11 changes: 10 additions & 1 deletion library/std/src/sys/unix/ext/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,14 @@ pub trait CommandExt: Sealed {
/// `fork`. This primarily means that any modifications made to memory on
/// behalf of this closure will **not** be visible to the parent process.
/// This is often a very constrained environment where normal operations
/// like `malloc` or acquiring a mutex are not guaranteed to work (due to
/// like `malloc`, accessing environment variables through [`std::env`]
/// or acquiring a mutex are not guaranteed to work (due to
/// other threads perhaps still running when the `fork` was run).
///
/// For further details refer to the [POSIX fork() specification]
/// and the equivalent documentation for any targeted
/// platform, especially the requirements around *async-signal-safety*.
///
/// This also means that all resources such as file descriptors and
/// memory-mapped regions got duplicated. It is your responsibility to make
/// sure that the closure does not violate library invariants by making
Expand All @@ -73,6 +78,10 @@ pub trait CommandExt: Sealed {
/// When this closure is run, aspects such as the stdio file descriptors and
/// working directory have successfully been changed, so output to these
/// locations may not appear where intended.
///
/// [POSIX fork() specification]:
/// https://pubs.opengroup.org/onlinepubs/9699919799/functions/fork.html
/// [`std::env`]: mod@crate::env
#[stable(feature = "process_pre_exec", since = "1.34.0")]
unsafe fn pre_exec<F>(&mut self, f: F) -> &mut process::Command
where
Expand Down
15 changes: 9 additions & 6 deletions library/std/src/sys/unix/process/process_unix.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::convert::TryInto;
use crate::fmt;
use crate::io::{self, Error, ErrorKind};
use crate::mem;
use crate::ptr;
use crate::sys;
use crate::sys::cvt;
Expand Down Expand Up @@ -45,15 +46,14 @@ impl Command {
//
// Note that as soon as we're done with the fork there's no need to hold
// a lock any more because the parent won't do anything and the child is
// in its own process.
let result = unsafe {
let _env_lock = sys::os::env_lock();
cvt(libc::fork())?
};
// in its own process. Thus the parent drops the lock guard while the child
// forgets it to avoid unlocking it on a new thread, which would be invalid.
let (env_lock, result) = unsafe { (sys::os::env_lock(), cvt(libc::fork())?) };

let pid = unsafe {
match result {
0 => {
mem::forget(env_lock);
drop(input);
let Err(err) = self.do_exec(theirs, envp.as_ref());
let errno = err.raw_os_error().unwrap_or(libc::EINVAL) as u32;
Expand All @@ -74,7 +74,10 @@ impl Command {
rtassert!(output.write(&bytes).is_ok());
libc::_exit(1)
}
n => n,
n => {
drop(env_lock);
n
}
}
};

Expand Down
Loading

0 comments on commit f98721f

Please sign in to comment.