Skip to content

Commit f98721f

Browse files
committed
Auto merge of rust-lang#82982 - Dylan-DPC:rollup-mt497z7, r=Dylan-DPC
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
2 parents 17a07d7 + e583132 commit f98721f

40 files changed

+228
-104
lines changed

compiler/rustc_builtin_macros/src/standard_library_imports.rs

+19-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc_ast as ast;
22
use rustc_expand::base::{ExtCtxt, ResolverExpand};
33
use rustc_expand::expand::ExpansionConfig;
44
use rustc_session::Session;
5-
use rustc_span::edition::Edition;
5+
use rustc_span::edition::Edition::*;
66
use rustc_span::hygiene::AstPass;
77
use rustc_span::symbol::{kw, sym, Ident, Symbol};
88
use rustc_span::DUMMY_SP;
@@ -13,7 +13,7 @@ pub fn inject(
1313
sess: &Session,
1414
alt_std_name: Option<Symbol>,
1515
) -> ast::Crate {
16-
let rust_2018 = sess.parse_sess.edition >= Edition::Edition2018;
16+
let edition = sess.parse_sess.edition;
1717

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

4343
// .rev() to preserve ordering above in combination with insert(0, ...)
4444
for &name in names.iter().rev() {
45-
let ident = if rust_2018 { Ident::new(name, span) } else { Ident::new(name, call_site) };
45+
let ident = if edition >= Edition2018 {
46+
Ident::new(name, span)
47+
} else {
48+
Ident::new(name, call_site)
49+
};
4650
krate.items.insert(
4751
0,
4852
cx.item(
@@ -58,14 +62,18 @@ pub fn inject(
5862
// the one with the prelude.
5963
let name = names[0];
6064

61-
let import_path = if rust_2018 {
62-
[name, sym::prelude, sym::v1].iter().map(|symbol| Ident::new(*symbol, span)).collect()
63-
} else {
64-
[kw::PathRoot, name, sym::prelude, sym::v1]
65-
.iter()
66-
.map(|symbol| Ident::new(*symbol, span))
67-
.collect()
68-
};
65+
let root = (edition == Edition2015).then(|| kw::PathRoot);
66+
67+
let import_path = root
68+
.iter()
69+
.chain(&[name, sym::prelude])
70+
.chain(&[match edition {
71+
Edition2015 => sym::rust_2015,
72+
Edition2018 => sym::rust_2018,
73+
Edition2021 => sym::rust_2021,
74+
}])
75+
.map(|&symbol| Ident::new(symbol, span))
76+
.collect();
6977

7078
let use_item = cx.item(
7179
span,

compiler/rustc_middle/src/ty/relate.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -421,12 +421,14 @@ pub fn super_relate_tys<R: TypeRelation<'tcx>>(
421421
let t = relation.relate(a_t, b_t)?;
422422
match relation.relate(sz_a, sz_b) {
423423
Ok(sz) => Ok(tcx.mk_ty(ty::Array(t, sz))),
424-
// FIXME(#72219) Implement improved diagnostics for mismatched array
425-
// length?
426-
Err(err) if relation.tcx().lazy_normalization() => Err(err),
427424
Err(err) => {
428425
// Check whether the lengths are both concrete/known values,
429426
// but are unequal, for better diagnostics.
427+
//
428+
// It might seem dubious to eagerly evaluate these constants here,
429+
// we however cannot end up with errors in `Relate` during both
430+
// `type_of` and `predicates_of`. This means that evaluating the
431+
// constants should not cause cycle errors here.
430432
let sz_a = sz_a.try_eval_usize(tcx, relation.param_env());
431433
let sz_b = sz_b.try_eval_usize(tcx, relation.param_env());
432434
match (sz_a, sz_b) {

compiler/rustc_mir/src/interpret/step.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
160160
let layout = self.layout_of(src.layout.ty.builtin_deref(true).unwrap().ty)?;
161161
let (size, align) = (layout.size, layout.align.abi);
162162
let size = size.checked_mul(count, self).ok_or_else(|| {
163-
err_ub_format!("overflow computing total size of `copy_nonoverlapping`")
163+
err_ub_format!(
164+
"overflow computing total size of `{}`",
165+
if nonoverlapping { "copy_nonoverlapping" } else { "copy" }
166+
)
164167
})?;
165168

166169
// Make sure we check both pointers for an access of the total size and aligment,

compiler/rustc_mir/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Rust MIR: a lowered representation of Rust.
2525
#![feature(stmt_expr_attributes)]
2626
#![feature(trait_alias)]
2727
#![feature(option_expect_none)]
28-
#![feature(option_get_or_default)]
28+
#![feature(option_get_or_insert_default)]
2929
#![feature(or_patterns)]
3030
#![feature(once_cell)]
3131
#![feature(control_flow_enum)]

compiler/rustc_mir/src/transform/coverage/graph.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@ impl BasicCoverageBlockData {
392392
}
393393
}
394394
let operand = counter_kind.as_operand_id();
395-
if let Some(replaced) = self.edge_from_bcbs.get_or_default().insert(from_bcb, counter_kind)
395+
if let Some(replaced) =
396+
self.edge_from_bcbs.get_or_insert_default().insert(from_bcb, counter_kind)
396397
{
397398
Error::from_string(format!(
398399
"attempt to set an edge counter more than once; from_bcb: \

compiler/rustc_span/src/edition.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub enum Edition {
2020
Edition2015,
2121
/// The 2018 edition
2222
Edition2018,
23-
/// The 2021 ediiton
23+
/// The 2021 edition
2424
Edition2021,
2525
}
2626

compiler/rustc_span/src/symbol.rs

+3
Original file line numberDiff line numberDiff line change
@@ -959,8 +959,11 @@ symbols! {
959959
rt,
960960
rtm_target_feature,
961961
rust,
962+
rust_2015,
962963
rust_2015_preview,
964+
rust_2018,
963965
rust_2018_preview,
966+
rust_2021,
964967
rust_2021_preview,
965968
rust_begin_unwind,
966969
rust_eh_catch_typeinfo,

compiler/rustc_target/src/spec/crt_objects.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,13 @@ pub(super) fn post_mingw() -> CrtObjects {
108108
}
109109

110110
pub(super) fn pre_wasi_fallback() -> CrtObjects {
111+
// Use crt1-command.o instead of crt1.o to enable support for new-style
112+
// commands. See https://reviews.llvm.org/D81689 for more info.
111113
new(&[
112-
(LinkOutputKind::DynamicNoPicExe, &["crt1.o"]),
113-
(LinkOutputKind::DynamicPicExe, &["crt1.o"]),
114-
(LinkOutputKind::StaticNoPicExe, &["crt1.o"]),
115-
(LinkOutputKind::StaticPicExe, &["crt1.o"]),
114+
(LinkOutputKind::DynamicNoPicExe, &["crt1-command.o"]),
115+
(LinkOutputKind::DynamicPicExe, &["crt1-command.o"]),
116+
(LinkOutputKind::StaticNoPicExe, &["crt1-command.o"]),
117+
(LinkOutputKind::StaticPicExe, &["crt1-command.o"]),
116118
(LinkOutputKind::WasiReactorExe, &["crt1-reactor.o"]),
117119
])
118120
}

library/core/src/option.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -854,55 +854,55 @@ impl<T> Option<T> {
854854
// Entry-like operations to insert if None and return a reference
855855
/////////////////////////////////////////////////////////////////////////
856856

857-
/// Inserts the default value into the option if it is [`None`], then
857+
/// Inserts `value` into the option if it is [`None`], then
858858
/// returns a mutable reference to the contained value.
859859
///
860860
/// # Examples
861861
///
862862
/// ```
863-
/// #![feature(option_get_or_default)]
864-
///
865863
/// let mut x = None;
866864
///
867865
/// {
868-
/// let y: &mut u32 = x.get_or_default();
869-
/// assert_eq!(y, &0);
866+
/// let y: &mut u32 = x.get_or_insert(5);
867+
/// assert_eq!(y, &5);
870868
///
871869
/// *y = 7;
872870
/// }
873871
///
874872
/// assert_eq!(x, Some(7));
875873
/// ```
876874
#[inline]
877-
#[unstable(feature = "option_get_or_default", issue = "82901")]
878-
pub fn get_or_default(&mut self) -> &mut T
879-
where
880-
T: Default,
881-
{
882-
self.get_or_insert_with(Default::default)
875+
#[stable(feature = "option_entry", since = "1.20.0")]
876+
pub fn get_or_insert(&mut self, value: T) -> &mut T {
877+
self.get_or_insert_with(|| value)
883878
}
884879

885-
/// Inserts `value` into the option if it is [`None`], then
880+
/// Inserts the default value into the option if it is [`None`], then
886881
/// returns a mutable reference to the contained value.
887882
///
888883
/// # Examples
889884
///
890885
/// ```
886+
/// #![feature(option_get_or_insert_default)]
887+
///
891888
/// let mut x = None;
892889
///
893890
/// {
894-
/// let y: &mut u32 = x.get_or_insert(5);
895-
/// assert_eq!(y, &5);
891+
/// let y: &mut u32 = x.get_or_insert_default();
892+
/// assert_eq!(y, &0);
896893
///
897894
/// *y = 7;
898895
/// }
899896
///
900897
/// assert_eq!(x, Some(7));
901898
/// ```
902899
#[inline]
903-
#[stable(feature = "option_entry", since = "1.20.0")]
904-
pub fn get_or_insert(&mut self, value: T) -> &mut T {
905-
self.get_or_insert_with(|| value)
900+
#[unstable(feature = "option_get_or_insert_default", issue = "82901")]
901+
pub fn get_or_insert_default(&mut self) -> &mut T
902+
where
903+
T: Default,
904+
{
905+
self.get_or_insert_with(Default::default)
906906
}
907907

908908
/// Inserts a value computed from `f` into the option if it is [`None`],

library/core/src/prelude/mod.rs

+36
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,41 @@
11
//! The libcore prelude
2+
//!
3+
//! This module is intended for users of libcore which do not link to libstd as
4+
//! well. This module is imported by default when `#![no_std]` is used in the
5+
//! same manner as the standard library's prelude.
26
37
#![stable(feature = "core_prelude", since = "1.4.0")]
48

59
pub mod v1;
10+
11+
/// The 2015 version of the core prelude.
12+
///
13+
/// See the [module-level documentation](self) for more.
14+
#[unstable(feature = "prelude_2015", issue = "none")]
15+
pub mod rust_2015 {
16+
#[unstable(feature = "prelude_2015", issue = "none")]
17+
#[doc(no_inline)]
18+
pub use super::v1::*;
19+
}
20+
21+
/// The 2018 version of the core prelude.
22+
///
23+
/// See the [module-level documentation](self) for more.
24+
#[unstable(feature = "prelude_2018", issue = "none")]
25+
pub mod rust_2018 {
26+
#[unstable(feature = "prelude_2018", issue = "none")]
27+
#[doc(no_inline)]
28+
pub use super::v1::*;
29+
}
30+
31+
/// The 2021 version of the core prelude.
32+
///
33+
/// See the [module-level documentation](self) for more.
34+
#[unstable(feature = "prelude_2021", issue = "none")]
35+
pub mod rust_2021 {
36+
#[unstable(feature = "prelude_2021", issue = "none")]
37+
#[doc(no_inline)]
38+
pub use super::v1::*;
39+
40+
// FIXME: Add more things.
41+
}

library/core/src/prelude/v1.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
//! The core prelude
1+
//! The first version of the core prelude.
22
//!
3-
//! This module is intended for users of libcore which do not link to libstd as
4-
//! well. This module is imported by default when `#![no_std]` is used in the
5-
//! same manner as the standard library's prelude.
3+
//! See the [module-level documentation](super) for more.
64
75
#![stable(feature = "core_prelude", since = "1.4.0")]
86

library/std/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@
302302
#![feature(panic_internals)]
303303
#![feature(panic_unwind)]
304304
#![feature(pin_static_ref)]
305+
#![feature(prelude_2021)]
305306
#![feature(prelude_import)]
306307
#![feature(ptr_internals)]
307308
#![feature(raw)]

library/std/src/prelude/mod.rs

+34
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,37 @@
8484
#![stable(feature = "rust1", since = "1.0.0")]
8585

8686
pub mod v1;
87+
88+
/// The 2015 version of the prelude of The Rust Standard Library.
89+
///
90+
/// See the [module-level documentation](self) for more.
91+
#[unstable(feature = "prelude_2015", issue = "none")]
92+
pub mod rust_2015 {
93+
#[unstable(feature = "prelude_2015", issue = "none")]
94+
#[doc(no_inline)]
95+
pub use super::v1::*;
96+
}
97+
98+
/// The 2018 version of the prelude of The Rust Standard Library.
99+
///
100+
/// See the [module-level documentation](self) for more.
101+
#[unstable(feature = "prelude_2018", issue = "none")]
102+
pub mod rust_2018 {
103+
#[unstable(feature = "prelude_2018", issue = "none")]
104+
#[doc(no_inline)]
105+
pub use super::v1::*;
106+
}
107+
108+
/// The 2021 version of the prelude of The Rust Standard Library.
109+
///
110+
/// See the [module-level documentation](self) for more.
111+
#[unstable(feature = "prelude_2021", issue = "none")]
112+
pub mod rust_2021 {
113+
#[unstable(feature = "prelude_2021", issue = "none")]
114+
#[doc(no_inline)]
115+
pub use super::v1::*;
116+
117+
#[unstable(feature = "prelude_2021", issue = "none")]
118+
#[doc(no_inline)]
119+
pub use core::prelude::rust_2021::*;
120+
}

library/std/src/prelude/v1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! The first version of the prelude of The Rust Standard Library.
22
//!
3-
//! See the [module-level documentation](../index.html) for more.
3+
//! See the [module-level documentation](super) for more.
44
55
#![stable(feature = "rust1", since = "1.0.0")]
66

library/std/src/sys/unix/ext/process.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,14 @@ pub trait CommandExt: Sealed {
6262
/// `fork`. This primarily means that any modifications made to memory on
6363
/// behalf of this closure will **not** be visible to the parent process.
6464
/// This is often a very constrained environment where normal operations
65-
/// like `malloc` or acquiring a mutex are not guaranteed to work (due to
65+
/// like `malloc`, accessing environment variables through [`std::env`]
66+
/// or acquiring a mutex are not guaranteed to work (due to
6667
/// other threads perhaps still running when the `fork` was run).
6768
///
69+
/// For further details refer to the [POSIX fork() specification]
70+
/// and the equivalent documentation for any targeted
71+
/// platform, especially the requirements around *async-signal-safety*.
72+
///
6873
/// This also means that all resources such as file descriptors and
6974
/// memory-mapped regions got duplicated. It is your responsibility to make
7075
/// sure that the closure does not violate library invariants by making
@@ -73,6 +78,10 @@ pub trait CommandExt: Sealed {
7378
/// When this closure is run, aspects such as the stdio file descriptors and
7479
/// working directory have successfully been changed, so output to these
7580
/// locations may not appear where intended.
81+
///
82+
/// [POSIX fork() specification]:
83+
/// https://pubs.opengroup.org/onlinepubs/9699919799/functions/fork.html
84+
/// [`std::env`]: mod@crate::env
7685
#[stable(feature = "process_pre_exec", since = "1.34.0")]
7786
unsafe fn pre_exec<F>(&mut self, f: F) -> &mut process::Command
7887
where

library/std/src/sys/unix/process/process_unix.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::convert::TryInto;
22
use crate::fmt;
33
use crate::io::{self, Error, ErrorKind};
4+
use crate::mem;
45
use crate::ptr;
56
use crate::sys;
67
use crate::sys::cvt;
@@ -45,15 +46,14 @@ impl Command {
4546
//
4647
// Note that as soon as we're done with the fork there's no need to hold
4748
// a lock any more because the parent won't do anything and the child is
48-
// in its own process.
49-
let result = unsafe {
50-
let _env_lock = sys::os::env_lock();
51-
cvt(libc::fork())?
52-
};
49+
// in its own process. Thus the parent drops the lock guard while the child
50+
// forgets it to avoid unlocking it on a new thread, which would be invalid.
51+
let (env_lock, result) = unsafe { (sys::os::env_lock(), cvt(libc::fork())?) };
5352

5453
let pid = unsafe {
5554
match result {
5655
0 => {
56+
mem::forget(env_lock);
5757
drop(input);
5858
let Err(err) = self.do_exec(theirs, envp.as_ref());
5959
let errno = err.raw_os_error().unwrap_or(libc::EINVAL) as u32;
@@ -74,7 +74,10 @@ impl Command {
7474
rtassert!(output.write(&bytes).is_ok());
7575
libc::_exit(1)
7676
}
77-
n => n,
77+
n => {
78+
drop(env_lock);
79+
n
80+
}
7881
}
7982
};
8083

0 commit comments

Comments
 (0)