Skip to content

Commit 79b4b57

Browse files
committed
Auto merge of #127701 - jhpratt:rollup-n50bfva, r=jhpratt
Rollup of 7 pull requests Successful merges: - #122300 (Add FileCheck annotations to mir-opt/dest-prop tests) - #127153 (Initial implementation of anonymous_pipe API) - #127434 (use "bootstrap" instead of "rustbuild" in comments and docs) - #127477 (Clear `inner_attr_ranges` regularly.) - #127659 (Use ManuallyDrop in BufWriter::into_parts) - #127671 (rustdoc: rename `issue-\d+.rs` tests to have meaningful names (part 8)) - #127677 (using correct tool mode for `run-make-support` crate) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 00167ab + 7a165e5 commit 79b4b57

File tree

67 files changed

+581
-88
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+581
-88
lines changed

INSTALL.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ python x.py build
215215

216216
Right now, building Rust only works with some known versions of Visual Studio.
217217
If you have a more recent version installed and the build system doesn't
218-
understand, you may need to force rustbuild to use an older version.
218+
understand, you may need to force bootstrap to use an older version.
219219
This can be done by manually calling the appropriate vcvars file before running
220220
the bootstrap.
221221

compiler/rustc_codegen_ssa/src/back/linker.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ impl<'a> GccLinker<'a> {
398398
self.link_arg("-dylib");
399399

400400
// Note that the `osx_rpath_install_name` option here is a hack
401-
// purely to support rustbuild right now, we should get a more
401+
// purely to support bootstrap right now, we should get a more
402402
// principled solution at some point to force the compiler to pass
403403
// the right `-Wl,-install_name` with an `@rpath` in it.
404404
if self.sess.opts.cg.rpath || self.sess.opts.unstable_opts.osx_rpath_install_name {

compiler/rustc_parse/src/parser/attr_wrapper.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -352,15 +352,10 @@ impl<'a> Parser<'a> {
352352
let target = AttrsTarget { attrs: final_attrs.iter().cloned().collect(), tokens };
353353
self.capture_state.replace_ranges.push((start_pos..end_pos, Some(target)));
354354
self.capture_state.replace_ranges.extend(inner_attr_replace_ranges);
355-
}
356-
357-
// Only clear our `replace_ranges` when we're finished capturing entirely.
358-
if matches!(self.capture_state.capturing, Capturing::No) {
355+
} else if matches!(self.capture_state.capturing, Capturing::No) {
356+
// Only clear the ranges once we've finished capturing entirely.
359357
self.capture_state.replace_ranges.clear();
360-
// We don't clear `inner_attr_ranges`, as doing so repeatedly
361-
// had a measurable performance impact. Most inner attributes that
362-
// we insert will get removed - when we drop the parser, we'll free
363-
// up the memory used by any attributes that we didn't remove from the map.
358+
self.capture_state.inner_attr_ranges.clear();
364359
}
365360
Ok(ret)
366361
}

compiler/rustc_session/src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2620,7 +2620,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
26202620
// This is the location used by the `rust-src` `rustup` component.
26212621
let mut candidate = sysroot.join("lib/rustlib/src/rust");
26222622
if let Ok(metadata) = candidate.symlink_metadata() {
2623-
// Replace the symlink rustbuild creates, with its destination.
2623+
// Replace the symlink bootstrap creates, with its destination.
26242624
// We could try to use `fs::canonicalize` instead, but that might
26252625
// produce unnecessarily verbose path.
26262626
if metadata.file_type().is_symlink() {

config.example.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Sample TOML configuration file for building Rust.
22
#
3-
# To configure rustbuild, run `./configure` or `./x.py setup`.
3+
# To configure bootstrap, run `./configure` or `./x.py setup`.
44
# See https://rustc-dev-guide.rust-lang.org/building/how-to-build-and-run.html#create-a-configtoml for more information.
55
#
66
# All options are commented out by default in this file, and they're commented
@@ -109,7 +109,7 @@
109109
# increases the size of binaries and consequently the memory required by
110110
# each linker process.
111111
# If set to 0, linker invocations are treated like any other job and
112-
# controlled by rustbuild's -j parameter.
112+
# controlled by bootstrap's -j parameter.
113113
#link-jobs = 0
114114

115115
# Whether to build LLVM as a dynamically linked library (as opposed to statically linked).
@@ -371,11 +371,11 @@
371371
# Useful for modifying only the stage2 compiler without having to pass `--keep-stage 0` each time.
372372
#local-rebuild = false
373373

374-
# Print out how long each rustbuild step took (mostly intended for CI and
374+
# Print out how long each bootstrap step took (mostly intended for CI and
375375
# tracking over time)
376376
#print-step-timings = false
377377

378-
# Print out resource usage data for each rustbuild step, as defined by the Unix
378+
# Print out resource usage data for each bootstrap step, as defined by the Unix
379379
# struct rusage. (Note that this setting is completely unstable: the data it
380380
# captures, what platforms it supports, the format of its associated output, and
381381
# this setting's very existence, are all subject to change.)

library/std/src/io/buffered/bufwriter.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::fmt;
33
use crate::io::{
44
self, ErrorKind, IntoInnerError, IoSlice, Seek, SeekFrom, Write, DEFAULT_BUF_SIZE,
55
};
6-
use crate::mem;
6+
use crate::mem::{self, ManuallyDrop};
77
use crate::ptr;
88

99
/// Wraps a writer and buffers its output.
@@ -164,13 +164,13 @@ impl<W: Write> BufWriter<W> {
164164
/// assert_eq!(&buffered_data.unwrap(), b"ata");
165165
/// ```
166166
#[stable(feature = "bufwriter_into_parts", since = "1.56.0")]
167-
pub fn into_parts(mut self) -> (W, Result<Vec<u8>, WriterPanicked>) {
168-
let buf = mem::take(&mut self.buf);
169-
let buf = if !self.panicked { Ok(buf) } else { Err(WriterPanicked { buf }) };
167+
pub fn into_parts(self) -> (W, Result<Vec<u8>, WriterPanicked>) {
168+
let mut this = ManuallyDrop::new(self);
169+
let buf = mem::take(&mut this.buf);
170+
let buf = if !this.panicked { Ok(buf) } else { Err(WriterPanicked { buf }) };
170171

171-
// SAFETY: forget(self) prevents double dropping inner
172-
let inner = unsafe { ptr::read(&self.inner) };
173-
mem::forget(self);
172+
// SAFETY: double-drops are prevented by putting `this` in a ManuallyDrop that is never dropped
173+
let inner = unsafe { ptr::read(&this.inner) };
174174

175175
(inner, buf)
176176
}

library/std/src/io/buffered/tests.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1067,3 +1067,13 @@ fn bufreader_full_initialize() {
10671067
// But we initialized the whole buffer!
10681068
assert_eq!(reader.initialized(), reader.capacity());
10691069
}
1070+
1071+
/// This is a regression test for https://github.com/rust-lang/rust/issues/127584.
1072+
#[test]
1073+
fn bufwriter_aliasing() {
1074+
use crate::io::{BufWriter, Cursor};
1075+
let mut v = vec![0; 1024];
1076+
let c = Cursor::new(&mut v);
1077+
let w = BufWriter::new(Box::new(c));
1078+
let _ = w.into_parts();
1079+
}

library/std/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,9 @@ pub use core::{
684684
module_path, option_env, stringify, trace_macros,
685685
};
686686

687+
#[unstable(feature = "anonymous_pipe", issue = "127154")]
688+
pub use crate::sys::anonymous_pipe as pipe;
689+
687690
#[unstable(
688691
feature = "concat_bytes",
689692
issue = "87555",
+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
//! Module for annoymous pipe
2+
//!
3+
//! ```
4+
//! #![feature(anonymous_pipe)]
5+
//! # fn main() -> std::io::Result<()> {
6+
//! let (reader, writer) = std::pipe::pipe()?;
7+
//! # Ok(())
8+
//! # }
9+
//! ```
10+
11+
use crate::{io, sys::pipe::AnonPipe};
12+
13+
/// Create annoymous pipe that is close-on-exec and blocking.
14+
#[unstable(feature = "anonymous_pipe", issue = "127154")]
15+
#[inline]
16+
pub fn pipe() -> io::Result<(PipeReader, PipeWriter)> {
17+
cfg_if::cfg_if! {
18+
if #[cfg(unix)] {
19+
unix::pipe()
20+
} else if #[cfg(windows)] {
21+
windows::pipe()
22+
} else {
23+
Err(io::Error::UNSUPPORTED_PLATFORM)
24+
}
25+
}
26+
}
27+
28+
/// Read end of the annoymous pipe.
29+
#[unstable(feature = "anonymous_pipe", issue = "127154")]
30+
#[derive(Debug)]
31+
pub struct PipeReader(AnonPipe);
32+
33+
/// Write end of the annoymous pipe.
34+
#[unstable(feature = "anonymous_pipe", issue = "127154")]
35+
#[derive(Debug)]
36+
pub struct PipeWriter(AnonPipe);
37+
38+
impl PipeReader {
39+
/// Create a new [`PipeReader`] instance that shares the same underlying file description.
40+
#[unstable(feature = "anonymous_pipe", issue = "127154")]
41+
pub fn try_clone(&self) -> io::Result<Self> {
42+
self.0.try_clone().map(Self)
43+
}
44+
}
45+
46+
impl PipeWriter {
47+
/// Create a new [`PipeWriter`] instance that shares the same underlying file description.
48+
#[unstable(feature = "anonymous_pipe", issue = "127154")]
49+
pub fn try_clone(&self) -> io::Result<Self> {
50+
self.0.try_clone().map(Self)
51+
}
52+
}
53+
54+
#[unstable(feature = "anonymous_pipe", issue = "127154")]
55+
impl io::Read for &PipeReader {
56+
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
57+
self.0.read(buf)
58+
}
59+
fn read_vectored(&mut self, bufs: &mut [io::IoSliceMut<'_>]) -> io::Result<usize> {
60+
self.0.read_vectored(bufs)
61+
}
62+
#[inline]
63+
fn is_read_vectored(&self) -> bool {
64+
self.0.is_read_vectored()
65+
}
66+
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
67+
self.0.read_to_end(buf)
68+
}
69+
fn read_buf(&mut self, buf: io::BorrowedCursor<'_>) -> io::Result<()> {
70+
self.0.read_buf(buf)
71+
}
72+
}
73+
74+
#[unstable(feature = "anonymous_pipe", issue = "127154")]
75+
impl io::Read for PipeReader {
76+
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
77+
self.0.read(buf)
78+
}
79+
fn read_vectored(&mut self, bufs: &mut [io::IoSliceMut<'_>]) -> io::Result<usize> {
80+
self.0.read_vectored(bufs)
81+
}
82+
#[inline]
83+
fn is_read_vectored(&self) -> bool {
84+
self.0.is_read_vectored()
85+
}
86+
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
87+
self.0.read_to_end(buf)
88+
}
89+
fn read_buf(&mut self, buf: io::BorrowedCursor<'_>) -> io::Result<()> {
90+
self.0.read_buf(buf)
91+
}
92+
}
93+
94+
#[unstable(feature = "anonymous_pipe", issue = "127154")]
95+
impl io::Write for &PipeWriter {
96+
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
97+
self.0.write(buf)
98+
}
99+
#[inline]
100+
fn flush(&mut self) -> io::Result<()> {
101+
Ok(())
102+
}
103+
104+
fn write_vectored(&mut self, bufs: &[io::IoSlice<'_>]) -> io::Result<usize> {
105+
self.0.write_vectored(bufs)
106+
}
107+
108+
#[inline]
109+
fn is_write_vectored(&self) -> bool {
110+
self.0.is_write_vectored()
111+
}
112+
}
113+
114+
#[unstable(feature = "anonymous_pipe", issue = "127154")]
115+
impl io::Write for PipeWriter {
116+
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
117+
self.0.write(buf)
118+
}
119+
#[inline]
120+
fn flush(&mut self) -> io::Result<()> {
121+
Ok(())
122+
}
123+
124+
fn write_vectored(&mut self, bufs: &[io::IoSlice<'_>]) -> io::Result<usize> {
125+
self.0.write_vectored(bufs)
126+
}
127+
128+
#[inline]
129+
fn is_write_vectored(&self) -> bool {
130+
self.0.is_write_vectored()
131+
}
132+
}
133+
134+
#[cfg(unix)]
135+
mod unix;
136+
137+
#[cfg(windows)]
138+
mod windows;
139+
140+
#[cfg(test)]
141+
mod tests;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use super::*;
2+
use crate::io::{Read, Write};
3+
4+
#[test]
5+
fn pipe_creation_and_rw() {
6+
let (mut rx, mut tx) = pipe().unwrap();
7+
tx.write_all(b"12345").unwrap();
8+
drop(tx);
9+
10+
let mut s = String::new();
11+
rx.read_to_string(&mut s).unwrap();
12+
assert_eq!(s, "12345");
13+
}
14+
15+
#[test]
16+
fn pipe_try_clone_and_rw() {
17+
let (mut rx, mut tx) = pipe().unwrap();
18+
tx.try_clone().unwrap().write_all(b"12").unwrap();
19+
tx.write_all(b"345").unwrap();
20+
drop(tx);
21+
22+
let mut s = String::new();
23+
rx.try_clone().unwrap().take(3).read_to_string(&mut s).unwrap();
24+
assert_eq!(s, "123");
25+
26+
s.clear();
27+
rx.read_to_string(&mut s).unwrap();
28+
assert_eq!(s, "45");
29+
}

0 commit comments

Comments
 (0)