Auto merge of #83105 - JohnTitor:rollup-tqpm8pb, r=JohnTitor

Rollup of 10 pull requests

Successful merges:

 - #81465 (Add documentation about formatting `Duration` values)
 - #82121 (Implement Extend and FromIterator for OsString)
 - #82617 (Document `everybody_loops`)
 - #82789 (Get with field index from pattern slice instead of directly indexing)
 - #82798 (Rename `rustdoc` to `rustdoc::all`)
 - #82804 (std: Fix a bug on the wasm32-wasi target opening files)
 - #82943 (Demonstrate best practice for feeding stdin of a child processes)
 - #83066 (Add `reverse` search alias for Iterator::rev())
 - #83070 (Update cargo)
 - #83081 (Fix panic message of `assert_failed_inner`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2021-03-14 04:09:02 +00:00
commit 1381dcfdc5
30 changed files with 269 additions and 62 deletions

View File

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

View File

@ -346,6 +346,7 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) {
"intra_doc_link_resolution_failure",
"use `rustdoc::broken_intra_doc_links` instead",
);
store.register_removed("rustdoc", "use `rustdoc::all` instead");
store.register_removed("unknown_features", "replaced by an error");
store.register_removed("unsigned_negation", "replaced by negate_unsigned feature gate");

View File

