Skip to content

Rollup of 10 pull requests #83105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Mar 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3ed6184
Implement Extend and FromIterator for OsString
lopopolo Feb 14, 2021
2fcb8b5
Optimize FromIterator<OsString> to reuse the first allocation
lopopolo Feb 16, 2021
05ea200
Add impls for iterators of Cow<OsStr>
lopopolo Mar 3, 2021
d6b06b8
std: Fix a bug on the wasm32-wasi target opening files
alexcrichton Mar 5, 2021
45229b0
Rename `rustdoc` to `rustdoc::all`
jyn514 Mar 5, 2021
ce2d95c
Demonstrate best practice for feeding stdin of a child processes
kornelski Mar 9, 2021
2fd2796
add ui testcase for issue 82772
csmoe Mar 5, 2021
77fb6a0
fix: check before index into generated patterns
csmoe Mar 11, 2021
1c9d56e
Update cargo
ehuss Mar 13, 2021
f201746
Add `reverse` search alias for Iterator::rev()
Seppel3210 Mar 13, 2021
bc8093e
Fix panic message of `assert_failed_inner`
Mar 13, 2021
7ecb5d8
Add regression tests
Mar 13, 2021
8fd2f0c
Add documentation about formatting `Duration` values
joshtriplett Jan 28, 2021
8164a74
Document `everybody_loops`
camelid Feb 28, 2021
6caa350
Rollup merge of #81465 - joshtriplett:duration-formatting-documentati…
JohnTitor Mar 14, 2021
67bc866
Rollup merge of #82121 - lopopolo:pathbuf-osstring-extend, r=joshtrip…
JohnTitor Mar 14, 2021
f0ebc10
Rollup merge of #82617 - camelid:everybody_loops-docs, r=jyn514
JohnTitor Mar 14, 2021
0d9a6ed
Rollup merge of #82789 - csmoe:issue-82772, r=estebank
JohnTitor Mar 14, 2021
3361402
Rollup merge of #82798 - jyn514:rustdoc-group, r=Manishearth,Guillaum…
JohnTitor Mar 14, 2021
9ce0820
Rollup merge of #82804 - alexcrichton:fix-wasi, r=pnkfelix
JohnTitor Mar 14, 2021
dda9d05
Rollup merge of #82943 - kornelski:threadstdio, r=joshtriplett
JohnTitor Mar 14, 2021
54546a8
Rollup merge of #83066 - Seppel3210:master, r=joshtriplett
JohnTitor Mar 14, 2021
bc79367
Rollup merge of #83070 - ehuss:update-cargo, r=ehuss
JohnTitor Mar 14, 2021
f8206ac
Rollup merge of #83081 - hyd-dev:assert-message, r=m-ou-se
JohnTitor Mar 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions compiler/rustc_interface/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>>,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, .. } => {
Expand Down
1 change: 1 addition & 0 deletions library/core/src/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
11 changes: 11 additions & 0 deletions library/core/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
86 changes: 86 additions & 0 deletions library/std/src/ffi/os_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
}
}
}
}
25 changes: 18 additions & 7 deletions library/std/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions library/std/src/sys/wasi/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc-ui/check-fail.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// compile-flags: -Z unstable-options --check

#![deny(missing_docs)]
#![deny(rustdoc)]
#![deny(rustdoc::all)]

//! ```rust,testharness
//~^ ERROR
Expand Down
12 changes: 6 additions & 6 deletions src/test/rustdoc-ui/check-fail.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`?
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc-ui/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#![warn(missing_docs)]
//~^ WARN
//~^^ WARN
#![warn(rustdoc)]
#![warn(rustdoc::all)]

pub fn foo() {}
//~^ WARN
Expand Down
16 changes: 8 additions & 8 deletions src/test/rustdoc-ui/check.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
| |_______________^
Expand All @@ -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

Expand All @@ -38,17 +38,17 @@ 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() {}
| |_______________^
|
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
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc-ui/lint-group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! println!("sup");
//! ```

#![deny(rustdoc)]
#![deny(rustdoc::all)]

/// what up, let's make an [error]
///
Expand Down
Loading