Skip to content

Commit 7cbeddb

Browse files
committed
Deprecate Read::chars and char::decode_utf8
Per FCP: * #27802 (comment) * #33906 (comment)
1 parent 21dae95 commit 7cbeddb

File tree

6 files changed

+32
-1
lines changed

6 files changed

+32
-1
lines changed

src/libcore/char/decode.rs

+11
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,32 @@ use super::from_u32_unchecked;
1717
/// An iterator over an iterator of bytes of the characters the bytes represent
1818
/// as UTF-8
1919
#[unstable(feature = "decode_utf8", issue = "33906")]
20+
#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead:
21+
https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")]
2022
#[derive(Clone, Debug)]
23+
#[allow(deprecated)]
2124
pub struct DecodeUtf8<I: Iterator<Item = u8>>(::iter::Peekable<I>);
2225

2326
/// Decodes an `Iterator` of bytes as UTF-8.
2427
#[unstable(feature = "decode_utf8", issue = "33906")]
28+
#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead:
29+
https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")]
30+
#[allow(deprecated)]
2531
#[inline]
2632
pub fn decode_utf8<I: IntoIterator<Item = u8>>(i: I) -> DecodeUtf8<I::IntoIter> {
2733
DecodeUtf8(i.into_iter().peekable())
2834
}
2935

3036
/// `<DecodeUtf8 as Iterator>::next` returns this for an invalid input sequence.
3137
#[unstable(feature = "decode_utf8", issue = "33906")]
38+
#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead:
39+
https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")]
3240
#[derive(PartialEq, Eq, Debug)]
41+
#[allow(deprecated)]
3342
pub struct InvalidSequence(());
3443

3544
#[unstable(feature = "decode_utf8", issue = "33906")]
45+
#[allow(deprecated)]
3646
impl<I: Iterator<Item = u8>> Iterator for DecodeUtf8<I> {
3747
type Item = Result<char, InvalidSequence>;
3848
#[inline]
@@ -127,6 +137,7 @@ impl<I: Iterator<Item = u8>> Iterator for DecodeUtf8<I> {
127137
}
128138

129139
#[unstable(feature = "decode_utf8", issue = "33906")]
140+
#[allow(deprecated)]
130141
impl<I: FusedIterator<Item = u8>> FusedIterator for DecodeUtf8<I> {}
131142

132143
/// An iterator that decodes UTF-16 encoded code points from an iterator of `u16`s.

src/libcore/char/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ pub use unicode::tables::UNICODE_VERSION;
5151
#[unstable(feature = "unicode_version", issue = "49726")]
5252
pub use unicode::version::UnicodeVersion;
5353
#[unstable(feature = "decode_utf8", issue = "33906")]
54+
#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead:
55+
https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")]
56+
#[allow(deprecated)]
5457
pub use self::decode::{decode_utf8, DecodeUtf8, InvalidSequence};
5558

5659
use fmt::{self, Write};

src/libcore/tests/char.rs

+1
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ fn eu_iterator_specializations() {
364364
}
365365

366366
#[test]
367+
#[allow(deprecated)]
367368
fn test_decode_utf8() {
368369
macro_rules! assert_decode_utf8 {
369370
($input_bytes: expr, $expected_str: expr) => {

src/libstd/io/buffered.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1251,13 +1251,15 @@ mod tests {
12511251
}
12521252

12531253
#[test]
1254+
#[allow(deprecated)]
12541255
fn read_char_buffered() {
12551256
let buf = [195, 159];
12561257
let reader = BufReader::with_capacity(1, &buf[..]);
12571258
assert_eq!(reader.chars().next().unwrap().unwrap(), 'ß');
12581259
}
12591260

12601261
#[test]
1262+
#[allow(deprecated)]
12611263
fn test_chars() {
12621264
let buf = [195, 159, b'a'];
12631265
let reader = BufReader::with_capacity(1, &buf[..]);

src/libstd/io/cursor.rs

+2
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ mod tests {
566566
}
567567

568568
#[test]
569+
#[allow(deprecated)]
569570
fn test_read_char() {
570571
let b = &b"Vi\xE1\xBB\x87t"[..];
571572
let mut c = Cursor::new(b).chars();
@@ -577,6 +578,7 @@ mod tests {
577578
}
578579

579580
#[test]
581+
#[allow(deprecated)]
580582
fn test_read_bad_char() {
581583
let b = &b"\x80"[..];
582584
let mut c = Cursor::new(b).chars();

src/libstd/io/mod.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,9 @@ pub trait Read {
840840
of where errors happen is currently \
841841
unclear and may change",
842842
issue = "27802")]
843+
#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead:
844+
https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")]
845+
#[allow(deprecated)]
843846
fn chars(self) -> Chars<Self> where Self: Sized {
844847
Chars { inner: self }
845848
}
@@ -2010,16 +2013,22 @@ impl<R: Read> Iterator for Bytes<R> {
20102013
/// [chars]: trait.Read.html#method.chars
20112014
#[unstable(feature = "io", reason = "awaiting stability of Read::chars",
20122015
issue = "27802")]
2016+
#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead:
2017+
https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")]
20132018
#[derive(Debug)]
2019+
#[allow(deprecated)]
20142020
pub struct Chars<R> {
20152021
inner: R,
20162022
}
20172023

20182024
/// An enumeration of possible errors that can be generated from the `Chars`
20192025
/// adapter.
2020-
#[derive(Debug)]
20212026
#[unstable(feature = "io", reason = "awaiting stability of Read::chars",
20222027
issue = "27802")]
2028+
#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead:
2029+
https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")]
2030+
#[derive(Debug)]
2031+
#[allow(deprecated)]
20232032
pub enum CharsError {
20242033
/// Variant representing that the underlying stream was read successfully
20252034
/// but it did not contain valid utf8 data.
@@ -2031,6 +2040,7 @@ pub enum CharsError {
20312040

20322041
#[unstable(feature = "io", reason = "awaiting stability of Read::chars",
20332042
issue = "27802")]
2043+
#[allow(deprecated)]
20342044
impl<R: Read> Iterator for Chars<R> {
20352045
type Item = result::Result<char, CharsError>;
20362046

@@ -2063,6 +2073,7 @@ impl<R: Read> Iterator for Chars<R> {
20632073

20642074
#[unstable(feature = "io", reason = "awaiting stability of Read::chars",
20652075
issue = "27802")]
2076+
#[allow(deprecated)]
20662077
impl std_error::Error for CharsError {
20672078
fn description(&self) -> &str {
20682079
match *self {
@@ -2080,6 +2091,7 @@ impl std_error::Error for CharsError {
20802091

20812092
#[unstable(feature = "io", reason = "awaiting stability of Read::chars",
20822093
issue = "27802")]
2094+
#[allow(deprecated)]
20832095
impl fmt::Display for CharsError {
20842096
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
20852097
match *self {

0 commit comments

Comments
 (0)