@ -1343,7 +1343,9 @@ impl<'p, 'tcx> Fields<'p, 'tcx> {
match &mut fields {
Fields::Vec(pats) => {
for (i, pat) in new_pats {
pats[i] = pat
if let Some(p) = pats.get_mut(i) {
*p = pat;
}
}
}
Fields::Filtered { fields, .. } => {

View File

@ -2737,6 +2737,7 @@ pub trait Iterator {
/// assert_eq!(iter.next(), None);
/// ```
#[inline]
#[doc(alias = "reverse")]
#[stable(feature = "rust1", since = "1.0.0")]
fn rev(self) -> Rev<Self>
where

View File

@ -154,7 +154,7 @@ fn assert_failed_inner(
Some(args) => panic!(
r#"assertion failed: `(left {} right)`
left: `{:?}`,
right: `{:?}: {}`"#,
right: `{:?}`: {}"#,
op, left, right, args
),
None => panic!(

View File

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

View File

@ -5,6 +5,7 @@ use crate::borrow::{Borrow, Cow};
use crate::cmp;
use crate::fmt;
use crate::hash::{Hash, Hasher};
use crate::iter::{Extend, FromIterator};
use crate::ops;
use crate::rc::Rc;
use crate::str::FromStr;
@ -1192,3 +1193,88 @@ impl FromStr for OsString {
Ok(OsString::from(s))
}
}
#[stable(feature = "osstring_extend", since = "1.52.0")]
impl Extend<OsString> for OsString {
#[inline]
fn extend<T: IntoIterator<Item = OsString>>(&mut self, iter: T) {
for s in iter {
self.push(&s);
}
}
}
#[stable(feature = "osstring_extend", since = "1.52.0")]
impl<'a> Extend<&'a OsStr> for OsString {
#[inline]
fn extend<T: IntoIterator<Item = &'a OsStr>>(&mut self, iter: T) {
for s in iter {
self.push(s);
}
}
}
#[stable(feature = "osstring_extend", since = "1.52.0")]
impl<'a> Extend<Cow<'a, OsStr>> for OsString {
#[inline]
fn extend<T: IntoIterator<Item = Cow<'a, OsStr>>>(&mut self, iter: T) {
for s in iter {
self.push(&s);
}
}
}
#[stable(feature = "osstring_extend", since = "1.52.0")]
impl FromIterator<OsString> for OsString {
#[inline]
fn from_iter<I: IntoIterator<Item = OsString>>(iter: I) -> Self {
let mut iterator = iter.into_iter();
// Because we're iterating over `OsString`s, we can avoid at least
// one allocation by getting the first string from the iterator
// and appending to it all the subsequent strings.
match iterator.next() {
None => OsString::new(),
Some(mut buf) => {
buf.extend(iterator);
buf
}
}
}
}
#[stable(feature = "osstring_extend", since = "1.52.0")]
impl<'a> FromIterator<&'a OsStr> for OsString {
#[inline]
fn from_iter<I: IntoIterator<Item = &'a OsStr>>(iter: I) -> Self {
let mut buf = Self::new();
for s in iter {
buf.push(s);
}
buf
}
}
#[stable(feature = "osstring_extend", since = "1.52.0")]
impl<'a> FromIterator<Cow<'a, OsStr>> for OsString {
#[inline]
fn from_iter<I: IntoIterator<Item = Cow<'a, OsStr>>>(iter: I) -> Self {
let mut iterator = iter.into_iter();
// Because we're iterating over `OsString`s, we can avoid at least
// one allocation by getting the first owned string from the iterator
// and appending to it all the subsequent strings.
match iterator.next() {
None => OsString::new(),
Some(Cow::Owned(mut buf)) => {
buf.extend(iterator);
buf
}
Some(Cow::Borrowed(buf)) => {
let mut buf = OsString::from(buf);
buf.extend(iterator);
buf
}
}
}
}

View File

@ -71,11 +71,15 @@
//! .spawn()
//! .expect("failed to execute child");
//!
//! {
//! // limited borrow of stdin
//! let stdin = child.stdin.as_mut().expect("failed to get stdin");
//! // If the child process fills its stdout buffer, it may end up
//! // waiting until the parent reads the stdout, and not be able to
//! // read stdin in the meantime, causing a deadlock.
//! // Writing from another thread ensures that stdout is being read
//! // at the same time, avoiding the problem.
//! let mut stdin = child.stdin.take().expect("failed to get stdin");
//! std::thread::spawn(move || {
//! stdin.write_all(b"test").expect("failed to write to stdin");
//! }
//! });
//!
//! let output = child
//! .wait_with_output()
@ -1145,14 +1149,21 @@ impl Stdio {
/// .spawn()
/// .expect("Failed to spawn child process");
///
/// {
/// let stdin = child.stdin.as_mut().expect("Failed to open stdin");
/// let mut stdin = child.stdin.take().expect("Failed to open stdin");
/// std::thread::spawn(move || {
/// stdin.write_all("Hello, world!".as_bytes()).expect("Failed to write to stdin");
/// }
/// });
///
/// let output = child.wait_with_output().expect("Failed to read stdout");
/// assert_eq!(String::from_utf8_lossy(&output.stdout), "!dlrow ,olleH");
/// ```
///
/// Writing more than a pipe buffer's worth of input to stdin without also reading
/// stdout and stderr at the same time may cause a deadlock.
/// This is an issue when running any program that doesn't guarantee that it reads
/// its entire stdin before writing more than a pipe buffer's worth of output.
/// The size of a pipe buffer varies on different targets.
///
#[stable(feature = "process", since = "1.0.0")]
pub fn piped() -> Stdio {
Stdio(imp::Stdio::MakePipe)

View File

@ -650,13 +650,11 @@ fn open_parent(p: &Path) -> io::Result<(ManuallyDrop<WasiFd>, PathBuf)> {
);
return Err(io::Error::new(io::ErrorKind::Other, msg));
}
let len = CStr::from_ptr(buf.as_ptr().cast()).to_bytes().len();
buf.set_len(len);
buf.shrink_to_fit();
let relative = CStr::from_ptr(relative_path).to_bytes().to_vec();
return Ok((
ManuallyDrop::new(WasiFd::from_raw(fd as u32)),
PathBuf::from(OsString::from_vec(buf)),
PathBuf::from(OsString::from_vec(relative)),
));
}
}

View File

