Skip to content

Commit 29302a2

Browse files
committed
Relax implicit W: Sized bound on LineWriter<W>
1 parent a497533 commit 29302a2

File tree

2 files changed

+29
-27
lines changed

2 files changed

+29
-27
lines changed

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

+26-24
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ use crate::io::{self, buffered::LineWriterShim, BufWriter, IntoInnerError, IoSli
6464
/// }
6565
/// ```
6666
#[stable(feature = "rust1", since = "1.0.0")]
67-
pub struct LineWriter<W: Write> {
67+
pub struct LineWriter<W: ?Sized + Write> {
6868
inner: BufWriter<W>,
6969
}
7070

@@ -109,27 +109,6 @@ impl<W: Write> LineWriter<W> {
109109
LineWriter { inner: BufWriter::with_capacity(capacity, inner) }
110110
}
111111

112-
/// Gets a reference to the underlying writer.
113-
///
114-
/// # Examples
115-
///
116-
/// ```no_run
117-
/// use std::fs::File;
118-
/// use std::io::LineWriter;
119-
///
120-
/// fn main() -> std::io::Result<()> {
121-
/// let file = File::create("poem.txt")?;
122-
/// let file = LineWriter::new(file);
123-
///
124-
/// let reference = file.get_ref();
125-
/// Ok(())
126-
/// }
127-
/// ```
128-
#[stable(feature = "rust1", since = "1.0.0")]
129-
pub fn get_ref(&self) -> &W {
130-
self.inner.get_ref()
131-
}
132-
133112
/// Gets a mutable reference to the underlying writer.
134113
///
135114
/// Caution must be taken when calling methods on the mutable reference
@@ -184,8 +163,31 @@ impl<W: Write> LineWriter<W> {
184163
}
185164
}
186165

166+
impl<W: ?Sized + Write> LineWriter<W> {
167+
/// Gets a reference to the underlying writer.
168+
///
169+
/// # Examples
170+
///
171+
/// ```no_run
172+
/// use std::fs::File;
173+
/// use std::io::LineWriter;
174+
///
175+
/// fn main() -> std::io::Result<()> {
176+
/// let file = File::create("poem.txt")?;
177+
/// let file = LineWriter::new(file);
178+
///
179+
/// let reference = file.get_ref();
180+
/// Ok(())
181+
/// }
182+
/// ```
183+
#[stable(feature = "rust1", since = "1.0.0")]
184+
pub fn get_ref(&self) -> &W {
185+
self.inner.get_ref()
186+
}
187+
}
188+
187189
#[stable(feature = "rust1", since = "1.0.0")]
188-
impl<W: Write> Write for LineWriter<W> {
190+
impl<W: ?Sized + Write> Write for LineWriter<W> {
189191
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
190192
LineWriterShim::new(&mut self.inner).write(buf)
191193
}
@@ -216,7 +218,7 @@ impl<W: Write> Write for LineWriter<W> {
216218
}
217219

218220
#[stable(feature = "rust1", since = "1.0.0")]
219-
impl<W: Write> fmt::Debug for LineWriter<W>
221+
impl<W: ?Sized + Write> fmt::Debug for LineWriter<W>
220222
where
221223
W: fmt::Debug,
222224
{

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ use crate::sys_common::memchr;
1111
/// `BufWriters` to be temporarily given line-buffering logic; this is what
1212
/// enables Stdout to be alternately in line-buffered or block-buffered mode.
1313
#[derive(Debug)]
14-
pub struct LineWriterShim<'a, W: Write> {
14+
pub struct LineWriterShim<'a, W: ?Sized + Write> {
1515
buffer: &'a mut BufWriter<W>,
1616
}
1717

18-
impl<'a, W: Write> LineWriterShim<'a, W> {
18+
impl<'a, W: ?Sized + Write> LineWriterShim<'a, W> {
1919
pub fn new(buffer: &'a mut BufWriter<W>) -> Self {
2020
Self { buffer }
2121
}
@@ -49,7 +49,7 @@ impl<'a, W: Write> LineWriterShim<'a, W> {
4949
}
5050
}
5151

52-
impl<'a, W: Write> Write for LineWriterShim<'a, W> {
52+
impl<'a, W: ?Sized + Write> Write for LineWriterShim<'a, W> {
5353
/// Write some data into this BufReader with line buffering. This means
5454
/// that, if any newlines are present in the data, the data up to the last
5555
/// newline is sent directly to the underlying writer, and data after it

0 commit comments

Comments
 (0)