Skip to content

[WIP] str is dead, long live str([u8])! #19612

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 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
681bbd3
librustc: add "str" lang item
Dec 4, 2014
f63b8e4
librustc: use "str" lang item in `mk_str`/`mk_str_slice`
Dec 5, 2014
5c73c5d
librustc[_trans]: fix fallout of changing `mk_str_slice` signature
Dec 5, 2014
c977921
librustc: add `is_str` utility function
Dec 5, 2014
c00d178
librustc: kill `ty_str`
Dec 5, 2014
b00cc6b
librustc_trans: kill `ty_str`
Dec 5, 2014
b4b2551
libsyntax: kill `TyStr`
Dec 5, 2014
10b2f55
librustc: kill `TyStr`
Dec 5, 2014
a55ae0e
libsyntax: use the full path of `str` in `format_args!`
Dec 5, 2014
2727aa1
libcore: use full path of `str` in `panic!` macro
Dec 5, 2014
52cae4c
libcore: make `str` a library type
Dec 5, 2014
6e5f5d9
libunicode: fix fallout
Dec 5, 2014
8608ac7
librand: fix fallout
Dec 5, 2014
8ad9238
libcollections: fix fallout
Dec 5, 2014
be8c54c
librustrt: fix fallout
Dec 5, 2014
31a3b28
libstd: use full path of `str` in `panic!` macro
Dec 5, 2014
e373977
libstd: fix fallout
Dec 5, 2014
005cdb7
libfmt_macros: fix fallout
Dec 5, 2014
54c55cf
libserialize: fix fallout
Dec 5, 2014
7f6b844
librbml: fix fallout
Dec 5, 2014
adab4be
libsyntax: fix fallout
Dec 5, 2014
bd7ccae
librustc_back: fix fallout
Dec 6, 2014
1174f1c
librustc: fix fallout
Dec 6, 2014
d3d5374
librustc_trans: fix fallout
Dec 6, 2014
99fb6c1
librustdoc: kill `ty_str` and `TyStr`
Dec 6, 2014
d11d28d
librustdoc: fix fallout
Dec 6, 2014
ca8649f
compiletest: fix fallout
Dec 6, 2014
c73df95
Fix run-pass tests
Dec 6, 2014
fd0a965
FIXME I broke run-pass/unsized3
Dec 6, 2014
c373b72
Fix compile-fail tests
Dec 6, 2014
ce37ad9
libstd: fix unit tests
Dec 6, 2014
47fb373
libcollections: fix unit tests
Dec 6, 2014
d49859f
libgraphviz: fix unit tests
Dec 6, 2014
702031c
libsyntax: fix unit tests
Dec 6, 2014
de8d4a4
libserialize: fix doc tests
Dec 6, 2014
f53120d
Fix bench
Dec 6, 2014
7620208
Fix guides
Dec 6, 2014
80ca6e5
Fix pretty test
Dec 6, 2014
cebddbb
libstd: fix fallout
Dec 6, 2014
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
6 changes: 3 additions & 3 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use std::io::process;
use std::io::timer;
use std::io;
use std::os;
use std::str;
use std::str as str_;
use std::string::String;
use std::task;
use std::time::Duration;
Expand Down Expand Up @@ -426,7 +426,7 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
gdbserver :5039 {}/{}",
config.adb_test_dir.clone(),
config.adb_test_dir.clone(),
str::from_utf8(
str_::from_utf8(
exe_file.filename()
.unwrap()).unwrap());

