Skip to content

Commit e77b14e

Browse files
committed
Relax implicit R: Sized bound on BufReader<R>
1 parent b7d8c88 commit e77b14e

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ use buffer::Buffer;
4747
/// }
4848
/// ```
4949
#[stable(feature = "rust1", since = "1.0.0")]
50-
pub struct BufReader<R> {
51-
inner: R,
50+
pub struct BufReader<R: ?Sized> {
5251
buf: Buffer,
52+
inner: R,
5353
}
5454

5555
impl<R: Read> BufReader<R> {
@@ -95,7 +95,7 @@ impl<R: Read> BufReader<R> {
9595
}
9696
}
9797

98-
impl<R> BufReader<R> {
98+
impl<R: ?Sized> BufReader<R> {
9999
/// Gets a reference to the underlying reader.
100100
///
101101
/// It is inadvisable to directly read from the underlying reader.
@@ -213,7 +213,10 @@ impl<R> BufReader<R> {
213213
/// }
214214
/// ```
215215
#[stable(feature = "rust1", since = "1.0.0")]
216-
pub fn into_inner(self) -> R {
216+
pub fn into_inner(self) -> R
217+
where
218+
R: Sized,
219+
{
217220
self.inner
218221
}
219222

@@ -226,13 +229,13 @@ impl<R> BufReader<R> {
226229

227230
// This is only used by a test which asserts that the initialization-tracking is correct.
228231
#[cfg(test)]
229-
impl<R> BufReader<R> {
232+
impl<R: ?Sized> BufReader<R> {
230233
pub fn initialized(&self) -> usize {
231234
self.buf.initialized()
232235
}
233236
}
234237

235-
impl<R: Seek> BufReader<R> {
238+
impl<R: ?Sized + Seek> BufReader<R> {
236239
/// Seeks relative to the current position. If the new position lies within the buffer,
237240
/// the buffer will not be flushed, allowing for more efficient seeks.
238241
/// This method does not return the location of the underlying reader, so the caller
@@ -257,7 +260,7 @@ impl<R: Seek> BufReader<R> {
257260
}
258261

259262
#[stable(feature = "rust1", since = "1.0.0")]
260-
impl<R: Read> Read for BufReader<R> {
263+
impl<R: ?Sized + Read> Read for BufReader<R> {
261264
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
262265
// If we don't have any buffered data and we're doing a massive read
263266
// (larger than our internal buffer), bypass our internal buffer
@@ -371,7 +374,7 @@ impl<R: Read> Read for BufReader<R> {
371374
}
372375

373376
#[stable(feature = "rust1", since = "1.0.0")]
374-
impl<R: Read> BufRead for BufReader<R> {
377+
impl<R: ?Sized + Read> BufRead for BufReader<R> {
375378
fn fill_buf(&mut self) -> io::Result<&[u8]> {
376379
self.buf.fill_buf(&mut self.inner)
377380
}
@@ -384,11 +387,11 @@ impl<R: Read> BufRead for BufReader<R> {
384387
#[stable(feature = "rust1", since = "1.0.0")]
385388
impl<R> fmt::Debug for BufReader<R>
386389
where
387-
R: fmt::Debug,
390+
R: ?Sized + fmt::Debug,
388391
{
389392
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
390393
fmt.debug_struct("BufReader")
391-
.field("reader", &self.inner)
394+
.field("reader", &&self.inner)
392395
.field(
393396
"buffer",
394397
&format_args!("{}/{}", self.buf.filled() - self.buf.pos(), self.capacity()),
@@ -398,7 +401,7 @@ where
398401
}
399402

400403
#[stable(feature = "rust1", since = "1.0.0")]
401-
impl<R: Seek> Seek for BufReader<R> {
404+
impl<R: ?Sized + Seek> Seek for BufReader<R> {
402405
/// Seek to an offset, in bytes, in the underlying reader.
403406
///
404407
/// The position used for seeking with <code>[SeekFrom::Current]\(_)</code> is the
@@ -491,7 +494,7 @@ impl<R: Seek> Seek for BufReader<R> {
491494
}
492495
}
493496

494-
impl<T> SizeHint for BufReader<T> {
497+
impl<T: ?Sized> SizeHint for BufReader<T> {
495498
#[inline]
496499
fn lower_bound(&self) -> usize {
497500
SizeHint::lower_bound(self.get_ref()) + self.buffer().len()

library/std/src/io/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2753,7 +2753,7 @@ trait SizeHint {
27532753
}
27542754
}
27552755

2756-
impl<T> SizeHint for T {
2756+
impl<T: ?Sized> SizeHint for T {
27572757
#[inline]
27582758
default fn lower_bound(&self) -> usize {
27592759
0

library/std/src/sys/unix/kernel_copy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ impl<T: CopyRead> CopyRead for Take<T> {
466466
}
467467
}
468468

469-
impl<T: CopyRead> CopyRead for BufReader<T> {
469+
impl<T: ?Sized + CopyRead> CopyRead for BufReader<T> {
470470
fn drain_to<W: Write>(&mut self, writer: &mut W, outer_limit: u64) -> Result<u64> {
471471
let buf = self.buffer();
472472
let buf = &buf[0..min(buf.len(), outer_limit.try_into().unwrap_or(usize::MAX))];

0 commit comments

Comments
 (0)