Skip to content

Soft deprecate Sink #114384

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion library/alloc/src/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ impl<T, A: Allocator> Vec<T, A> {
/// ```
/// use std::io::{self, Write};
/// let buffer = vec![1, 2, 3, 5, 8];
/// io::sink().write(buffer.as_slice()).unwrap();
/// io::empty().write(buffer.as_slice()).unwrap();
/// ```
#[inline]
#[stable(feature = "vec_as_slice", since = "1.7.0")]
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/io/buffered/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ fn bench_buffered_reader_small_reads(b: &mut test::Bencher) {

#[bench]
fn bench_buffered_writer(b: &mut test::Bencher) {
b.iter(|| BufWriter::new(io::sink()));
b.iter(|| BufWriter::new(io::empty()));
}

/// A simple `Write` target, designed to be wrapped by `LineWriter` /
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/io/copy/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::io::*;
#[test]
fn copy_copies() {
let mut r = repeat(0).take(4);
let mut w = sink();
let mut w = empty();
assert_eq!(copy(&mut r, &mut w).unwrap(), 4);

let mut r = repeat(0).take(1 << 17);
Expand Down
1 change: 1 addition & 0 deletions library/std/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ pub use self::stdio::IsTerminal;
#[unstable(feature = "print_internals", issue = "none")]
pub use self::stdio::{_eprint, _print};
#[stable(feature = "rust1", since = "1.0.0")]
#[allow(deprecated_in_future)]
pub use self::{
buffered::{BufReader, BufWriter, IntoInnerError, LineWriter},
copy::copy,
Expand Down
6 changes: 6 additions & 0 deletions library/std/src/io/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ impl fmt::Debug for Repeat {
#[stable(feature = "rust1", since = "1.0.0")]
#[non_exhaustive]
#[derive(Copy, Clone, Debug, Default)]
#[deprecated(since = "TBD", note = "superseded by `Empty`")]
pub struct Sink;

/// Creates an instance of a writer which will successfully consume all data.
Expand All @@ -258,6 +259,7 @@ pub struct Sink;
/// # Examples
///
/// ```rust
/// #![allow(deprecated_in_future)]
/// use std::io::{self, Write};
///
/// let buffer = vec![1, 2, 3, 5, 8];
Expand All @@ -267,11 +269,14 @@ pub struct Sink;
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_io_structs", issue = "78812")]
#[deprecated(since = "TBD", note = "superseded by `Empty`")]
#[allow(deprecated_in_future, dead_code)]
pub const fn sink() -> Sink {
Sink
}

#[stable(feature = "rust1", since = "1.0.0")]
#[allow(deprecated_in_future)]
impl Write for Sink {
#[inline]
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
Expand All @@ -296,6 +301,7 @@ impl Write for Sink {
}

#[stable(feature = "write_mt", since = "1.48.0")]
#[allow(deprecated_in_future)]
impl Write for &Sink {
#[inline]
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
Expand Down
8 changes: 5 additions & 3 deletions library/std/src/io/util/tests.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use crate::io::prelude::*;
use crate::io::{empty, repeat, sink, BorrowedBuf, Empty, Repeat, SeekFrom, Sink};
use crate::io::{self, empty, repeat, BorrowedBuf, Empty, Repeat, SeekFrom};

use crate::mem::MaybeUninit;

#[test]
#[allow(deprecated_in_future)]
fn sink_sinks() {
let mut s = sink();
let mut s = io::sink();
assert_eq!(s.write(&[]).unwrap(), 0);
assert_eq!(s.write(&[0]).unwrap(), 1);
assert_eq!(s.write(&[0; 1024]).unwrap(), 1024);
Expand Down Expand Up @@ -90,8 +91,9 @@ fn take_some_bytes() {
}

#[allow(dead_code)]
#[allow(deprecated_in_future)]
fn const_utils() {
const _: Empty = empty();
const _: Repeat = repeat(b'c');
const _: Sink = sink();
const _: io::Sink = io::sink();
}
2 changes: 1 addition & 1 deletion library/test/src/stats/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ macro_rules! assert_approx_eq {
fn check(samples: &[f64], summ: &Summary) {
let summ2 = Summary::new(samples);

let mut w = io::sink();
let mut w = io::empty();
let w = &mut w;
(write!(w, "\n")).unwrap();

Expand Down
5 changes: 1 addition & 4 deletions src/tools/clippy/clippy_lints/src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,10 +716,7 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) {
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
let fallback_bundle =
rustc_errors::fallback_fluent_bundle(rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(), false);
let emitter = EmitterWriter::new(
Box::new(io::sink()),
fallback_bundle,
);
let emitter = EmitterWriter::new(Box::new(io::sink()), fallback_bundle);
let handler = Handler::with_emitter(Box::new(emitter)).disable_warnings();
let sess = ParseSess::with_span_handler(handler, sm);

Expand Down
8 changes: 5 additions & 3 deletions tests/ui/write-fmt-errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#![feature(io_error_uncategorized)]

use std::fmt;
use std::io::{self, Error, Write, sink};
use std::io::{self, empty, Error, Write};

struct ErrorDisplay;

Expand All @@ -23,12 +23,14 @@ impl Write for ErrorWriter {
Err(Error::new(WRITER_ERROR, "not connected"))
}

fn flush(&mut self) -> io::Result<()> { Ok(()) }
fn flush(&mut self) -> io::Result<()> {
Ok(())
}
}

fn main() {
// Test that the error from the formatter is propagated.
let res = write!(sink(), "{} {} {}", 1, ErrorDisplay, "bar");
let res = write!(empty(), "{} {} {}", 1, ErrorDisplay, "bar");
assert!(res.is_err(), "formatter error did not propagate");
assert_eq!(res.unwrap_err().kind(), FORMAT_ERROR);

Expand Down