Skip to content

Commit 05baf9b

Browse files
committed
Deprecate str::from_char
Use `String::from_char` or `.to_str` instead [breaking-change]
1 parent 20a6894 commit 05baf9b

File tree

5 files changed

+17
-21
lines changed

5 files changed

+17
-21
lines changed

src/libcollections/str.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ pub fn from_utf8_owned(vv: Vec<u8>) -> Result<String, Vec<u8>> {
125125
/// let string = str::from_byte(104);
126126
/// assert_eq!(string.as_slice(), "h");
127127
/// ```
128+
#[deprecated = "Replaced by String::from_byte"]
128129
pub fn from_byte(b: u8) -> String {
129130
assert!(b < 128u8);
130131
String::from_char(1, b as char)
@@ -139,8 +140,9 @@ pub fn from_byte(b: u8) -> String {
139140
/// let string = str::from_char('b');
140141
/// assert_eq!(string.as_slice(), "b");
141142
/// ```
143+
#[deprecated = "use String::from_char or char.to_string()"]
142144
pub fn from_char(ch: char) -> String {
143-
String::from_char(ch)
145+
String::from_char(1, ch)
144146
}
145147

146148
/// Convert a vector of chars to a string

src/librustc/metadata/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ fn encode_visibility(ebml_w: &mut Encoder, visibility: Visibility) {
619619
Public => 'y',
620620
Inherited => 'i',
621621
};
622-
ebml_w.wr_str(str::from_char(ch).as_slice());
622+
ebml_w.wr_str(ch.to_str().as_slice());
623623
ebml_w.end_tag();
624624
}
625625

src/libstd/ascii.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,6 @@ static ASCII_UPPER_MAP: &'static [u8] = &[
525525
mod tests {
526526
use prelude::*;
527527
use super::*;
528-
use str::from_char;
529528
use char::from_u32;
530529
use vec::Vec;
531530
use str::StrSlice;
@@ -677,8 +676,8 @@ mod tests {
677676
while i <= 500 {
678677
let upper = if 'a' as u32 <= i && i <= 'z' as u32 { i + 'A' as u32 - 'a' as u32 }
679678
else { i };
680-
assert_eq!(from_char(from_u32(i).unwrap()).as_slice().to_ascii_upper(),
681-
from_char(from_u32(upper).unwrap()).to_string())
679+
assert_eq!((from_u32(i).unwrap()).to_str().as_slice().to_ascii_upper(),
680+
(from_u32(upper).unwrap()).to_str())
682681
i += 1;
683682
}
684683
}
@@ -693,8 +692,8 @@ mod tests {
693692
while i <= 500 {
694693
let lower = if 'A' as u32 <= i && i <= 'Z' as u32 { i + 'a' as u32 - 'A' as u32 }
695694
else { i };
696-
assert_eq!(from_char(from_u32(i).unwrap()).as_slice().to_ascii_lower(),
697-
from_char(from_u32(lower).unwrap()).to_string())
695+
assert_eq!((from_u32(i).unwrap()).to_str().as_slice().to_ascii_lower(),
696+
(from_u32(lower).unwrap()).to_str())
698697
i += 1;
699698
}
700699
}
@@ -709,8 +708,8 @@ mod tests {
709708
while i <= 500 {
710709
let upper = if 'a' as u32 <= i && i <= 'z' as u32 { i + 'A' as u32 - 'a' as u32 }
711710
else { i };
712-
assert_eq!(from_char(from_u32(i).unwrap()).to_string().into_ascii_upper(),
713-
from_char(from_u32(upper).unwrap()).to_string())
711+
assert_eq!((from_u32(i).unwrap()).to_str().into_ascii_upper(),
712+
(from_u32(upper).unwrap()).to_str())
714713
i += 1;
715714
}
716715
}
@@ -726,8 +725,8 @@ mod tests {
726725
while i <= 500 {
727726
let lower = if 'A' as u32 <= i && i <= 'Z' as u32 { i + 'a' as u32 - 'A' as u32 }
728727
else { i };
729-
assert_eq!(from_char(from_u32(i).unwrap()).to_string().into_ascii_lower(),
730-
from_char(from_u32(lower).unwrap()).to_string())
728+
assert_eq!((from_u32(i).unwrap()).to_str().into_ascii_lower(),
729+
(from_u32(lower).unwrap()).to_str())
731730
i += 1;
732731
}
733732
}
@@ -747,11 +746,8 @@ mod tests {
747746
let c = i;
748747
let lower = if 'A' as u32 <= c && c <= 'Z' as u32 { c + 'a' as u32 - 'A' as u32 }
749748
else { c };
750-
assert!(from_char(from_u32(i).unwrap()).as_slice()
751-
.eq_ignore_ascii_case(
752-
from_char(
753-
from_u32(lower)
754-
.unwrap()).as_slice()));
749+
assert!((from_u32(i).unwrap()).to_str().as_slice().eq_ignore_ascii_case(
750+
(from_u32(lower).unwrap()).to_str().as_slice()));
755751
i += 1;
756752
}
757753
}

src/libterm/terminfo/searcher.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub fn get_dbpath_for_term(term: &str) -> Option<Box<Path>> {
5959
// Look for the terminal in all of the search directories
6060
for p in dirs_to_search.iter() {
6161
if p.exists() {
62-
let f = str::from_char(first_char);
62+
let f = first_char.to_str();
6363
let newp = p.join_many([f.as_slice(), term]);
6464
if newp.exists() {
6565
return Some(box newp);

src/libtime/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,9 +486,7 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, String> {
486486
if c == range.ch {
487487
Ok(range.next)
488488
} else {
489-
Err(format!("Expected {}, found {}",
490-
str::from_char(c),
491-
str::from_char(range.ch)))
489+
Err(format!("Expected {}, found {}", c, range.ch))
492490
}
493491
}
494492

@@ -789,7 +787,7 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, String> {
789787
}
790788
'%' => parse_char(s, pos, '%'),
791789
ch => {
792-
Err(format!("unknown formatting type: {}", str::from_char(ch)))
790+
Err(format!("unknown formatting type: {}", ch))
793791
}
794792
}
795793
}

0 commit comments

Comments
 (0)