Skip to content

Commit 1381dcf

Browse files
committed
Auto merge of rust-lang#83105 - JohnTitor:rollup-tqpm8pb, r=JohnTitor
Rollup of 10 pull requests Successful merges: - rust-lang#81465 (Add documentation about formatting `Duration` values) - rust-lang#82121 (Implement Extend and FromIterator for OsString) - rust-lang#82617 (Document `everybody_loops`) - rust-lang#82789 (Get with field index from pattern slice instead of directly indexing) - rust-lang#82798 (Rename `rustdoc` to `rustdoc::all`) - rust-lang#82804 (std: Fix a bug on the wasm32-wasi target opening files) - rust-lang#82943 (Demonstrate best practice for feeding stdin of a child processes) - rust-lang#83066 (Add `reverse` search alias for Iterator::rev()) - rust-lang#83070 (Update cargo) - rust-lang#83081 (Fix panic message of `assert_failed_inner`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents acca818 + f8206ac commit 1381dcf

30 files changed

+269
-62
lines changed

compiler/rustc_interface/src/util.rs

+18-10
Original file line numberDiff line numberDiff line change
@@ -712,16 +712,24 @@ pub fn non_durable_rename(src: &Path, dst: &Path) -> std::io::Result<()> {
712712
std::fs::rename(src, dst)
713713
}
714714

715-
// Note: Also used by librustdoc, see PR #43348. Consider moving this struct elsewhere.
716-
//
717-
// FIXME: Currently the `everybody_loops` transformation is not applied to:
718-
// * `const fn`, due to issue #43636 that `loop` is not supported for const evaluation. We are
719-
// waiting for miri to fix that.
720-
// * `impl Trait`, due to issue #43869 that functions returning impl Trait cannot be diverging.
721-
// Solving this may require `!` to implement every trait, which relies on the an even more
722-
// ambitious form of the closed RFC #1637. See also [#34511].
723-
//
724-
// [#34511]: https://github.com/rust-lang/rust/issues/34511#issuecomment-322340401
715+
/// Replaces function bodies with `loop {}` (an infinite loop). This gets rid of
716+
/// all semantic errors in the body while still satisfying the return type,
717+
/// except in certain cases, see below for more.
718+
///
719+
/// This pass is known as `everybody_loops`. Very punny.
720+
///
721+
/// As of March 2021, `everybody_loops` is only used for the
722+
/// `-Z unpretty=everybody_loops` debugging option.
723+
///
724+
/// FIXME: Currently the `everybody_loops` transformation is not applied to:
725+
/// * `const fn`; support could be added, but hasn't. Originally `const fn`
726+
/// was skipped due to issue #43636 that `loop` was not supported for
727+
/// const evaluation.
728+
/// * `impl Trait`, due to issue #43869 that functions returning impl Trait cannot be diverging.
729+
/// Solving this may require `!` to implement every trait, which relies on the an even more
730+
/// ambitious form of the closed RFC #1637. See also [#34511].
731+
///
732+
/// [#34511]: https://github.com/rust-lang/rust/issues/34511#issuecomment-322340401
725733
pub struct ReplaceBodyWithLoop<'a, 'b> {
726734
within_static_or_const: bool,
727735
nested_blocks: Option<Vec<ast::Block>>,

compiler/rustc_lint/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) {
346346
"intra_doc_link_resolution_failure",
347347
"use `rustdoc::broken_intra_doc_links` instead",
348348
);
349+
store.register_removed("rustdoc", "use `rustdoc::all` instead");
349350

350351
store.register_removed("unknown_features", "replaced by an error");
351352
store.register_removed("unsigned_negation", "replaced by negate_unsigned feature gate");

compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,9 @@ impl<'p, 'tcx> Fields<'p, 'tcx> {
13431343
match &mut fields {
13441344
Fields::Vec(pats) => {
13451345
for (i, pat) in new_pats {
1346-
pats[i] = pat
1346+
if let Some(p) = pats.get_mut(i) {
1347+
*p = pat;
1348+
}
13471349
}
13481350
}
13491351
Fields::Filtered { fields, .. } => {

library/core/src/iter/traits/iterator.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2737,6 +2737,7 @@ pub trait Iterator {
27372737
/// assert_eq!(iter.next(), None);
27382738
/// ```
27392739
#[inline]
2740+
#[doc(alias = "reverse")]
27402741
#[stable(feature = "rust1", since = "1.0.0")]
27412742
fn rev(self) -> Rev<Self>
27422743
where

library/core/src/panicking.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ fn assert_failed_inner(
154154
Some(args) => panic!(
155155
r#"assertion failed: `(left {} right)`
156156
left: `{:?}`,
157-
right: `{:?}: {}`"#,
157+
right: `{:?}`: {}"#,
158158
op, left, right, args
159159
),
160160
None => panic!(

library/core/src/time.rs

+11
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ const MICROS_PER_SEC: u64 = 1_000_000;
4848
///
4949
/// let ten_millis = Duration::from_millis(10);
5050
/// ```
51+
///
52+
/// # Formatting `Duration` values
53+
///
54+
/// `Duration` intentionally does not have a `Display` impl, as there are a
55+
/// variety of ways to format spans of time for human readability. `Duration`
56+
/// provides a `Debug` impl that shows the full precision of the value.
57+
///
58+
/// The `Debug` output uses the non-ASCII "µs" suffix for microseconds. If your
59+
/// program output may appear in contexts that cannot rely on full Unicode
60+
/// compatibility, you may wish to format `Duration` objects yourself or use a
61+
/// crate to do so.
5162
#[stable(feature = "duration", since = "1.3.0")]
5263
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
5364
pub struct Duration {

library/std/src/ffi/os_str.rs

+86
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::borrow::{Borrow, Cow};
55
use crate::cmp;
66
use crate::fmt;
77
use crate::hash::{Hash, Hasher};
8+
use crate::iter::{Extend, FromIterator};
89
use crate::ops;
910
use crate::rc::Rc;
1011
use crate::str::FromStr;
@@ -1192,3 +1193,88 @@ impl FromStr for OsString {
11921193
Ok(OsString::from(s))
11931194
}
11941195
}
1196+
1197+
#[stable(feature = "osstring_extend", since = "1.52.0")]
1198+
impl Extend<OsString> for OsString {
1199+
#[inline]
1200+
fn extend<T: IntoIterator<Item = OsString>>(&mut self, iter: T) {
1201+
for s in iter {
1202+
self.push(&s);
1203+
}
1204+
}
1205+
}
1206+
1207+
#[stable(feature = "osstring_extend", since = "1.52.0")]
1208+
impl<'a> Extend<&'a OsStr> for OsString {
1209+
#[inline]
1210+
fn extend<T: IntoIterator<Item = &'a OsStr>>(&mut self, iter: T) {
1211+
for s in iter {
1212+
self.push(s);
1213+
}
1214+
}
1215+
}
1216+
1217+
#[stable(feature = "osstring_extend", since = "1.52.0")]
1218+
impl<'a> Extend<Cow<'a, OsStr>> for OsString {
1219+
#[inline]
1220+
fn extend<T: IntoIterator<Item = Cow<'a, OsStr>>>(&mut self, iter: T) {
1221+
for s in iter {
1222+
self.push(&s);
1223+
}
1224+
}
1225+
}
1226+
1227+
#[stable(feature = "osstring_extend", since = "1.52.0")]
1228+
impl FromIterator<OsString> for OsString {
1229+
#[inline]
1230+
fn from_iter<I: IntoIterator<Item = OsString>>(iter: I) -> Self {
1231+
let mut iterator = iter.into_iter();
1232+
1233+
// Because we're iterating over `OsString`s, we can avoid at least
1234+
// one allocation by getting the first string from the iterator
1235+
// and appending to it all the subsequent strings.
1236+
match iterator.next() {
1237+
None => OsString::new(),
1238+
Some(mut buf) => {
1239+
buf.extend(iterator);
1240+
buf
1241+
}
1242+
}
1243+
}
1244+
}
1245+
1246+
#[stable(feature = "osstring_extend", since = "1.52.0")]
1247+
impl<'a> FromIterator<&'a OsStr> for OsString {
1248+
#[inline]
1249+
fn from_iter<I: IntoIterator<Item = &'a OsStr>>(iter: I) -> Self {
1250+
let mut buf = Self::new();
1251+
for s in iter {
1252+
buf.push(s);
1253+
}
1254+
buf
1255+
}
1256+
}
1257+
1258+
#[stable(feature = "osstring_extend", since = "1.52.0")]
1259+
impl<'a> FromIterator<Cow<'a, OsStr>> for OsString {
1260+
#[inline]
1261+
fn from_iter<I: IntoIterator<Item = Cow<'a, OsStr>>>(iter: I) -> Self {
1262+
let mut iterator = iter.into_iter();
1263+
1264+
// Because we're iterating over `OsString`s, we can avoid at least
1265+
// one allocation by getting the first owned string from the iterator
1266+
// and appending to it all the subsequent strings.
1267+
match iterator.next() {
1268+
None => OsString::new(),
1269+
Some(Cow::Owned(mut buf)) => {
1270+
buf.extend(iterator);
1271+
buf
1272+
}
1273+
Some(Cow::Borrowed(buf)) => {
1274+
let mut buf = OsString::from(buf);
1275+
buf.extend(iterator);
1276+
buf
1277+
}
1278+
}
1279+
}
1280+
}

library/std/src/process.rs

+18-7
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,15 @@
7171
//! .spawn()
7272
//! .expect("failed to execute child");
7373
//!
74-
//! {
75-
//! // limited borrow of stdin
76-
//! let stdin = child.stdin.as_mut().expect("failed to get stdin");
74+
//! // If the child process fills its stdout buffer, it may end up
75+
//! // waiting until the parent reads the stdout, and not be able to
76+
//! // read stdin in the meantime, causing a deadlock.
77+
//! // Writing from another thread ensures that stdout is being read
78+
//! // at the same time, avoiding the problem.
79+
//! let mut stdin = child.stdin.take().expect("failed to get stdin");
80+
//! std::thread::spawn(move || {
7781
//! stdin.write_all(b"test").expect("failed to write to stdin");
78-
//! }
82+
//! });
7983
//!
8084
//! let output = child
8185
//! .wait_with_output()
@@ -1145,14 +1149,21 @@ impl Stdio {
11451149
/// .spawn()
11461150
/// .expect("Failed to spawn child process");
11471151
///
1148-
/// {
1149-
/// let stdin = child.stdin.as_mut().expect("Failed to open stdin");
1152+
/// let mut stdin = child.stdin.take().expect("Failed to open stdin");
1153+
/// std::thread::spawn(move || {
11501154
/// stdin.write_all("Hello, world!".as_bytes()).expect("Failed to write to stdin");
1151-
/// }
1155+
/// });
11521156
///
11531157
/// let output = child.wait_with_output().expect("Failed to read stdout");
11541158
/// assert_eq!(String::from_utf8_lossy(&output.stdout), "!dlrow ,olleH");
11551159
/// ```
1160+
///
1161+
/// Writing more than a pipe buffer's worth of input to stdin without also reading
1162+
/// stdout and stderr at the same time may cause a deadlock.
1163+
/// This is an issue when running any program that doesn't guarantee that it reads
1164+
/// its entire stdin before writing more than a pipe buffer's worth of output.
1165+
/// The size of a pipe buffer varies on different targets.
1166+
///
11561167
#[stable(feature = "process", since = "1.0.0")]
11571168
pub fn piped() -> Stdio {
11581169
Stdio(imp::Stdio::MakePipe)

library/std/src/sys/wasi/fs.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -650,13 +650,11 @@ fn open_parent(p: &Path) -> io::Result<(ManuallyDrop<WasiFd>, PathBuf)> {
650650
);
651651
return Err(io::Error::new(io::ErrorKind::Other, msg));
652652
}
653-
let len = CStr::from_ptr(buf.as_ptr().cast()).to_bytes().len();
654-
buf.set_len(len);
655-
buf.shrink_to_fit();
653+
let relative = CStr::from_ptr(relative_path).to_bytes().to_vec();
656654

657655
return Ok((
658656
ManuallyDrop::new(WasiFd::from_raw(fd as u32)),
659-
PathBuf::from(OsString::from_vec(buf)),
657+
PathBuf::from(OsString::from_vec(relative)),
660658
));
661659
}
662660
}

src/librustdoc/lint.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ crate fn register_lints(_sess: &Session, lint_store: &mut LintStore) {
175175
lint_store.register_lints(&**RUSTDOC_LINTS);
176176
lint_store.register_group(
177177
true,
178-
"rustdoc",
179-
None,
178+
"rustdoc::all",
179+
Some("rustdoc"),
180180
RUSTDOC_LINTS.iter().map(|&lint| LintId::of(lint)).collect(),
181181
);
182182
for lint in &*RUSTDOC_LINTS {

src/test/rustdoc-ui/check-fail.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// compile-flags: -Z unstable-options --check
22

33
#![deny(missing_docs)]
4-
#![deny(rustdoc)]
4+
#![deny(rustdoc::all)]
55

66
//! ```rust,testharness
77
//~^ ERROR

src/test/rustdoc-ui/check-fail.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ LL | pub fn foo() {}
1919
note: the lint level is defined here
2020
--> $DIR/check-fail.rs:4:9
2121
|
22-
LL | #![deny(rustdoc)]
23-
| ^^^^^^^
24-
= note: `#[deny(rustdoc::missing_doc_code_examples)]` implied by `#[deny(rustdoc)]`
22+
LL | #![deny(rustdoc::all)]
23+
| ^^^^^^^^^^^^
24+
= note: `#[deny(rustdoc::missing_doc_code_examples)]` implied by `#[deny(rustdoc::all)]`
2525

2626
error: unknown attribute `testharness`. Did you mean `test_harness`?
2727
--> $DIR/check-fail.rs:6:1
@@ -35,9 +35,9 @@ LL | | //! ```
3535
note: the lint level is defined here
3636
--> $DIR/check-fail.rs:4:9
3737
|
38-
LL | #![deny(rustdoc)]
39-
| ^^^^^^^
40-
= note: `#[deny(rustdoc::invalid_codeblock_attributes)]` implied by `#[deny(rustdoc)]`
38+
LL | #![deny(rustdoc::all)]
39+
| ^^^^^^^^^^^^
40+
= note: `#[deny(rustdoc::invalid_codeblock_attributes)]` implied by `#[deny(rustdoc::all)]`
4141
= help: the code block will either not be tested if not marked as a rust one or the code will be wrapped inside a main function
4242

4343
error: unknown attribute `testharness`. Did you mean `test_harness`?

src/test/rustdoc-ui/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#![warn(missing_docs)]
55
//~^ WARN
66
//~^^ WARN
7-
#![warn(rustdoc)]
7+
#![warn(rustdoc::all)]
88

99
pub fn foo() {}
1010
//~^ WARN

src/test/rustdoc-ui/check.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ warning: missing documentation for the crate
44
LL | / #![warn(missing_docs)]
55
LL | |
66
LL | |
7-
LL | | #![warn(rustdoc)]
7+
LL | | #![warn(rustdoc::all)]
88
LL | |
99
LL | | pub fn foo() {}
1010
| |_______________^
@@ -26,9 +26,9 @@ warning: no documentation found for this crate's top-level module
2626
note: the lint level is defined here
2727
--> $DIR/check.rs:7:9
2828
|
29-
LL | #![warn(rustdoc)]
30-
| ^^^^^^^
31-
= note: `#[warn(rustdoc::missing_crate_level_docs)]` implied by `#[warn(rustdoc)]`
29+
LL | #![warn(rustdoc::all)]
30+
| ^^^^^^^^^^^^
31+
= note: `#[warn(rustdoc::missing_crate_level_docs)]` implied by `#[warn(rustdoc::all)]`
3232
= help: The following guide may be of use:
3333
https://doc.rust-lang.org/nightly/rustdoc/how-to-write-documentation.html
3434

@@ -38,17 +38,17 @@ warning: missing code example in this documentation
3838
LL | / #![warn(missing_docs)]
3939
LL | |
4040
LL | |
41-
LL | | #![warn(rustdoc)]
41+
LL | | #![warn(rustdoc::all)]
4242
LL | |
4343
LL | | pub fn foo() {}
4444
| |_______________^
4545
|
4646
note: the lint level is defined here
4747
--> $DIR/check.rs:7:9
4848
|
49-
LL | #![warn(rustdoc)]
50-
| ^^^^^^^
51-
= note: `#[warn(rustdoc::missing_doc_code_examples)]` implied by `#[warn(rustdoc)]`
49+
LL | #![warn(rustdoc::all)]
50+
| ^^^^^^^^^^^^
51+
= note: `#[warn(rustdoc::missing_doc_code_examples)]` implied by `#[warn(rustdoc::all)]`
5252

5353
warning: missing code example in this documentation
5454
--> $DIR/check.rs:9:1

src/test/rustdoc-ui/lint-group.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! println!("sup");
55
//! ```
66
7-
#![deny(rustdoc)]
7+
#![deny(rustdoc::all)]
88

99
/// what up, let's make an [error]
1010
///

0 commit comments

Comments
 (0)