@ -175,8 +175,8 @@ crate fn register_lints(_sess: &Session, lint_store: &mut LintStore) {
lint_store.register_lints(&**RUSTDOC_LINTS);
lint_store.register_group(
true,
"rustdoc",
None,
"rustdoc::all",
Some("rustdoc"),
RUSTDOC_LINTS.iter().map(|&lint| LintId::of(lint)).collect(),
);
for lint in &*RUSTDOC_LINTS {

View File

@ -1,7 +1,7 @@
// compile-flags: -Z unstable-options --check
#![deny(missing_docs)]
#![deny(rustdoc)]
#![deny(rustdoc::all)]
//! ```rust,testharness
//~^ ERROR

View File

@ -19,9 +19,9 @@ LL | pub fn foo() {}
note: the lint level is defined here
--> $DIR/check-fail.rs:4:9
|
LL | #![deny(rustdoc)]
| ^^^^^^^
= note: `#[deny(rustdoc::missing_doc_code_examples)]` implied by `#[deny(rustdoc)]`
LL | #![deny(rustdoc::all)]
| ^^^^^^^^^^^^
= note: `#[deny(rustdoc::missing_doc_code_examples)]` implied by `#[deny(rustdoc::all)]`
error: unknown attribute `testharness`. Did you mean `test_harness`?
--> $DIR/check-fail.rs:6:1
@ -35,9 +35,9 @@ LL | | //! ```
note: the lint level is defined here
--> $DIR/check-fail.rs:4:9
|
LL | #![deny(rustdoc)]
| ^^^^^^^
= note: `#[deny(rustdoc::invalid_codeblock_attributes)]` implied by `#[deny(rustdoc)]`
LL | #![deny(rustdoc::all)]
| ^^^^^^^^^^^^
= note: `#[deny(rustdoc::invalid_codeblock_attributes)]` implied by `#[deny(rustdoc::all)]`
= 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
error: unknown attribute `testharness`. Did you mean `test_harness`?

View File

@ -4,7 +4,7 @@
#![warn(missing_docs)]
//~^ WARN
//~^^ WARN
#![warn(rustdoc)]
#![warn(rustdoc::all)]
pub fn foo() {}
//~^ WARN

View File

@ -4,7 +4,7 @@ warning: missing documentation for the crate
LL | / #![warn(missing_docs)]
LL | |
LL | |
LL | | #![warn(rustdoc)]
LL | | #![warn(rustdoc::all)]
LL | |
LL | | pub fn foo() {}
| |_______________^
@ -26,9 +26,9 @@ warning: no documentation found for this crate's top-level module
note: the lint level is defined here
--> $DIR/check.rs:7:9
|
LL | #![warn(rustdoc)]
| ^^^^^^^
= note: `#[warn(rustdoc::missing_crate_level_docs)]` implied by `#[warn(rustdoc)]`
LL | #![warn(rustdoc::all)]
| ^^^^^^^^^^^^
= note: `#[warn(rustdoc::missing_crate_level_docs)]` implied by `#[warn(rustdoc::all)]`
= help: The following guide may be of use:
https://doc.rust-lang.org/nightly/rustdoc/how-to-write-documentation.html
@ -38,7 +38,7 @@ warning: missing code example in this documentation
LL | / #![warn(missing_docs)]
LL | |
LL | |
LL | | #![warn(rustdoc)]
LL | | #![warn(rustdoc::all)]
LL | |
LL | | pub fn foo() {}
| |_______________^
@ -46,9 +46,9 @@ LL | | pub fn foo() {}
note: the lint level is defined here
--> $DIR/check.rs:7:9
|
LL | #![warn(rustdoc)]
| ^^^^^^^
= note: `#[warn(rustdoc::missing_doc_code_examples)]` implied by `#[warn(rustdoc)]`
LL | #![warn(rustdoc::all)]
| ^^^^^^^^^^^^
= note: `#[warn(rustdoc::missing_doc_code_examples)]` implied by `#[warn(rustdoc::all)]`
warning: missing code example in this documentation
--> $DIR/check.rs:9:1

View File

@ -4,7 +4,7 @@
//! println!("sup");
//! ```
#![deny(rustdoc)]
#![deny(rustdoc::all)]
/// what up, let's make an [error]
///

View File

@ -7,9 +7,9 @@ LL | /// wait, this doesn't have a doctest?
note: the lint level is defined here
--> $DIR/lint-group.rs:7:9
|
LL | #![deny(rustdoc)]
| ^^^^^^^
= note: `#[deny(rustdoc::missing_doc_code_examples)]` implied by `#[deny(rustdoc)]`
LL | #![deny(rustdoc::all)]
| ^^^^^^^^^^^^
= note: `#[deny(rustdoc::missing_doc_code_examples)]` implied by `#[deny(rustdoc::all)]`
error: documentation test in private item
--> $DIR/lint-group.rs:19:1
@ -24,9 +24,9 @@ LL | | /// ```
note: the lint level is defined here
--> $DIR/lint-group.rs:7:9
|
LL | #![deny(rustdoc)]
| ^^^^^^^
= note: `#[deny(rustdoc::private_doc_tests)]` implied by `#[deny(rustdoc)]`
LL | #![deny(rustdoc::all)]
| ^^^^^^^^^^^^
= note: `#[deny(rustdoc::private_doc_tests)]` implied by `#[deny(rustdoc::all)]`
error: missing code example in this documentation
--> $DIR/lint-group.rs:26:1
@ -43,9 +43,9 @@ LL | /// what up, let's make an [error]
note: the lint level is defined here
--> $DIR/lint-group.rs:7:9
|
LL | #![deny(rustdoc)]
| ^^^^^^^
= note: `#[deny(rustdoc::broken_intra_doc_links)]` implied by `#[deny(rustdoc)]`
LL | #![deny(rustdoc::all)]
| ^^^^^^^^^^^^
= note: `#[deny(rustdoc::broken_intra_doc_links)]` implied by `#[deny(rustdoc::all)]`
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
error: unclosed HTML tag `unknown`
@ -57,9 +57,9 @@ LL | /// <unknown>
note: the lint level is defined here
--> $DIR/lint-group.rs:7:9
|
LL | #![deny(rustdoc)]
| ^^^^^^^
= note: `#[deny(rustdoc::invalid_html_tags)]` implied by `#[deny(rustdoc)]`
LL | #![deny(rustdoc::all)]
| ^^^^^^^^^^^^
= note: `#[deny(rustdoc::invalid_html_tags)]` implied by `#[deny(rustdoc::all)]`
error: aborting due to 5 previous errors

View File

@ -12,6 +12,9 @@
#![deny(non_autolinks)]
//~^ ERROR renamed to `rustdoc::non_autolinks`
#![deny(rustdoc)]
//~^ ERROR removed: use `rustdoc::all` instead
// Explicitly don't try to handle this case, it was never valid
#![deny(rustdoc::intra_doc_link_resolution_failure)]
//~^ ERROR unknown lint

View File

@ -34,13 +34,19 @@ error: lint `non_autolinks` has been renamed to `rustdoc::non_autolinks`
LL | #![deny(non_autolinks)]
| ^^^^^^^^^^^^^ help: use the new name: `rustdoc::non_autolinks`
error: lint `rustdoc` has been removed: use `rustdoc::all` instead
--> $DIR/unknown-renamed-lints.rs:15:9
|
LL | #![deny(rustdoc)]
| ^^^^^^^
error: unknown lint: `rustdoc::intra_doc_link_resolution_failure`
--> $DIR/unknown-renamed-lints.rs:16:9
--> $DIR/unknown-renamed-lints.rs:19:9
|
LL | #![deny(rustdoc::intra_doc_link_resolution_failure)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: Compilation failed, aborting rustdoc
error: aborting due to 6 previous errors
error: aborting due to 7 previous errors

View File

@ -0,0 +1,5 @@
// check-pass
// compile-flags: --crate-type lib
#![deny(rustdoc)]
//~^ WARNING removed: use `rustdoc::all`
#![deny(rustdoc::all)] // has no effect when run with rustc directly

View File

@ -0,0 +1,10 @@
warning: lint `rustdoc` has been removed: use `rustdoc::all` instead
--> $DIR/rustdoc-group.rs:3:9
|
LL | #![deny(rustdoc)]
| ^^^^^^^
|
= note: `#[warn(renamed_and_removed_lints)]` on by default
warning: 1 warning emitted

View File

@ -0,0 +1,9 @@
// run-fail
// error-pattern:panicked at 'assertion failed: `(left == right)`
// error-pattern: left: `2`
// error-pattern:right: `3`: 1 + 1 definitely should be 3'
// ignore-emscripten no processes
fn main() {
assert_eq!(1 + 1, 3, "1 + 1 definitely should be 3");
}

View File

@ -0,0 +1,11 @@
// run-fail
// error-pattern:panicked at 'assertion failed: `(left matches right)`
// error-pattern: left: `2`
// error-pattern:right: `3`: 1 + 1 definitely should be 3'
// ignore-emscripten no processes
#![feature(assert_matches)]
fn main() {
assert_matches!(1 + 1, 3, "1 + 1 definitely should be 3");
}

View File

@ -0,0 +1,9 @@
// run-fail
// error-pattern:panicked at 'assertion failed: `(left != right)`
// error-pattern: left: `2`
// error-pattern:right: `2`: 1 + 1 definitely should not be 2'
// ignore-emscripten no processes
fn main() {
assert_ne!(1 + 1, 2, "1 + 1 definitely should not be 2");
}

View File

@ -1,7 +1,8 @@
// aux-build:struct_variant_privacy.rs
extern crate struct_variant_privacy;
fn f(b: struct_variant_privacy::Bar) { //~ ERROR enum `Bar` is private
fn f(b: struct_variant_privacy::Bar) {
//~^ ERROR enum `Bar` is private
match b {
struct_variant_privacy::Bar::Baz { a: _a } => {} //~ ERROR enum `Bar` is private
}

View File

@ -11,7 +11,7 @@ LL | enum Bar {
| ^^^^^^^^
error[E0603]: enum `Bar` is private
--> $DIR/struct-variant-privacy-xc.rs:6:33
--> $DIR/struct-variant-privacy-xc.rs:7:33
|
LL | struct_variant_privacy::Bar::Baz { a: _a } => {}
| ^^^ private enum

View File

@ -1,10 +1,11 @@
mod foo {
enum Bar {
Baz { a: isize }
Baz { a: isize },
}
}
fn f(b: foo::Bar) { //~ ERROR enum `Bar` is private
fn f(b: foo::Bar) {
//~^ ERROR enum `Bar` is private
match b {
foo::Bar::Baz { a: _a } => {} //~ ERROR enum `Bar` is private
}

View File

@ -11,7 +11,7 @@ LL | enum Bar {
| ^^^^^^^^
error[E0603]: enum `Bar` is private
--> $DIR/struct-variant-privacy.rs:9:14
--> $DIR/struct-variant-privacy.rs:10:14
|
LL | foo::Bar::Baz { a: _a } => {}
| ^^^ private enum

View File

@ -0,0 +1,13 @@
// edition:2018
fn main() {
use a::ModPrivateStruct;
let Box { 0: _, .. }: Box<()>; //~ ERROR field `0` of
let Box { 1: _, .. }: Box<()>; //~ ERROR field `1` of
let ModPrivateStruct { 1: _, .. } = ModPrivateStruct::default(); //~ ERROR field `1` of
}
mod a {
#[derive(Default)]
pub struct ModPrivateStruct(u8, u8);
}

View File

@ -0,0 +1,21 @@
error[E0451]: field `0` of struct `Box` is private
--> $DIR/issue-82772.rs:5:15
|
LL | let Box { 0: _, .. }: Box<()>;
| ^^^^ private field
error[E0451]: field `1` of struct `Box` is private
--> $DIR/issue-82772.rs:6:15
|
LL | let Box { 1: _, .. }: Box<()>;
| ^^^^ private field
error[E0451]: field `1` of struct `ModPrivateStruct` is private
--> $DIR/issue-82772.rs:7:28
|
LL | let ModPrivateStruct { 1: _, .. } = ModPrivateStruct::default();
| ^^^^ private field
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0451`.

@ -1 +1 @@
Subproject commit 970bc67c3775781b9708c8a36893576b9459c64a
Subproject commit 32da9eaa5de5be241cf8096ca6b749a157194f77