Skip to content

Commit e29faf0

Browse files
committed
Auto merge of #64057 - Centril:rollup-nwtk2fb, r=Centril
Rollup of 5 pull requests Successful merges: - #63410 (Update BufWriter example to include call to flush()) - #64029 (Account for rounding errors when deciding the diagnostic boundaries) - #64032 (rustdoc use -Ccodegen-units=1 by default for test compile) - #64039 (Update sync condvar doc style) - #64042 (Fix word repetition in str documentation) Failed merges: r? @ghost
2 parents d0677b9 + 0211246 commit e29faf0

File tree

5 files changed

+37
-32
lines changed

5 files changed

+37
-32
lines changed

src/libcore/str/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3558,7 +3558,7 @@ impl str {
35583558
/// A string is a sequence of bytes. `start` in this context means the first
35593559
/// position of that byte string; for a left-to-right language like English or
35603560
/// Russian, this will be left side, and for right-to-left languages like
3561-
/// like Arabic or Hebrew, this will be the right side.
3561+
/// Arabic or Hebrew, this will be the right side.
35623562
///
35633563
/// # Examples
35643564
///
@@ -3595,7 +3595,7 @@ impl str {
35953595
/// A string is a sequence of bytes. `end` in this context means the last
35963596
/// position of that byte string; for a left-to-right language like English or
35973597
/// Russian, this will be right side, and for right-to-left languages like
3598-
/// like Arabic or Hebrew, this will be the left side.
3598+
/// Arabic or Hebrew, this will be the left side.
35993599
///
36003600
/// # Examples
36013601
///
@@ -3762,7 +3762,7 @@ impl str {
37623762
/// A string is a sequence of bytes. `start` in this context means the first
37633763
/// position of that byte string; for a left-to-right language like English or
37643764
/// Russian, this will be left side, and for right-to-left languages like
3765-
/// like Arabic or Hebrew, this will be the right side.
3765+
/// Arabic or Hebrew, this will be the right side.
37663766
///
37673767
/// # Examples
37683768
///
@@ -3801,7 +3801,7 @@ impl str {
38013801
/// A string is a sequence of bytes. `end` in this context means the last
38023802
/// position of that byte string; for a left-to-right language like English or
38033803
/// Russian, this will be right side, and for right-to-left languages like
3804-
/// like Arabic or Hebrew, this will be the left side.
3804+
/// Arabic or Hebrew, this will be the left side.
38053805
///
38063806
/// # Examples
38073807
///

src/librustc_errors/emitter.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,12 @@ impl Margin {
146146
} else if self.label_right - self.span_left <= self.column_width {
147147
// Attempt to fit the code window considering only the spans and labels.
148148
let padding_left = (self.column_width - (self.label_right - self.span_left)) / 2;
149-
self.computed_left = self.span_left - padding_left;
149+
self.computed_left = self.span_left.saturating_sub(padding_left);
150150
self.computed_right = self.computed_left + self.column_width;
151151
} else if self.span_right - self.span_left <= self.column_width {
152152
// Attempt to fit the code window considering the spans and labels plus padding.
153153
let padding_left = (self.column_width - (self.span_right - self.span_left)) / 5 * 2;
154-
self.computed_left = self.span_left - padding_left;
154+
self.computed_left = self.span_left.saturating_sub(padding_left);
155155
self.computed_right = self.computed_left + self.column_width;
156156
} else { // Mostly give up but still don't show the full line.
157157
self.computed_left = self.span_left;
@@ -1304,11 +1304,13 @@ impl EmitterWriter {
13041304
};
13051305

13061306
let column_width = if let Some(width) = self.terminal_width {
1307-
width
1307+
width.saturating_sub(code_offset)
13081308
} else if self.ui_testing {
13091309
140
13101310
} else {
1311-
term_size::dimensions().map(|(w, _)| w - code_offset).unwrap_or(140)
1311+
term_size::dimensions()
1312+
.map(|(w, _)| w.saturating_sub(code_offset))
1313+
.unwrap_or(std::usize::MAX)
13121314
};
13131315

13141316
let margin = Margin::new(

src/librustdoc/test.rs

+1
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ fn run_test(
263263
for extern_str in &options.extern_strs {
264264
compiler.arg("--extern").arg(&extern_str);
265265
}
266+
compiler.arg("-Ccodegen-units=1");
266267
for codegen_options_str in &options.codegen_options_strs {
267268
compiler.arg("-C").arg(&codegen_options_str);
268269
}

src/libstd/io/buffered.rs

+24-22
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ use crate::io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom,
99
IoSliceMut};
1010
use crate::memchr;
1111

12-
/// The `BufReader` struct adds buffering to any reader.
12+
/// The `BufReader<R>` struct adds buffering to any reader.
1313
///
1414
/// It can be excessively inefficient to work directly with a [`Read`] instance.
1515
/// For example, every call to [`read`][`TcpStream::read`] on [`TcpStream`]
16-
/// results in a system call. A `BufReader` performs large, infrequent reads on
16+
/// results in a system call. A `BufReader<R>` performs large, infrequent reads on
1717
/// the underlying [`Read`] and maintains an in-memory buffer of the results.
1818
///
19-
/// `BufReader` can improve the speed of programs that make *small* and
19+
/// `BufReader<R>` can improve the speed of programs that make *small* and
2020
/// *repeated* read calls to the same file or network socket. It does not
2121
/// help when reading very large amounts at once, or reading just one or a few
2222
/// times. It also provides no advantage when reading from a source that is
2323
/// already in memory, like a `Vec<u8>`.
2424
///
25-
/// When the `BufReader` is dropped, the contents of its buffer will be
26-
/// discarded. Creating multiple instances of a `BufReader` on the same
25+
/// When the `BufReader<R>` is dropped, the contents of its buffer will be
26+
/// discarded. Creating multiple instances of a `BufReader<R>` on the same
2727
/// stream can cause data loss.
2828
///
2929
/// [`Read`]: ../../std/io/trait.Read.html
@@ -56,7 +56,7 @@ pub struct BufReader<R> {
5656
}
5757

5858
impl<R: Read> BufReader<R> {
59-
/// Creates a new `BufReader` with a default buffer capacity. The default is currently 8 KB,
59+
/// Creates a new `BufReader<R>` with a default buffer capacity. The default is currently 8 KB,
6060
/// but may change in the future.
6161
///
6262
/// # Examples
@@ -76,7 +76,7 @@ impl<R: Read> BufReader<R> {
7676
BufReader::with_capacity(DEFAULT_BUF_SIZE, inner)
7777
}
7878

79-
/// Creates a new `BufReader` with the specified buffer capacity.
79+
/// Creates a new `BufReader<R>` with the specified buffer capacity.
8080
///
8181
/// # Examples
8282
///
@@ -177,7 +177,7 @@ impl<R> BufReader<R> {
177177
&self.buf[self.pos..self.cap]
178178
}
179179

180-
/// Unwraps this `BufReader`, returning the underlying reader.
180+
/// Unwraps this `BufReader<R>`, returning the underlying reader.
181181
///
182182
/// Note that any leftover data in the internal buffer is lost.
183183
///
@@ -304,7 +304,7 @@ impl<R: Seek> Seek for BufReader<R> {
304304
/// Seek to an offset, in bytes, in the underlying reader.
305305
///
306306
/// The position used for seeking with `SeekFrom::Current(_)` is the
307-
/// position the underlying reader would be at if the `BufReader` had no
307+
/// position the underlying reader would be at if the `BufReader<R>` had no
308308
/// internal buffer.
309309
///
310310
/// Seeking always discards the internal buffer, even if the seek position
@@ -355,19 +355,20 @@ impl<R: Seek> Seek for BufReader<R> {
355355
/// It can be excessively inefficient to work directly with something that
356356
/// implements [`Write`]. For example, every call to
357357
/// [`write`][`TcpStream::write`] on [`TcpStream`] results in a system call. A
358-
/// `BufWriter` keeps an in-memory buffer of data and writes it to an underlying
358+
/// `BufWriter<W>` keeps an in-memory buffer of data and writes it to an underlying
359359
/// writer in large, infrequent batches.
360360
///
361-
/// `BufWriter` can improve the speed of programs that make *small* and
361+
/// `BufWriter<W>` can improve the speed of programs that make *small* and
362362
/// *repeated* write calls to the same file or network socket. It does not
363363
/// help when writing very large amounts at once, or writing just one or a few
364364
/// times. It also provides no advantage when writing to a destination that is
365365
/// in memory, like a `Vec<u8>`.
366366
///
367-
/// When the `BufWriter` is dropped, the contents of its buffer will be written
368-
/// out. However, any errors that happen in the process of flushing the buffer
369-
/// when the writer is dropped will be ignored. Code that wishes to handle such
370-
/// errors must manually call [`flush`] before the writer is dropped.
367+
/// It is critical to call [`flush`] before `BufWriter<W>` is dropped. Though
368+
/// dropping will attempt to flush the the contents of the buffer, any errors
369+
/// that happen in the process of dropping will be ignored. Calling ['flush']
370+
/// ensures that the buffer is empty and thus dropping will not even attempt
371+
/// file operations.
371372
///
372373
/// # Examples
373374
///
@@ -386,7 +387,7 @@ impl<R: Seek> Seek for BufReader<R> {
386387
///
387388
/// Because we're not buffering, we write each one in turn, incurring the
388389
/// overhead of a system call per byte written. We can fix this with a
389-
/// `BufWriter`:
390+
/// `BufWriter<W>`:
390391
///
391392
/// ```no_run
392393
/// use std::io::prelude::*;
@@ -398,11 +399,12 @@ impl<R: Seek> Seek for BufReader<R> {
398399
/// for i in 0..10 {
399400
/// stream.write(&[i+1]).unwrap();
400401
/// }
402+
/// stream.flush().unwrap();
401403
/// ```
402404
///
403-
/// By wrapping the stream with a `BufWriter`, these ten writes are all grouped
404-
/// together by the buffer, and will all be written out in one system call when
405-
/// the `stream` is dropped.
405+
/// By wrapping the stream with a `BufWriter<W>`, these ten writes are all grouped
406+
/// together by the buffer and will all be written out in one system call when
407+
/// the `stream` is flushed.
406408
///
407409
/// [`Write`]: ../../std/io/trait.Write.html
408410
/// [`TcpStream::write`]: ../../std/net/struct.TcpStream.html#method.write
@@ -447,7 +449,7 @@ pub struct BufWriter<W: Write> {
447449
pub struct IntoInnerError<W>(W, Error);
448450

449451
impl<W: Write> BufWriter<W> {
450-
/// Creates a new `BufWriter` with a default buffer capacity. The default is currently 8 KB,
452+
/// Creates a new `BufWriter<W>` with a default buffer capacity. The default is currently 8 KB,
451453
/// but may change in the future.
452454
///
453455
/// # Examples
@@ -463,7 +465,7 @@ impl<W: Write> BufWriter<W> {
463465
BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner)
464466
}
465467

466-
/// Creates a new `BufWriter` with the specified buffer capacity.
468+
/// Creates a new `BufWriter<W>` with the specified buffer capacity.
467469
///
468470
/// # Examples
469471
///
@@ -564,7 +566,7 @@ impl<W: Write> BufWriter<W> {
564566
&self.buf
565567
}
566568

567-
/// Unwraps this `BufWriter`, returning the underlying writer.
569+
/// Unwraps this `BufWriter<W>`, returning the underlying writer.
568570
///
569571
/// The buffer is written out before returning the writer.
570572
///

src/libstd/sync/condvar.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ impl WaitTimeoutResult {
2828
/// once the boolean has been updated and notified.
2929
///
3030
/// ```
31-
/// use std::sync::{Arc, Mutex, Condvar};
31+
/// use std::sync::{Arc, Condvar, Mutex};
3232
/// use std::thread;
3333
/// use std::time::Duration;
3434
///
3535
/// let pair = Arc::new((Mutex::new(false), Condvar::new()));
3636
/// let pair2 = pair.clone();
3737
///
38-
/// thread::spawn(move|| {
38+
/// thread::spawn(move || {
3939
/// let (lock, cvar) = &*pair2;
4040
///
4141
/// // Let's wait 20 milliseconds before notifying the condvar.

0 commit comments

Comments
 (0)