Expand Down Expand Up @@ -1731,7 +1731,7 @@ fn disassemble_extract(config: &Config, _props: &TestProps,

fn count_extracted_lines(p: &Path) -> uint {
let x = File::open(&p.with_extension("ll")).read_to_end().unwrap();
let x = str::from_utf8(x.as_slice()).unwrap();
let x = str_::from_utf8(x.as_slice()).unwrap();
x.lines().count()
}

Expand Down
4 changes: 2 additions & 2 deletions src/doc/guide-strings.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ fn main() {
You can also get a `&str` from a stack-allocated array of bytes:

```{rust}
use std::str;
use std::str as str_;

let x: &[u8] = &[b'a', b'b'];
let stack_str: &str = str::from_utf8(x).unwrap();
let stack_str: &str = str_::from_utf8(x).unwrap();
```

# Best Practices
Expand Down
2 changes: 1 addition & 1 deletion src/doc/guide-unsafe.md
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ pub extern fn dot_product(a: *const u32, a_len: u32,

#[lang = "panic_fmt"]
extern fn panic_fmt(args: &core::fmt::Arguments,
file: &str,
file: &core::str::str,
line: uint) -> ! {
loop {}
}
Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2028,8 +2028,8 @@ mod tests {
#[test]
fn test_from_bytes() {
let bitv = from_bytes(&[0b10110110, 0b00000000, 0b11111111]);
let str = format!("{}{}{}", "10110110", "00000000", "11111111");
assert_eq!(bitv.to_string().as_slice(), str.as_slice());
let s = format!("{}{}{}", "10110110", "00000000", "11111111");
assert_eq!(bitv.to_string().as_slice(), s.as_slice());
}

#[test]
Expand Down
3 changes: 3 additions & 0 deletions src/libcollections/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ use core::borrow::{Cow, ToOwned};
use core::intrinsics::TypeId;
use core::mem;
use core::num::Int;
#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
use core::str::str;

use vec::Vec;

Expand Down Expand Up @@ -326,6 +328,7 @@ mod tests {
#[test]
fn test_writer_hasher() {
use alloc::boxed::Box;
use core::str::str;

let hasher = MyWriterHasher;

Expand Down
2 changes: 2 additions & 0 deletions src/libcollections/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,6 @@ mod std {
pub use core::clone; // deriving(Clone)
pub use core::cmp; // deriving(Eq, Ord, etc.)
pub use hash; // deriving(Hash)
#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
pub use core::str;
}
8 changes: 7 additions & 1 deletion src/libcollections/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ pub use core::str::{eq_slice, is_utf8, is_utf16, Utf16Items};
pub use core::str::{Utf16Item, ScalarValue, LoneSurrogate, utf16_items};
pub use core::str::{truncate_utf16_at_nul, utf8_char_width, CharRange};
pub use core::str::{FromStr, from_str};
pub use core::str::{Str, StrPrelude};
pub use core::str::Str;
// NOTE(stage0): Remove import after a snapshot
#[cfg(stage0)]
pub use core::str::StrPrelude;
#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
pub use core::str::str;
pub use core::str::{from_utf8_unchecked, from_c_str};
pub use unicode::str::{UnicodeStrPrelude, Words, Graphemes, GraphemeIndices};

Expand Down Expand Up @@ -2331,6 +2336,7 @@ mod bench {
use test::black_box;
use super::*;
use std::iter::{IteratorExt, DoubleEndedIteratorExt};
#[cfg(stage0)] // NOTE(stage0): Remove import after a snapshot
use std::str::StrPrelude;
use std::slice::SlicePrelude;

Expand Down
35 changes: 21 additions & 14 deletions src/libcollections/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

use core::prelude::*;

#[cfg(stage0)] // NOTE(stage0): Remove import after a snapshot
use core::str::StrPrelude;

use core::borrow::{Cow, IntoCow};
use core::default::Default;
use core::fmt;
Expand All @@ -22,11 +25,13 @@ use core::ptr;
use core::ops;
// FIXME: ICE's abound if you import the `Slice` type while importing `Slice` trait
use core::raw::Slice as RawSlice;
#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
use core::str::str;

use hash;
use slice::CloneSliceAllocPrelude;
use str;
use str::{CharRange, CowString, FromStr, StrAllocating, Owned};
use str as str_;
use vec::{DerefVec, Vec, as_vec};

/// A growable string stored as a UTF-8 encoded buffer.
Expand Down Expand Up @@ -103,7 +108,7 @@ impl String {
#[inline]
#[unstable = "error type may change"]
pub fn from_utf8(vec: Vec<u8>) -> Result<String, Vec<u8>> {
if str::is_utf8(vec.as_slice()) {
if str_::is_utf8(vec.as_slice()) {
Ok(String { vec: vec })
} else {
Err(vec)
Expand All @@ -122,7 +127,7 @@ impl String {
/// ```
#[unstable = "return type may change"]
pub fn from_utf8_lossy<'a>(v: &'a [u8]) -> CowString<'a> {
if str::is_utf8(v) {
if str_::is_utf8(v) {
return Cow::Borrowed(unsafe { mem::transmute(v) })
}

Expand Down Expand Up @@ -172,7 +177,7 @@ impl String {
if byte < 128u8 {
// subseqidx handles this
} else {
let w = str::utf8_char_width(byte);
let w = str_::utf8_char_width(byte);

match w {
2 => {
Expand Down Expand Up @@ -255,10 +260,10 @@ impl String {
#[unstable = "error value in return may change"]
pub fn from_utf16(v: &[u16]) -> Option<String> {
let mut s = String::with_capacity(v.len());
for c in str::utf16_items(v) {
for c in str_::utf16_items(v) {
match c {
str::ScalarValue(c) => s.push(c),
str::LoneSurrogate(_) => return None
str_::ScalarValue(c) => s.push(c),
str_::LoneSurrogate(_) => return None
}
}
Some(s)
Expand All @@ -279,7 +284,7 @@ impl String {
/// ```
#[stable]
pub fn from_utf16_lossy(v: &[u16]) -> String {
str::utf16_items(v).map(|c| c.to_char_lossy()).collect()
str_::utf16_items(v).map(|c| c.to_char_lossy()).collect()
}

/// Convert a vector of `char`s to a `String`.
Expand Down Expand Up @@ -317,7 +322,7 @@ impl String {
/// slice is not checked to see whether it contains valid UTF-8
#[unstable = "just renamed from `mod raw`"]
pub unsafe fn from_raw_buf(buf: *const u8) -> String {
String::from_str(str::from_c_str(buf as *const i8))
String::from_str(str_::from_c_str(buf as *const i8))
}

/// Creates a `String` from a `*const u8` buffer of the given length.
Expand Down Expand Up @@ -978,8 +983,10 @@ mod tests {
use test::Bencher;

use slice::CloneSliceAllocPrelude;
use str::{Str, StrPrelude};
use str;
use str::Str;
#[cfg(stage0)] // NOTE(stage0): Remove import after a snapshot
use str::StrPrelude;
use str as str_;
use super::{as_string, String, ToString};
use vec::Vec;

Expand Down Expand Up @@ -1011,11 +1018,11 @@ mod tests {
#[test]
fn test_from_utf8_lossy() {
let xs = b"hello";
let ys: str::CowString = "hello".into_cow();
let ys: str_::CowString = "hello".into_cow();
assert_eq!(String::from_utf8_lossy(xs), ys);

let xs = "ศไทย中华Việt Nam".as_bytes();
let ys: str::CowString = "ศไทย中华Việt Nam".into_cow();
let ys: str_::CowString = "ศไทย中华Việt Nam".into_cow();
assert_eq!(String::from_utf8_lossy(xs), ys);

let xs = b"Hello\xC2 There\xFF Goodbye";
Expand Down Expand Up @@ -1095,7 +1102,7 @@ mod tests {
let s_as_utf16 = s.as_slice().utf16_units().collect::<Vec<u16>>();
let u_as_string = String::from_utf16(u.as_slice()).unwrap();

assert!(str::is_utf16(u.as_slice()));
assert!(str_::is_utf16(u.as_slice()));
assert_eq!(s_as_utf16, u);

assert_eq!(u_as_string, s);
Expand Down
1 change: 1 addition & 0 deletions src/libcore/fmt/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use num::{Float, FPNaN, FPInfinite, ToPrimitive};
use num::cast;
use result::Ok;
use slice::{mod, SlicePrelude};
#[cfg(stage0)] // NOTE(stage0): Remove import after a snapshot
use str::StrPrelude;

/// A flag that specifies whether to use exponential (scientific) notation.
Expand Down
3 changes: 3 additions & 0 deletions src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ use result::{Ok, Err};
use result;
use slice::SlicePrelude;
use slice;
#[cfg(stage0)] // NOTE(stage0): Remove import after a snapshot
use str::StrPrelude;
#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
use str::str;

pub use self::num::radix;
pub use self::num::Radix;
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/fmt/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ use fmt;
use iter::DoubleEndedIteratorExt;
use num::{Int, cast};
use slice::SlicePrelude;
#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
use str::str;

/// A type that represents a specific radix
#[doc(hidden)]
Expand Down
3 changes: 3 additions & 0 deletions src/libcore/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
#![experimental]
#![allow(missing_docs)]

#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
use str::str;

pub type GlueFn = extern "Rust" fn(*const i8);

#[lang="ty_desc"]
Expand Down
1 change: 1 addition & 0 deletions src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,5 @@ mod std {
pub use kinds;
pub use option;
pub use fmt;
pub use str;
}
40 changes: 40 additions & 0 deletions src/libcore/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#![macro_escape]

// NOTE(stage0): Remove macro after a snapshot
#[cfg(stage0)]
/// Entry point of task panic, for details, see std::macros
#[macro_export]
macro_rules! panic(
Expand Down Expand Up @@ -46,6 +48,44 @@ macro_rules! panic(
});
)

#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
/// Entry point of task panic, for details, see std::macros
#[macro_export]
macro_rules! panic(
() => (
panic!("{}", "explicit panic")
);
($msg:expr) => ({
static _MSG_FILE_LINE: (&'static ::std::str::str, &'static ::std::str::str, uint) =
($msg, file!(), line!());
::core::panicking::panic(&_MSG_FILE_LINE)
});
($fmt:expr, $($arg:tt)*) => ({
// a closure can't have return type !, so we need a full
// function to pass to format_args!, *and* we need the
// file and line numbers right here; so an inner bare fn
// is our only choice.
//
// LLVM doesn't tend to inline this, presumably because begin_unwind_fmt
// is #[cold] and #[inline(never)] and because this is flagged as cold
// as returning !. We really do want this to be inlined, however,
// because it's just a tiny wrapper. Small wins (156K to 149K in size)
// were seen when forcing this to be inlined, and that number just goes
// up with the number of calls to panic!()
//
// The leading _'s are to avoid dead code warnings if this is
// used inside a dead function. Just `#[allow(dead_code)]` is
// insufficient, since the user may have
// `#[forbid(dead_code)]` and which cannot be overridden.
#[inline(always)]
fn _run_fmt(fmt: &::std::fmt::Arguments) -> ! {
static _FILE_LINE: (&'static ::std::str::str, uint) = (file!(), line!());
::core::panicking::panic_fmt(fmt, &_FILE_LINE)
}
format_args!(_run_fmt, $fmt, $($arg)*)
});
)

/// Runtime assertion, for details see std::macros
#[macro_export]
macro_rules! assert(
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use mem;
use num::{Float, FPNormal, FPCategory, FPZero, FPSubnormal, FPInfinite, FPNaN};
use num::from_str_radix;
use option::Option;
#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
use str::str;

#[stable]
pub const RADIX: uint = 2u;
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use mem;
use num::{Float, FPNormal, FPCategory, FPZero, FPSubnormal, FPInfinite, FPNaN};
use num::from_str_radix;
use option::Option;
#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
use str::str;

// FIXME(#5527): These constants should be deprecated once associated
// constants are implemented in favour of referencing the respective
Expand Down
10 changes: 7 additions & 3 deletions src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ use mem::size_of;
use ops::{Add, Sub, Mul, Div, Rem, Neg};
use ops::{Not, BitAnd, BitOr, BitXor, Shl, Shr};
use option::{Option, Some, None};
use str::{FromStr, from_str, StrPrelude};
use str::{FromStr, from_str};
#[cfg(stage0)] // NOTE(stage0): Remove import after a snapshot
use str::StrPrelude;
#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
use str::str;

/// Simultaneous division and remainder
#[inline]
Expand Down Expand Up @@ -1437,8 +1441,8 @@ pub trait FromStrRadix {

/// A utility function that just calls FromStrRadix::from_str_radix.
#[experimental = "might need to return Result"]
pub fn from_str_radix<T: FromStrRadix>(str: &str, radix: uint) -> Option<T> {
FromStrRadix::from_str_radix(str, radix)
pub fn from_str_radix<T: FromStrRadix>(s: &str, radix: uint) -> Option<T> {
FromStrRadix::from_str_radix(s, radix)
}

macro_rules! from_str_radix_float_impl {
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ use slice;
use slice::AsSlice;
use clone::Clone;
use ops::Deref;
#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
use str::str;

// Note that this is not a lang item per se, but it has a hidden dependency on
// `Iterator`, which is one. The compiler assumes that the `next` method of
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

use fmt;
use intrinsics;
#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
use str::str;

#[cold] #[inline(never)] // this is the slow path, always
#[lang="panic"]
Expand Down
4 changes: 3 additions & 1 deletion src/libcore/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ pub use option::Option::{Some, None};
pub use ptr::RawPtr;
pub use result::Result;
pub use result::Result::{Ok, Err};
pub use str::{Str, StrPrelude};
pub use str::Str;
#[cfg(stage0)] // NOTE(stage0): Remove import after a snapshot
pub use str::StrPrelude;
pub use tuple::{Tuple1, Tuple2, Tuple3, Tuple4};
pub use tuple::{Tuple5, Tuple6, Tuple7, Tuple8};
pub use tuple::{Tuple9, Tuple10, Tuple11, Tuple12};
Expand Down
Loading