Skip to content

librustc: Remove all uses of ~str from the language and libraries. #14310

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 6 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
12 changes: 8 additions & 4 deletions src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub fn parse_config(args: Vec<StrBuf> ) -> Config {
let args_ = args.tail();
if args.get(1).as_slice() == "-h" || args.get(1).as_slice() == "--help" {
let message = format!("Usage: {} [OPTIONS] [TESTNAME...]", argv0);
println!("{}", getopts::usage(message, groups.as_slice()));
println!("{}", getopts::usage(message.as_slice(), groups.as_slice()));
println!("");
fail!()
}
Expand All @@ -109,7 +109,7 @@ pub fn parse_config(args: Vec<StrBuf> ) -> Config {

if matches.opt_present("h") || matches.opt_present("help") {
let message = format!("Usage: {} [OPTIONS] [TESTNAME...]", argv0);
println!("{}", getopts::usage(message, groups.as_slice()));
println!("{}", getopts::usage(message.as_slice(), groups.as_slice()));
println!("");
fail!()
}
Expand Down Expand Up @@ -323,11 +323,15 @@ pub fn is_test(config: &Config, testfile: &Path) -> bool {
let mut valid = false;

for ext in valid_extensions.iter() {
if name.ends_with(*ext) { valid = true; }
if name.ends_with(ext.as_slice()) {
valid = true;
}
}

for pre in invalid_prefixes.iter() {
if name.starts_with(*pre) { valid = false; }
if name.starts_with(pre.as_slice()) {
valid = false;
}
}

return valid;
Expand Down
2 changes: 1 addition & 1 deletion src/compiletest/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn load_errors(re: &Regex, testfile: &Path) -> Vec<ExpectedError> {
let mut rdr = BufferedReader::new(File::open(testfile).unwrap());

rdr.lines().enumerate().filter_map(|(line_no, ln)| {
parse_expected(line_no + 1, ln.unwrap(), re)
parse_expected(line_no + 1, ln.unwrap().as_slice(), re)
}).collect()
}

Expand Down
9 changes: 7 additions & 2 deletions src/compiletest/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,14 @@ fn iter_header(testfile: &Path, it: |&str| -> bool) -> bool {
// module or function. This doesn't seem to be an optimization
// with a warm page cache. Maybe with a cold one.
let ln = ln.unwrap();
if ln.starts_with("fn") || ln.starts_with("mod") {
if ln.as_slice().starts_with("fn") ||
ln.as_slice().starts_with("mod") {
return true;
} else { if !(it(ln.trim())) { return false; } }
} else {
if !(it(ln.as_slice().trim())) {
return false;
}
}
}
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion src/compiletest/procsrv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use std::unstable::dynamic_lib::DynamicLibrary;

fn target_env(lib_path: &str, prog: &str) -> Vec<(StrBuf, StrBuf)> {
let prog = if cfg!(windows) {prog.slice_to(prog.len() - 4)} else {prog};
let aux_path = prog + ".libaux";
let mut aux_path = prog.to_strbuf();
aux_path.push_str(".libaux");

// Need to be sure to put both the lib_path and the aux path in the dylib
// search path for the child.
Expand Down
28 changes: 19 additions & 9 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,10 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
cmds,
"quit".to_strbuf()].connect("\n");
debug!("script_str = {}", script_str);
dump_output_file(config, testfile, script_str, "debugger.script");
dump_output_file(config,
testfile,
script_str.as_slice(),
"debugger.script");


procsrv::run("",
Expand Down Expand Up @@ -459,7 +462,10 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
"quit\n".to_strbuf()
].connect("\n");
debug!("script_str = {}", script_str);
dump_output_file(config, testfile, script_str, "debugger.script");
dump_output_file(config,
testfile,
script_str.as_slice(),
"debugger.script");

// run debugger script with gdb
#[cfg(windows)]
Expand Down Expand Up @@ -538,7 +544,8 @@ fn run_debuginfo_lldb_test(config: &Config, props: &TestProps, testfile: &Path)

// Set breakpoints on every line that contains the string "#break"
for line in breakpoint_lines.iter() {
script_str.push_str(format!("breakpoint set --line {}\n", line));
script_str.push_str(format!("breakpoint set --line {}\n",
line).as_slice());
}

// Append the other commands
Expand All @@ -552,7 +559,10 @@ fn run_debuginfo_lldb_test(config: &Config, props: &TestProps, testfile: &Path)

// Write the script into a file
debug!("script_str = {}", script_str);
dump_output_file(config, testfile, script_str.into_owned(), "debugger.script");
dump_output_file(config,
testfile,
script_str.as_slice(),
"debugger.script");
let debugger_script = make_out_name(config, testfile, "debugger.script");

// Let LLDB execute the script via lldb_batchmode.py
Expand Down Expand Up @@ -609,8 +619,8 @@ fn parse_debugger_commands(file_path: &Path, debugger_prefix: &str)
-> DebuggerCommands {
use std::io::{BufferedReader, File};

let command_directive = debugger_prefix + "-command";
let check_directive = debugger_prefix + "-check";
let command_directive = format!("{}-command", debugger_prefix);
let check_directive = format!("{}-check", debugger_prefix);

let mut breakpoint_lines = vec!();
let mut commands = vec!();
Expand All @@ -620,18 +630,18 @@ fn parse_debugger_commands(file_path: &Path, debugger_prefix: &str)
for line in reader.lines() {
match line {
Ok(line) => {
if line.contains("#break") {
if line.as_slice().contains("#break") {
breakpoint_lines.push(counter);
}

header::parse_name_value_directive(
line,
line.as_slice(),
command_directive.to_strbuf()).map(|cmd| {
commands.push(cmd)
});

header::parse_name_value_directive(
line,
line.as_slice(),
check_directive.to_strbuf()).map(|cmd| {
check_lines.push(cmd)
});
Expand Down
4 changes: 2 additions & 2 deletions src/doc/complement-cheatsheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ To return an Owned String (StrBuf) use the str helper function [`from_utf8_owned
~~~
use std::str;

let x: Result<StrBuf,~[u8]> =
str::from_utf8_owned(~[104u8,105u8]).map(|x| x.to_strbuf());
let x: Option<StrBuf> =
str::from_utf8([ 104u8, 105u8 ]).map(|x| x.to_strbuf());
let y: StrBuf = x.unwrap();
~~~

Expand Down
12 changes: 6 additions & 6 deletions src/liballoc/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,18 @@ pub fn stats_print() {
}
}

// The compiler never calls `exchange_free` on ~ZeroSizeType, so zero-size
// allocations can point to this `static`. It would be incorrect to use a null
// pointer, due to enums assuming types like unique pointers are never null.
pub static mut EMPTY: uint = 12345;

/// The allocator for unique pointers.
#[cfg(not(test))]
#[lang="exchange_malloc"]
#[inline]
unsafe fn exchange_malloc(size: uint, align: uint) -> *mut u8 {
// The compiler never calls `exchange_free` on ~ZeroSizeType, so zero-size
// allocations can point to this `static`. It would be incorrect to use a null
// pointer, due to enums assuming types like unique pointers are never null.
static EMPTY: () = ();

if size == 0 {
&EMPTY as *() as *mut u8
&EMPTY as *uint as *mut u8
} else {
allocate(size, align)
}
Expand Down
17 changes: 17 additions & 0 deletions src/liballoc/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,20 @@ fn align_to(size: uint, align: uint) -> uint {
assert!(align != 0);
(size + align - 1) & !(align - 1)
}

// FIXME(#14344): When linking liballoc with libstd, this library will be linked
// as an rlib (it only exists as an rlib). It turns out that an
// optimized standard library doesn't actually use *any* symbols
// from this library. Everything is inlined and optimized away.
// This means that linkers will actually omit the object for this
// file, even though it may be needed in the future.
//
// To get around this for now, we define a dummy symbol which
// will never get inlined so the stdlib can call it. The stdlib's
// reference to this symbol will cause this library's object file
// to get linked in to libstd successfully (the linker won't
// optimize it out).
#[deprecated]
#[doc(hidden)]
pub fn make_stdlib_link_work() {}

6 changes: 3 additions & 3 deletions src/libcollections/bitv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ impl Bitv {
* The resulting string has the same length as `self`, and each
* character is either '0' or '1'.
*/
pub fn to_str(&self) -> ~str {
pub fn to_str(&self) -> StrBuf {
let mut rs = StrBuf::new();
for i in self.iter() {
if i {
Expand All @@ -547,7 +547,7 @@ impl Bitv {
rs.push_char('0');
}
};
rs.into_owned()
rs
}


Expand Down Expand Up @@ -1330,7 +1330,7 @@ mod tests {
#[test]
fn test_from_bytes() {
let bitv = from_bytes([0b10110110, 0b00000000, 0b11111111]);
let str = "10110110".to_owned() + "00000000" + "11111111";
let str = format!("{}{}{}", "10110110", "00000000", "11111111");
assert_eq!(bitv.to_str(), str);
}

Expand Down
14 changes: 9 additions & 5 deletions src/libcore/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ mod tests {
use prelude::*;
use super::*;
use realstd::owned::{Box, AnyOwnExt};
use realstd::str::StrAllocating;
use realstd::str::{Str, StrAllocating};

#[deriving(Eq, Show)]
struct Test;
Expand Down Expand Up @@ -249,13 +249,17 @@ mod tests {
use realstd::to_str::ToStr;
let a = box 8u as Box<::realstd::any::Any>;
let b = box Test as Box<::realstd::any::Any>;
assert_eq!(a.to_str(), "Box<Any>".to_owned());
assert_eq!(b.to_str(), "Box<Any>".to_owned());
let a_str = a.to_str();
let b_str = b.to_str();
assert_eq!(a_str.as_slice(), "Box<Any>");
assert_eq!(b_str.as_slice(), "Box<Any>");

let a = &8u as &Any;
let b = &Test as &Any;
assert_eq!(format!("{}", a), "&Any".to_owned());
assert_eq!(format!("{}", b), "&Any".to_owned());
let s = format!("{}", a);
assert_eq!(s.as_slice(), "&Any");
let s = format!("{}", b);
assert_eq!(s.as_slice(), "&Any");
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/libcore/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,10 @@ mod tests {

#[test]
fn test_to_str() {
assert_eq!(false.to_str(), "false".to_owned());
assert_eq!(true.to_str(), "true".to_owned());
let s = false.to_str();
assert_eq!(s.as_slice(), "false");
let s = true.to_str();
assert_eq!(s.as_slice(), "true");
}

#[test]
Expand Down
5 changes: 3 additions & 2 deletions src/libcore/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,12 +404,13 @@ mod test {
#[test]
fn cell_has_sensible_show() {
use str::StrSlice;
use realstd::str::Str;

let x = Cell::new("foo bar");
assert!(format!("{}", x).contains(x.get()));
assert!(format!("{}", x).as_slice().contains(x.get()));

x.set("baz qux");
assert!(format!("{}", x).contains(x.get()));
assert!(format!("{}", x).as_slice().contains(x.get()));
}

#[test]
Expand Down
69 changes: 44 additions & 25 deletions src/libcore/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ mod test {
use slice::ImmutableVector;
use option::{Some, None};
use realstd::strbuf::StrBuf;
use realstd::str::StrAllocating;
use realstd::str::{Str, StrAllocating};

#[test]
fn test_is_lowercase() {
Expand Down Expand Up @@ -742,46 +742,65 @@ mod test {

#[test]
fn test_escape_default() {
fn string(c: char) -> ~str {
fn string(c: char) -> StrBuf {
let mut result = StrBuf::new();
escape_default(c, |c| { result.push_char(c); });
return result.into_owned();
return result;
}
assert_eq!(string('\n'), "\\n".to_owned());
assert_eq!(string('\r'), "\\r".to_owned());
assert_eq!(string('\''), "\\'".to_owned());
assert_eq!(string('"'), "\\\"".to_owned());
assert_eq!(string(' '), " ".to_owned());
assert_eq!(string('a'), "a".to_owned());
assert_eq!(string('~'), "~".to_owned());
assert_eq!(string('\x00'), "\\x00".to_owned());
assert_eq!(string('\x1f'), "\\x1f".to_owned());
assert_eq!(string('\x7f'), "\\x7f".to_owned());
assert_eq!(string('\xff'), "\\xff".to_owned());
assert_eq!(string('\u011b'), "\\u011b".to_owned());
assert_eq!(string('\U0001d4b6'), "\\U0001d4b6".to_owned());
let s = string('\n');
assert_eq!(s.as_slice(), "\\n");
let s = string('\r');
assert_eq!(s.as_slice(), "\\r");
let s = string('\'');
assert_eq!(s.as_slice(), "\\'");
let s = string('"');
assert_eq!(s.as_slice(), "\\\"");
let s = string(' ');
assert_eq!(s.as_slice(), " ");
let s = string('a');
assert_eq!(s.as_slice(), "a");
let s = string('~');
assert_eq!(s.as_slice(), "~");
let s = string('\x00');
assert_eq!(s.as_slice(), "\\x00");
let s = string('\x1f');
assert_eq!(s.as_slice(), "\\x1f");
let s = string('\x7f');
assert_eq!(s.as_slice(), "\\x7f");
let s = string('\xff');
assert_eq!(s.as_slice(), "\\xff");
let s = string('\u011b');
assert_eq!(s.as_slice(), "\\u011b");
let s = string('\U0001d4b6');
assert_eq!(s.as_slice(), "\\U0001d4b6");
}

#[test]
fn test_escape_unicode() {
fn string(c: char) -> ~str {
fn string(c: char) -> StrBuf {
let mut result = StrBuf::new();
escape_unicode(c, |c| { result.push_char(c); });
return result.into_owned();
return result;
}
assert_eq!(string('\x00'), "\\x00".to_owned());
assert_eq!(string('\n'), "\\x0a".to_owned());
assert_eq!(string(' '), "\\x20".to_owned());
assert_eq!(string('a'), "\\x61".to_owned());
assert_eq!(string('\u011b'), "\\u011b".to_owned());
assert_eq!(string('\U0001d4b6'), "\\U0001d4b6".to_owned());
let s = string('\x00');
assert_eq!(s.as_slice(), "\\x00");
let s = string('\n');
assert_eq!(s.as_slice(), "\\x0a");
let s = string(' ');
assert_eq!(s.as_slice(), "\\x20");
let s = string('a');
assert_eq!(s.as_slice(), "\\x61");
let s = string('\u011b');
assert_eq!(s.as_slice(), "\\u011b");
let s = string('\U0001d4b6');
assert_eq!(s.as_slice(), "\\U0001d4b6");
}

#[test]
fn test_to_str() {
use realstd::to_str::ToStr;
let s = 't'.to_str();
assert_eq!(s, "t".to_owned());
assert_eq!(s.as_slice(), "t");
}

#[test]
Expand Down
Loading