From f1ff3c140c1cd3e0d3f19c658bd2662437686955 Mon Sep 17 00:00:00 2001 From: Alex Saveau Date: Wed, 2 Aug 2023 20:54:09 +0100 Subject: [PATCH 1/3] Soft deprecate Sink Signed-off-by: Alex Saveau --- library/std/src/io/mod.rs | 1 + library/std/src/io/util.rs | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/library/std/src/io/mod.rs b/library/std/src/io/mod.rs index 5c1d2d8f46cd4..2c672dccf42fb 100644 --- a/library/std/src/io/mod.rs +++ b/library/std/src/io/mod.rs @@ -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, diff --git a/library/std/src/io/util.rs b/library/std/src/io/util.rs index 3840ffe7eecaa..9289b9da4033b 100644 --- a/library/std/src/io/util.rs +++ b/library/std/src/io/util.rs @@ -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. @@ -267,11 +268,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)] 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 { @@ -296,6 +300,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 { From 7a077b5a94635e1e677d888eb40f1a851393f9df Mon Sep 17 00:00:00 2001 From: Alex Saveau Date: Wed, 2 Aug 2023 21:24:49 +0100 Subject: [PATCH 2/3] Migrate sink usages to empty Signed-off-by: Alex Saveau --- library/alloc/src/vec/mod.rs | 2 +- library/std/src/io/buffered/tests.rs | 2 +- library/std/src/io/copy/tests.rs | 2 +- library/std/src/io/util.rs | 3 ++- library/std/src/io/util/tests.rs | 8 +++++--- library/test/src/stats/tests.rs | 2 +- src/librustdoc/doctest.rs | 4 ++-- src/tools/clippy/clippy_lints/src/doc.rs | 5 +---- tests/ui/write-fmt-errors.rs | 8 +++++--- 9 files changed, 19 insertions(+), 17 deletions(-) diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index e45ddc7896beb..64a7b9a4d980e 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -1181,7 +1181,7 @@ impl Vec { /// ``` /// 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")] diff --git a/library/std/src/io/buffered/tests.rs b/library/std/src/io/buffered/tests.rs index 35a5291a34769..30867d95329be 100644 --- a/library/std/src/io/buffered/tests.rs +++ b/library/std/src/io/buffered/tests.rs @@ -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` / diff --git a/library/std/src/io/copy/tests.rs b/library/std/src/io/copy/tests.rs index af137eaf856f5..d58d1d6c5c691 100644 --- a/library/std/src/io/copy/tests.rs +++ b/library/std/src/io/copy/tests.rs @@ -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); diff --git a/library/std/src/io/util.rs b/library/std/src/io/util.rs index 9289b9da4033b..194f8bbf140d1 100644 --- a/library/std/src/io/util.rs +++ b/library/std/src/io/util.rs @@ -259,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]; @@ -269,7 +270,7 @@ pub struct Sink; #[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)] +#[allow(deprecated_in_future, dead_code)] pub const fn sink() -> Sink { Sink } diff --git a/library/std/src/io/util/tests.rs b/library/std/src/io/util/tests.rs index 6de91e29c7707..4608e21fd11a6 100644 --- a/library/std/src/io/util/tests.rs +++ b/library/std/src/io/util/tests.rs @@ -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); @@ -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(); } diff --git a/library/test/src/stats/tests.rs b/library/test/src/stats/tests.rs index 3a6e8401bf1ab..46184b6132d44 100644 --- a/library/test/src/stats/tests.rs +++ b/library/test/src/stats/tests.rs @@ -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(); diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 3315ccad4d367..544fea6cbab04 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -562,7 +562,7 @@ pub(crate) fn make_test( .diagnostic_width(Some(80)) .supports_color(); - let emitter = EmitterWriter::new(Box::new(io::sink()), fallback_bundle); + let emitter = EmitterWriter::new(Box::new(io::empty()), fallback_bundle); // FIXME(misdreavus): pass `-Z treat-err-as-bug` to the doctest parser let handler = Handler::with_emitter(Box::new(emitter)).disable_warnings(); @@ -738,7 +738,7 @@ fn check_if_attr_is_complete(source: &str, edition: Edition) -> bool { false, ); - let emitter = EmitterWriter::new(Box::new(io::sink()), fallback_bundle); + let emitter = EmitterWriter::new(Box::new(io::empty()), fallback_bundle); let handler = Handler::with_emitter(Box::new(emitter)).disable_warnings(); let sess = ParseSess::with_span_handler(handler, sm); diff --git a/src/tools/clippy/clippy_lints/src/doc.rs b/src/tools/clippy/clippy_lints/src/doc.rs index 2c4d93e33ba76..8b1a4112a9990 100644 --- a/src/tools/clippy/clippy_lints/src/doc.rs +++ b/src/tools/clippy/clippy_lints/src/doc.rs @@ -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::empty()), fallback_bundle); let handler = Handler::with_emitter(Box::new(emitter)).disable_warnings(); let sess = ParseSess::with_span_handler(handler, sm); diff --git a/tests/ui/write-fmt-errors.rs b/tests/ui/write-fmt-errors.rs index 3fcaefaa63ef1..414bfa3d5dd56 100644 --- a/tests/ui/write-fmt-errors.rs +++ b/tests/ui/write-fmt-errors.rs @@ -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; @@ -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); From cc8057edfd59ebcb3bb540938bef4e1fae5e4af3 Mon Sep 17 00:00:00 2001 From: Alex Saveau Date: Sun, 6 Aug 2023 11:44:58 +0100 Subject: [PATCH 3/3] Revert 3P changes that require termcolor to be updated Signed-off-by: Alex Saveau --- src/librustdoc/doctest.rs | 4 ++-- src/tools/clippy/clippy_lints/src/doc.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 544fea6cbab04..3315ccad4d367 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -562,7 +562,7 @@ pub(crate) fn make_test( .diagnostic_width(Some(80)) .supports_color(); - let emitter = EmitterWriter::new(Box::new(io::empty()), fallback_bundle); + let emitter = EmitterWriter::new(Box::new(io::sink()), fallback_bundle); // FIXME(misdreavus): pass `-Z treat-err-as-bug` to the doctest parser let handler = Handler::with_emitter(Box::new(emitter)).disable_warnings(); @@ -738,7 +738,7 @@ fn check_if_attr_is_complete(source: &str, edition: Edition) -> bool { false, ); - let emitter = EmitterWriter::new(Box::new(io::empty()), 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); diff --git a/src/tools/clippy/clippy_lints/src/doc.rs b/src/tools/clippy/clippy_lints/src/doc.rs index 8b1a4112a9990..e29ab634c9790 100644 --- a/src/tools/clippy/clippy_lints/src/doc.rs +++ b/src/tools/clippy/clippy_lints/src/doc.rs @@ -716,7 +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::empty()), 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);