test: Remove all uses of `~str` from the test suite.

This commit is contained in:
Patrick Walton 2014-05-12 17:56:43 -07:00
parent 2a7a39191a
commit 95e310abdc
189 changed files with 842 additions and 771 deletions

View File

@ -13,7 +13,7 @@ pub mod kitties {
meows : uint,
pub how_hungry : int,
pub name : ~str,
pub name : StrBuf,
}
impl cat {
@ -41,7 +41,7 @@ pub mod kitties {
}
}
pub fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
pub fn cat(in_x : uint, in_y : int, in_name: StrBuf) -> cat {
cat {
meows: in_x,
how_hungry: in_y,

View File

@ -14,7 +14,7 @@ pub mod kitty {
pub struct cat {
meows : uint,
pub how_hungry : int,
pub name : ~str,
pub name : StrBuf,
}
impl fmt::Show for cat {
@ -50,7 +50,7 @@ pub mod kitty {
}
}
pub fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
pub fn cat(in_x : uint, in_y : int, in_name: StrBuf) -> cat {
cat {
meows: in_x,
how_hungry: in_y,

View File

@ -17,11 +17,11 @@ pub mod name_pool {
pub type name_pool = ();
pub trait add {
fn add(&self, s: ~str);
fn add(&self, s: StrBuf);
}
impl add for name_pool {
fn add(&self, _s: ~str) {
fn add(&self, _s: StrBuf) {
}
}
}

View File

@ -12,10 +12,10 @@
#![crate_type = "lib"]
pub struct NameVal { pub name: ~str, pub val: int }
pub struct NameVal { pub name: StrBuf, pub val: int }
pub fn struct_nameval() -> NameVal {
NameVal { name: "crateresolve5".to_owned(), val: 10 }
NameVal { name: "crateresolve5".to_strbuf(), val: 10 }
}
pub enum e {

View File

@ -12,9 +12,9 @@
#![crate_type = "lib"]
pub struct NameVal { pub name: ~str, pub val: int }
pub struct NameVal { pub name: StrBuf, pub val: int }
pub fn struct_nameval() -> NameVal {
NameVal { name: "crateresolve5".to_owned(), val: 10 }
NameVal { name: "crateresolve5".to_strbuf(), val: 10 }
}
pub enum e {

View File

@ -14,7 +14,7 @@ pub trait Foo {
}
pub struct Bar {
pub x: ~str
pub x: StrBuf
}
impl Foo for Bar {

View File

@ -17,6 +17,6 @@ trait foo {
fn foo(&self);
}
impl foo for ~str {
impl foo for StrBuf {
fn foo(&self) {}
}

View File

@ -17,9 +17,11 @@ extern crate collections;
use std::cell::RefCell;
use collections::HashMap;
pub type header_map = HashMap<~str, @RefCell<Vec<@~str>>>;
pub type header_map = HashMap<StrBuf, @RefCell<Vec<@StrBuf>>>;
// the unused ty param is necessary so this gets monomorphized
pub fn request<T>(req: &header_map) {
let _x = (**((**req.get(&"METHOD".to_owned())).clone()).borrow().clone().get(0)).clone();
let _x = (**((**req.get(&"METHOD".to_strbuf())).clone()).borrow()
.clone()
.get(0)).clone();
}

View File

@ -48,7 +48,7 @@ pub mod testtypes {
// Tests ty_float (does not test all variants of FloatTy)
pub type FooFloat = f64;
// For ty_str, what kind of string should I use? &'static str? ~str? Raw str?
// For ty_str, what kind of string should I use? &'static str? StrBuf? Raw str?
// Tests ty_enum
pub enum FooEnum {

View File

@ -12,9 +12,9 @@
#![crate_type = "lib"]
trait to_strz {
fn to_strz() -> ~str;
fn to_strz() -> StrBuf;
}
impl to_strz for ~str {
fn to_strz() -> ~str { self.clone() }
impl to_strz for StrBuf {
fn to_strz() -> StrBuf { self.clone() }
}

View File

@ -16,5 +16,5 @@ extern crate a;
use a::to_strz;
impl to_strz for bool {
fn to_strz() -> ~str { fmt!("%b", self) }
fn to_strz() -> StrBuf { fmt!("%b", self) }
}

View File

@ -31,7 +31,7 @@ pub mod sub_foo {
}
pub struct Boz {
unused_str: ~str
unused_str: StrBuf
}
impl Boz {
@ -46,8 +46,8 @@ pub mod sub_foo {
}
impl Bort {
pub fn bort() -> ~str {
"bort()".to_owned()
pub fn bort() -> StrBuf {
"bort()".to_strbuf()
}
}
}

View File

@ -14,17 +14,17 @@
use std::int;
pub trait read {
fn readMaybe(s: ~str) -> Option<Self>;
fn readMaybe(s: StrBuf) -> Option<Self>;
}
impl read for int {
fn readMaybe(s: ~str) -> Option<int> {
from_str::<int>(s)
fn readMaybe(s: StrBuf) -> Option<int> {
from_str::<int>(s.as_slice())
}
}
impl read for bool {
fn readMaybe(s: ~str) -> Option<bool> {
fn readMaybe(s: StrBuf) -> Option<bool> {
match s.as_slice() {
"true" => Some(true),
"false" => Some(false),
@ -33,7 +33,7 @@ impl read for bool {
}
}
pub fn read<T:read>(s: ~str) -> T {
pub fn read<T:read>(s: StrBuf) -> T {
match read::readMaybe(s) {
Some(x) => x,
_ => fail!("read failed!")

View File

@ -80,7 +80,7 @@ impl Results {
}
}
pub fn bench_str<T:MutableSet<~str>,
pub fn bench_str<T:MutableSet<StrBuf>,
R:rand::Rng>(
&mut self,
rng: &mut R,
@ -90,11 +90,11 @@ impl Results {
let mut set = f();
timed(&mut self.sequential_strings, || {
for i in range(0u, num_keys) {
set.insert(i.to_str());
set.insert(i.to_str().to_strbuf());
}
for i in range(0u, num_keys) {
assert!(set.contains(&i.to_str()));
assert!(set.contains(&i.to_str().to_strbuf()));
}
})
}
@ -103,7 +103,7 @@ impl Results {
let mut set = f();
timed(&mut self.random_strings, || {
for _ in range(0, num_keys) {
let s = rng.gen::<uint>().to_str();
let s = rng.gen::<uint>().to_str().to_strbuf();
set.insert(s);
}
})
@ -112,11 +112,11 @@ impl Results {
{
let mut set = f();
for i in range(0u, num_keys) {
set.insert(i.to_str());
set.insert(i.to_str().to_strbuf());
}
timed(&mut self.delete_strings, || {
for i in range(0u, num_keys) {
assert!(set.remove(&i.to_str()));
assert!(set.remove(&i.to_str().to_strbuf()));
}
})
}
@ -175,7 +175,7 @@ fn main() {
s
});
results.bench_str(&mut rng, num_keys, || {
let s: HashSet<~str> = HashSet::new();
let s: HashSet<StrBuf> = HashSet::new();
s
});
write_results("collections::HashSet", &results);
@ -189,7 +189,7 @@ fn main() {
s
});
results.bench_str(&mut rng, num_keys, || {
let s: TreeSet<~str> = TreeSet::new();
let s: TreeSet<StrBuf> = TreeSet::new();
s
});
write_results("collections::TreeSet", &results);

View File

@ -24,11 +24,13 @@ use std::vec;
use std::io::File;
macro_rules! bench (
($argv:expr, $id:ident) => (maybe_run_test($argv.as_slice(), stringify!($id).to_owned(), $id))
($argv:expr, $id:ident) => (maybe_run_test($argv.as_slice(),
stringify!($id).to_strbuf(),
$id))
)
fn main() {
let argv = os::args();
let argv = os::args().move_iter().map(|x| x.to_strbuf()).collect::<Vec<StrBuf>>();
let _tests = argv.slice(1, argv.len());
bench!(argv, shift_push);
@ -40,13 +42,13 @@ fn main() {
bench!(argv, is_utf8_multibyte);
}
fn maybe_run_test(argv: &[~str], name: ~str, test: ||) {
fn maybe_run_test(argv: &[StrBuf], name: StrBuf, test: ||) {
let mut run_test = false;
if os::getenv("RUST_BENCH").is_some() {
run_test = true
} else if argv.len() > 0 {
run_test = argv.iter().any(|x| x == &"all".to_owned()) || argv.iter().any(|x| x == &name)
run_test = argv.iter().any(|x| x == &"all".to_strbuf()) || argv.iter().any(|x| x == &name)
}
if !run_test {

View File

@ -52,12 +52,12 @@ fn server(requests: &Receiver<request>, responses: &Sender<uint>) {
//println!("server exiting");
}
fn run(args: &[~str]) {
fn run(args: &[StrBuf]) {
let (to_parent, from_child) = channel();
let (to_child, from_parent) = channel();
let size = from_str::<uint>(args[1]).unwrap();
let workers = from_str::<uint>(args[2]).unwrap();
let size = from_str::<uint>(args[1].as_slice()).unwrap();
let workers = from_str::<uint>(args[2].as_slice()).unwrap();
let num_bytes = 100;
let start = time::precise_time_s();
let mut worker_results = Vec::new();
@ -97,13 +97,13 @@ fn run(args: &[~str]) {
fn main() {
let args = os::args();
let args = if os::getenv("RUST_BENCH").is_some() {
vec!("".to_owned(), "1000000".to_owned(), "10000".to_owned())
vec!("".to_strbuf(), "1000000".to_strbuf(), "10000".to_strbuf())
} else if args.len() <= 1u {
vec!("".to_owned(), "10000".to_owned(), "4".to_owned())
vec!("".to_strbuf(), "10000".to_strbuf(), "4".to_strbuf())
} else {
args.clone().move_iter().collect()
args.move_iter().map(|x| x.to_strbuf()).collect()
};
println!("{:?}", args);
println!("{}", args);
run(args.as_slice());
}

View File

@ -47,11 +47,11 @@ fn server(requests: &Receiver<request>, responses: &Sender<uint>) {
//println!("server exiting");
}
fn run(args: &[~str]) {
fn run(args: &[StrBuf]) {
let (to_parent, from_child) = channel();
let size = from_str::<uint>(args[1]).unwrap();
let workers = from_str::<uint>(args[2]).unwrap();
let size = from_str::<uint>(args[1].as_slice()).unwrap();
let workers = from_str::<uint>(args[2].as_slice()).unwrap();
let num_bytes = 100;
let start = time::precise_time_s();
let mut worker_results = Vec::new();
@ -107,11 +107,11 @@ fn run(args: &[~str]) {
fn main() {
let args = os::args();
let args = if os::getenv("RUST_BENCH").is_some() {
vec!("".to_owned(), "1000000".to_owned(), "8".to_owned())
vec!("".to_strbuf(), "1000000".to_strbuf(), "8".to_strbuf())
} else if args.len() <= 1u {
vec!("".to_owned(), "10000".to_owned(), "4".to_owned())
vec!("".to_strbuf(), "10000".to_strbuf(), "4".to_strbuf())
} else {
args.clone().move_iter().collect()
args.clone().move_iter().map(|x| x.to_strbuf()).collect()
};
println!("{:?}", args);

View File

@ -74,10 +74,10 @@ fn main() {
let b = bottom_up_tree(&arena, -i, depth);
chk += item_check(a) + item_check(b);
}
format!("{}\t trees of depth {}\t check: {}",
iterations * 2, depth, chk)
format_strbuf!("{}\t trees of depth {}\t check: {}",
iterations * 2, depth, chk)
})
}).collect::<Vec<Future<~str>>>();
}).collect::<Vec<Future<StrBuf>>>();
for message in messages.mut_iter() {
println!("{}", *message.get_ref());

View File

@ -107,7 +107,7 @@ fn creature(
mut color: Color,
from_rendezvous: Receiver<CreatureInfo>,
to_rendezvous: Sender<CreatureInfo>,
to_rendezvous_log: Sender<~str>
to_rendezvous_log: Sender<StrBuf>
) {
let mut creatures_met = 0;
let mut evil_clones_met = 0;
@ -132,7 +132,9 @@ fn creature(
}
}
// log creatures met and evil clones of self
let report = format!("{}{}", creatures_met, Number(evil_clones_met));
let report = format_strbuf!("{}{}",
creatures_met,
Number(evil_clones_met));
to_rendezvous_log.send(report);
}
@ -141,7 +143,7 @@ fn rendezvous(nn: uint, set: Vec<Color>) {
let (to_rendezvous, from_creatures) = channel::<CreatureInfo>();
// these channels will be passed to the creatures so they can talk to us
let (to_rendezvous_log, from_creatures_log) = channel::<~str>();
let (to_rendezvous_log, from_creatures_log) = channel::<StrBuf>();
// these channels will allow us to talk to each creature by 'name'/index
let mut to_creature: Vec<Sender<CreatureInfo>> =

View File

@ -37,7 +37,7 @@ fn f64_cmp(x: f64, y: f64) -> Ordering {
}
// given a map, print a sorted version of it
fn sort_and_fmt(mm: &HashMap<Vec<u8> , uint>, total: uint) -> ~str {
fn sort_and_fmt(mm: &HashMap<Vec<u8> , uint>, total: uint) -> StrBuf {
fn pct(xx: uint, yy: uint) -> f64 {
return (xx as f64) * 100.0 / (yy as f64);
}
@ -67,12 +67,12 @@ fn sort_and_fmt(mm: &HashMap<Vec<u8> , uint>, total: uint) -> ~str {
.into_str(), v));
}
return buffer.into_owned();
return buffer
}
// given a map, search for the frequency of a pattern
fn find(mm: &HashMap<Vec<u8> , uint>, key: ~str) -> uint {
let key = key.into_ascii().as_slice().to_lower().into_str();
fn find(mm: &HashMap<Vec<u8> , uint>, key: StrBuf) -> uint {
let key = key.to_owned().into_ascii().as_slice().to_lower().into_str();
match mm.find_equiv(&key.as_bytes()) {
option::None => { return 0u; }
option::Some(&num) => { return num; }
@ -106,7 +106,7 @@ fn windows_with_carry(bb: &[u8], nn: uint, it: |window: &[u8]|) -> Vec<u8> {
fn make_sequence_processor(sz: uint,
from_parent: &Receiver<Vec<u8>>,
to_parent: &Sender<~str>) {
to_parent: &Sender<StrBuf>) {
let mut freqs: HashMap<Vec<u8>, uint> = HashMap::new();
let mut carry = Vec::new();
let mut total: uint = 0u;
@ -129,13 +129,13 @@ fn make_sequence_processor(sz: uint,
let buffer = match sz {
1u => { sort_and_fmt(&freqs, total) }
2u => { sort_and_fmt(&freqs, total) }
3u => { format!("{}\t{}", find(&freqs, "GGT".to_owned()), "GGT") }
4u => { format!("{}\t{}", find(&freqs, "GGTA".to_owned()), "GGTA") }
6u => { format!("{}\t{}", find(&freqs, "GGTATT".to_owned()), "GGTATT") }
12u => { format!("{}\t{}", find(&freqs, "GGTATTTTAATT".to_owned()), "GGTATTTTAATT") }
18u => { format!("{}\t{}", find(&freqs, "GGTATTTTAATTTATAGT".to_owned()),
3u => { format_strbuf!("{}\t{}", find(&freqs, "GGT".to_strbuf()), "GGT") }
4u => { format_strbuf!("{}\t{}", find(&freqs, "GGTA".to_strbuf()), "GGTA") }
6u => { format_strbuf!("{}\t{}", find(&freqs, "GGTATT".to_strbuf()), "GGTATT") }
12u => { format_strbuf!("{}\t{}", find(&freqs, "GGTATTTTAATT".to_strbuf()), "GGTATTTTAATT") }
18u => { format_strbuf!("{}\t{}", find(&freqs, "GGTATTTTAATTTATAGT".to_strbuf()),
"GGTATTTTAATTTATAGT") }
_ => { "".to_owned() }
_ => { "".to_strbuf() }
};
to_parent.send(buffer);
@ -155,7 +155,7 @@ fn main() {
// initialize each sequence sorter
let sizes = vec!(1u,2,3,4,6,12,18);
let mut streams = Vec::from_fn(sizes.len(), |_| Some(channel::<~str>()));
let mut streams = Vec::from_fn(sizes.len(), |_| Some(channel::<StrBuf>()));
let mut from_child = Vec::new();
let to_child = sizes.iter().zip(streams.mut_iter()).map(|(sz, stream_ref)| {
let sz = *sz;

View File

@ -184,7 +184,7 @@ fn get_id(m: u64) -> u8 {
fail!("{:016x} does not have a valid identifier", m);
}
// Converts a list of mask to a ~str.
// Converts a list of mask to a StrBuf.
fn to_vec(raw_sol: &List<u64>) -> Vec<u8> {
let mut sol = Vec::from_elem(50, '.' as u8);
for &m in raw_sol.iter() {
@ -198,7 +198,7 @@ fn to_vec(raw_sol: &List<u64>) -> Vec<u8> {
sol
}
// Prints a solution in ~str form.
// Prints a solution in StrBuf form.
fn print_sol(sol: &Vec<u8>) {
for (i, c) in sol.iter().enumerate() {
if (i) % 5 == 0 { println!(""); }

View File

@ -52,9 +52,10 @@ struct Config {
stress: bool
}
fn parse_opts(argv: Vec<~str> ) -> Config {
fn parse_opts(argv: Vec<StrBuf> ) -> Config {
let opts = vec!(getopts::optflag("", "stress", ""));
let argv = argv.iter().map(|x| x.to_str()).collect::<Vec<_>>();
let opt_args = argv.slice(1, argv.len());
match getopts::getopts(opt_args, opts.as_slice()) {
@ -92,11 +93,11 @@ fn stress(num_tasks: int) {
fn main() {
let args = os::args();
let args = if os::getenv("RUST_BENCH").is_some() {
vec!("".to_owned(), "20".to_owned())
vec!("".to_strbuf(), "20".to_strbuf())
} else if args.len() <= 1u {
vec!("".to_owned(), "8".to_owned())
vec!("".to_strbuf(), "8".to_strbuf())
} else {
args.move_iter().collect()
args.move_iter().map(|x| x.to_strbuf()).collect()
};
let opts = parse_opts(args.clone());

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern:expected `~str` but found `int`
// error-pattern:expected `std::strbuf::StrBuf` but found `int`
static i: ~str = 10i;
fn main() { println!("{:?}", i); }
static i: StrBuf = 10i;
fn main() { println!("{}", i); }

View File

@ -12,4 +12,4 @@
mod m1 {}
fn main(args: Vec<~str>) { log(debug, m1::a); }
fn main(args: Vec<StrBuf>) { log(debug, m1::a); }

View File

@ -14,6 +14,6 @@ mod m1 {
pub mod a {}
}
fn main(args: Vec<~str>) {
fn main(args: Vec<StrBuf>) {
log(debug, m1::a);
}

View File

@ -8,6 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern:`^` cannot be applied to type `~str`
// error-pattern:`^` cannot be applied to type `std::strbuf::StrBuf`
fn main() { let x = "a".to_owned() ^ "b".to_owned(); }
fn main() { let x = "a".to_strbuf() ^ "b".to_strbuf(); }

View File

@ -26,15 +26,15 @@ fn blah() {
}
struct S {
f: ~str,
g: ~str
f: StrBuf,
g: StrBuf
}
impl Drop for S {
fn drop(&mut self) { println!("{}", self.f); }
}
fn move_in_match() {
match S {f: "foo".to_owned(), g: "bar".to_owned()} {
match S {f: "foo".to_strbuf(), g: "bar".to_strbuf()} {
S { //~ ERROR cannot move out of type `S`, which defines the `Drop` trait
f: _s, //~ NOTE attempting to move value to here
g: _t //~ NOTE and here

View File

@ -8,9 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn with(f: |&~str|) {}
fn with(f: |&StrBuf|) {}
fn arg_item(&_x: &~str) {}
fn arg_item(&_x: &StrBuf) {}
//~^ ERROR cannot move out of dereference of `&`-pointer
fn arg_closure() {

View File

@ -8,20 +8,20 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct S {f:~str}
struct S {f:StrBuf}
impl Drop for S {
fn drop(&mut self) { println!("{}", self.f); }
}
fn move_in_match() {
match S {f:"foo".to_owned()} {
match S {f:"foo".to_strbuf()} {
S {f:_s} => {}
//~^ ERROR cannot move out of type `S`, which defines the `Drop` trait
}
}
fn move_in_let() {
let S {f:_s} = S {f:"foo".to_owned()};
let S {f:_s} = S {f:"foo".to_strbuf()};
//~^ ERROR cannot move out of type `S`, which defines the `Drop` trait
}

View File

@ -8,20 +8,20 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct S(~str);
struct S(StrBuf);
impl Drop for S {
fn drop(&mut self) { }
}
fn move_in_match() {
match S("foo".to_owned()) {
match S("foo".to_strbuf()) {
S(_s) => {}
//~^ ERROR cannot move out of type `S`, which defines the `Drop` trait
}
}
fn move_in_let() {
let S(_s) = S("foo".to_owned());
let S(_s) = S("foo".to_strbuf());
//~^ ERROR cannot move out of type `S`, which defines the `Drop` trait
}

View File

@ -12,14 +12,14 @@
#[deriving(Clone)]
struct Foo {
string: ~str
string: StrBuf
}
pub fn main() {
let x = vec!(
Foo { string: "foo".to_owned() },
Foo { string: "bar".to_owned() },
Foo { string: "baz".to_owned() }
Foo { string: "foo".to_strbuf() },
Foo { string: "bar".to_strbuf() },
Foo { string: "baz".to_strbuf() }
);
let x: &[Foo] = x.as_slice();
match x {

View File

@ -9,7 +9,7 @@
// except according to those terms.
struct Foo {
t: ~str
t: StrBuf
}
fn cond() -> bool { true }

View File

@ -10,17 +10,17 @@
enum E {
Foo,
Bar(~str)
Bar(StrBuf)
}
struct S {
x: E
}
fn f(x: ~str) {}
fn f(x: StrBuf) {}
fn main() {
let s = S { x: Bar("hello".to_owned()) };
let s = S { x: Bar("hello".to_strbuf()) };
match &s.x {
&Foo => {}
&Bar(identifier) => f(identifier.clone()) //~ ERROR cannot move

View File

@ -27,7 +27,7 @@ enum SafeEnum {
Variant1,
Variant2(int),
Variant3(WithDtor),
Variant4(~str)
Variant4(StrBuf)
}
// These should be ok
@ -106,8 +106,11 @@ static mut STATIC12: UnsafeStruct = UnsafeStruct;
static mut STATIC13: SafeStruct = SafeStruct{field1: Variant1, field2: Variant3(WithDtor)};
//~^ ERROR mutable static items are not allowed to have destructors
static mut STATIC14: SafeStruct = SafeStruct{field1: Variant1, field2: Variant4("str".to_owned())};
static mut STATIC14: SafeStruct = SafeStruct {
//~^ ERROR mutable static items are not allowed to have destructors
field1: Variant1,
field2: Variant4("str".to_strbuf())
};
static STATIC15: &'static [Box<MyOwned>] = &'static [box MyOwned, box MyOwned];
//~^ ERROR static items are not allowed to have owned pointers

View File

@ -11,7 +11,7 @@
mod circular_modules_hello; //~ERROR: circular modules
pub fn hi_str() -> ~str {
pub fn hi_str() -> StrBuf {
"Hi!".to_owned()
}

View File

@ -17,7 +17,7 @@ struct cat {
meows : uint,
how_hungry : int,
name : ~str,
name : StrBuf,
}
impl cat {
@ -49,7 +49,7 @@ impl cat {
}
}
fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
fn cat(in_x : uint, in_y : int, in_name: StrBuf) -> cat {
cat {
meows: in_x,
how_hungry: in_y,
@ -58,6 +58,6 @@ fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
}
fn main() {
let nyan: Box<noisy> = box cat(0, 2, "nyan".to_owned()) as Box<noisy>;
let nyan: Box<noisy> = box cat(0, 2, "nyan".to_strbuf()) as Box<noisy>;
nyan.eat(); //~ ERROR does not implement any method in scope named `eat`
}

View File

@ -9,7 +9,7 @@
// except according to those terms.
struct X {
x: ~str,
x: StrBuf,
}
impl Drop for X {
@ -18,13 +18,13 @@ impl Drop for X {
}
}
fn unwrap(x: X) -> ~str {
fn unwrap(x: X) -> StrBuf {
let X { x: y } = x; //~ ERROR cannot move out of type
y
}
fn main() {
let x = X { x: "hello".to_owned() };
let x = X { x: "hello".to_strbuf() };
let y = unwrap(x);
println!("contents: {}", y);
}

View File

@ -9,7 +9,7 @@
// except according to those terms.
struct X {
x: ~str,
x: StrBuf,
}
impl Drop for X {
@ -19,7 +19,7 @@ impl Drop for X {
}
fn main() {
let x = X { x: "hello".to_owned() };
let x = X { x: "hello".to_strbuf() };
match x {
X { x: y } => println!("contents: {}", y)

View File

@ -8,16 +8,16 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn wants_uniq(x: ~str) { }
fn wants_uniq(x: StrBuf) { }
fn wants_slice(x: &str) { }
fn has_uniq(x: ~str) {
fn has_uniq(x: StrBuf) {
wants_uniq(x);
wants_slice(x);
wants_slice(x.as_slice());
}
fn has_slice(x: &str) {
wants_uniq(x); //~ ERROR mismatched types: expected `~str` but found `&str` (expected box but f
wants_uniq(x); //~ ERROR mismatched types
wants_slice(x);
}

View File

@ -28,10 +28,10 @@ fn main() {
//~^ ERROR mismatched types: expected `Foo<int>` but found `()`
// Including cases where the default is using previous type params.
let _: HashMap<~str, int> = ();
//~^ ERROR mismatched types: expected `HashMap<~str,int>` but found `()`
let _: HashMap<~str, int, Hash<~str>> = ();
//~^ ERROR mismatched types: expected `HashMap<~str,int>` but found `()`
let _: HashMap<StrBuf, int> = ();
//~^ ERROR mismatched types: expected `HashMap<std::strbuf::StrBuf,int>` but found `()`
let _: HashMap<StrBuf, int, Hash<StrBuf>> = ();
//~^ ERROR mismatched types: expected `HashMap<std::strbuf::StrBuf,int>` but found `()`
// But not when there's a different type in between.
let _: Foo<A, int, C> = ();

View File

@ -16,4 +16,4 @@ use zed::baz;
mod zed {
pub fn bar() { println!("bar"); }
}
fn main(args: Vec<~str>) { bar(); }
fn main(args: Vec<StrBuf>) { bar(); }

View File

@ -16,4 +16,4 @@ mod baz {}
mod zed {
pub fn bar() { println!("bar3"); }
}
fn main(args: Vec<~str>) { bar(); }
fn main(args: Vec<StrBuf>) { bar(); }

View File

@ -10,17 +10,17 @@
pub fn main() {
let v: Vec<int> = vec!(0, 1, 2, 3, 4, 5);
let s: ~str = "abcdef".to_owned();
let s: StrBuf = "abcdef".to_strbuf();
assert_eq!(v.as_slice()[3u], 3);
assert_eq!(v.as_slice()[3u8], 3); //~ ERROR: mismatched types
assert_eq!(v.as_slice()[3i8], 3); //~ ERROR: mismatched types
assert_eq!(v.as_slice()[3u32], 3); //~ ERROR: mismatched types
assert_eq!(v.as_slice()[3i32], 3); //~ ERROR: mismatched types
println!("{}", v.as_slice()[3u8]); //~ ERROR: mismatched types
assert_eq!(s[3u], 'd' as u8);
assert_eq!(s[3u8], 'd' as u8); //~ ERROR: mismatched types
assert_eq!(s[3i8], 'd' as u8); //~ ERROR: mismatched types
assert_eq!(s[3u32], 'd' as u8); //~ ERROR: mismatched types
assert_eq!(s[3i32], 'd' as u8); //~ ERROR: mismatched types
println!("{}", s[3u8]); //~ ERROR: mismatched types
assert_eq!(s.as_slice()[3u], 'd' as u8);
assert_eq!(s.as_slice()[3u8], 'd' as u8); //~ ERROR: mismatched types
assert_eq!(s.as_slice()[3i8], 'd' as u8); //~ ERROR: mismatched types
assert_eq!(s.as_slice()[3u32], 'd' as u8); //~ ERROR: mismatched types
assert_eq!(s.as_slice()[3i32], 'd' as u8); //~ ERROR: mismatched types
println!("{}", s.as_slice()[3u8]); //~ ERROR: mismatched types
}

View File

@ -10,16 +10,16 @@
// Regression test for #13428
fn foo() -> ~str { //~ ERROR not all control paths return a value
format!("Hello {}",
"world")
fn foo() -> StrBuf { //~ ERROR not all control paths return a value
format_strbuf!("Hello {}",
"world")
// Put the trailing semicolon on its own line to test that the
// note message gets the offending semicolon exactly
; //~ NOTE consider removing this semicolon
}
fn bar() -> ~str { //~ ERROR not all control paths return a value
"foobar".to_owned()
fn bar() -> StrBuf { //~ ERROR not all control paths return a value
"foobar".to_strbuf()
; //~ NOTE consider removing this semicolon
}

View File

@ -16,14 +16,14 @@
struct t(Box<t>); //~ ERROR this type cannot be instantiated
trait to_str_2 {
fn my_to_str() -> ~str;
fn my_to_str() -> StrBuf;
}
// I use an impl here because it will cause
// the compiler to attempt autoderef and then
// try to resolve the method.
impl to_str_2 for t {
fn my_to_str() -> ~str { "t".to_owned() }
fn my_to_str() -> StrBuf { "t".to_strbuf() }
}
fn new_t(x: t) {

View File

@ -8,11 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn a(x: ~str) -> ~str {
fn a(x: StrBuf) -> StrBuf {
format!("First function with {}", x)
}
fn a(x: ~str, y: ~str) -> ~str { //~ ERROR duplicate definition of value `a`
fn a(x: StrBuf, y: StrBuf) -> StrBuf { //~ ERROR duplicate definition of value `a`
format!("Second function with {} and {}", x, y)
}

View File

@ -10,7 +10,7 @@
struct HTMLImageData {
image: Option<~str>
image: Option<StrBuf>
}
struct ElementData {

View File

@ -22,7 +22,7 @@ impl ToStr for Point { //~ ERROR implements a method not defined in the trait
Point { x: x, y: y }
}
fn to_str(&self) -> ~str {
fn to_str(&self) -> StrBuf {
format!("({}, {})", self.x, self.y)
}
}

View File

@ -13,7 +13,7 @@
use std::io::ReaderUtil;
use std::io::Reader;
fn bar(r:@ReaderUtil) -> ~str { r.read_line() }
fn bar(r:@ReaderUtil) -> StrBuf { r.read_line() }
fn main() {
let r : @Reader = io::stdin();

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn foo(b: bool) -> Result<bool,~str> {
fn foo(b: bool) -> Result<bool,StrBuf> {
Err("bar".to_owned());
//~^ ERROR: cannot determine a type for this expression: unconstrained type
}

View File

@ -10,15 +10,15 @@
pub struct CrateId {
local_path: ~str,
junk: ~str
local_path: StrBuf,
junk: StrBuf
}
impl CrateId {
fn new(s: &str) -> CrateId {
CrateId {
local_path: s.to_owned(),
junk: "wutevs".to_owned()
local_path: s.to_strbuf(),
junk: "wutevs".to_strbuf()
}
}
}

View File

@ -51,7 +51,7 @@ trait ManyImplTrait {
}
}
impl ManyImplTrait for ~str {
impl ManyImplTrait for StrBuf {
fn is_str() -> bool {
true
}

View File

@ -39,7 +39,7 @@ fn test<'a,T,U:Copy>(_: &'a int) {
// ~ pointers are not ok
assert_copy::<Box<int>>(); //~ ERROR does not fulfill
assert_copy::<~str>(); //~ ERROR does not fulfill
assert_copy::<StrBuf>(); //~ ERROR does not fulfill
assert_copy::<Vec<int> >(); //~ ERROR does not fulfill
assert_copy::<Box<&'a mut int>>(); //~ ERROR does not fulfill

View File

@ -30,7 +30,7 @@ fn test<'a,T,U:Send>(_: &'a int) {
// boxes are ok
assert_send::<Box<int>>();
assert_send::<~str>();
assert_send::<StrBuf>();
assert_send::<Vec<int> >();
// but not if they own a bad thing

View File

@ -51,7 +51,7 @@ fn good2() {
sure that when purity is inherited that the source of the unsafe-ness
is tracked correctly */
unsafe {
unsafe fn what() -> Vec<~str> { fail!() }
unsafe fn what() -> Vec<StrBuf> { fail!() }
callback(|| {
what();

View File

@ -12,36 +12,36 @@
// of the various arms, particularly in the case where regions are
// involved.
pub fn opt_str0<'a>(maybestr: &'a Option<~str>) -> &'a str {
pub fn opt_str0<'a>(maybestr: &'a Option<StrBuf>) -> &'a str {
if maybestr.is_none() {
"(none)"
} else {
let s: &'a str = *maybestr.get_ref();
let s: &'a str = maybestr.get_ref().as_slice();
s
}
}
pub fn opt_str1<'a>(maybestr: &'a Option<~str>) -> &'a str {
pub fn opt_str1<'a>(maybestr: &'a Option<StrBuf>) -> &'a str {
if maybestr.is_some() {
let s: &'a str = *maybestr.get_ref();
let s: &'a str = maybestr.get_ref().as_slice();
s
} else {
"(none)"
}
}
pub fn opt_str2<'a>(maybestr: &'a Option<~str>) -> &'static str {
pub fn opt_str2<'a>(maybestr: &'a Option<StrBuf>) -> &'static str {
if maybestr.is_none() { //~ ERROR mismatched types
"(none)"
} else {
let s: &'a str = *maybestr.get_ref();
let s: &'a str = maybestr.get_ref().as_slice();
s
}
}
pub fn opt_str3<'a>(maybestr: &'a Option<~str>) -> &'static str {
pub fn opt_str3<'a>(maybestr: &'a Option<StrBuf>) -> &'static str {
if maybestr.is_some() { //~ ERROR mismatched types
let s: &'a str = *maybestr.get_ref();
let s: &'a str = maybestr.get_ref().as_slice();
s
} else {
"(none)"

View File

@ -12,40 +12,40 @@
// of the various arms, particularly in the case where regions are
// involved.
pub fn opt_str0<'a>(maybestr: &'a Option<~str>) -> &'a str {
pub fn opt_str0<'a>(maybestr: &'a Option<StrBuf>) -> &'a str {
match *maybestr {
Some(ref s) => {
let s: &'a str = *s;
let s: &'a str = s.as_slice();
s
}
None => "(none)",
}
}
pub fn opt_str1<'a>(maybestr: &'a Option<~str>) -> &'a str {
pub fn opt_str1<'a>(maybestr: &'a Option<StrBuf>) -> &'a str {
match *maybestr {
None => "(none)",
Some(ref s) => {
let s: &'a str = *s;
let s: &'a str = s.as_slice();
s
}
}
}
pub fn opt_str2<'a>(maybestr: &'a Option<~str>) -> &'static str {
pub fn opt_str2<'a>(maybestr: &'a Option<StrBuf>) -> &'static str {
match *maybestr { //~ ERROR mismatched types
None => "(none)",
Some(ref s) => {
let s: &'a str = *s;
let s: &'a str = s.as_slice();
s
}
}
}
pub fn opt_str3<'a>(maybestr: &'a Option<~str>) -> &'static str {
pub fn opt_str3<'a>(maybestr: &'a Option<StrBuf>) -> &'static str {
match *maybestr { //~ ERROR mismatched types
Some(ref s) => {
let s: &'a str = *s;
let s: &'a str = s.as_slice();
s
}
None => "(none)",

View File

@ -15,9 +15,9 @@ use collections::HashMap;
// Test that trait types printed in error msgs include the type arguments.
fn main() {
let x: Box<HashMap<~str, ~str>> = box HashMap::new();
let x: Box<Map<~str, ~str>> = x;
let y: Box<Map<uint, ~str>> = box x;
//~^ ERROR failed to find an implementation of trait core::container::Map<uint,~str>
// for ~core::container::Map<~str,~str>:Send
let x: Box<HashMap<int, int>> = box HashMap::new();
let x: Box<Map<int, int>> = x;
let y: Box<Map<uint, int>> = box x;
//~^ ERROR failed to find an implementation of trait core::container::Map<uint,int>
// for ~core::container::Map<int,int>:Send
}

View File

@ -9,8 +9,8 @@
// except according to those terms.
fn main() {
match "foo".to_owned() {
['f', 'o', ..] => { } //~ ERROR mismatched types: expected `~str` but found a vector pattern
match "foo".to_strbuf() {
['f', 'o', ..] => {} //~ ERROR mismatched types
_ => { }
}
}

View File

@ -18,8 +18,10 @@ fn main() {
_ => ()
}
let x: Vec<~str> = vec!("foo".to_owned(), "bar".to_owned(), "baz".to_owned());
let x: &[~str] = x.as_slice();
let x: Vec<StrBuf> = vec!["foo".to_strbuf(),
"bar".to_strbuf(),
"baz".to_strbuf()];
let x: &[StrBuf] = x.as_slice();
match x {
[a, _, _, ..] => { println!("{}", a); }
[_, _, _, _, _] => { } //~ ERROR unreachable pattern

View File

@ -8,6 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern:cannot apply unary operator `-` to type `~str`
// error-pattern:cannot apply unary operator `-` to type `std::strbuf::StrBuf`
fn main() { -"foo".to_owned(); }
fn main() { -"foo".to_strbuf(); }

View File

@ -11,18 +11,18 @@
// Tests that if you move from `x.f` or `x[0]`, `x` is inaccessible.
// Also tests that we give a more specific error message.
struct Foo { f: ~str, y: int }
fn consume(_s: ~str) {}
struct Foo { f: StrBuf, y: int }
fn consume(_s: StrBuf) {}
fn touch<A>(_a: &A) {}
fn f10() {
let x = Foo { f: "hi".to_owned(), y: 3 };
let x = Foo { f: "hi".to_strbuf(), y: 3 };
consume(x.f);
touch(&x.y); //~ ERROR use of partially moved value: `x`
}
fn f20() {
let x = vec!("hi".to_owned());
let x = vec!("hi".to_strbuf());
consume(x.move_iter().next().unwrap());
touch(x.get(0)); //~ ERROR use of moved value: `x`
}

View File

@ -14,17 +14,17 @@
#![feature(managed_boxes)]
struct Foo<A> { f: A }
fn guard(_s: ~str) -> bool {fail!()}
fn guard(_s: StrBuf) -> bool {fail!()}
fn touch<A>(_a: &A) {}
fn f10() {
let x = "hi".to_owned();
let x = "hi".to_strbuf();
let _y = Foo { f:x };
touch(&x); //~ ERROR use of moved value: `x`
}
fn f20() {
let x = "hi".to_owned();
let x = "hi".to_strbuf();
let _y = (x, 3);
touch(&x); //~ ERROR use of moved value: `x`
}
@ -36,8 +36,8 @@ fn f21() {
}
fn f30(cond: bool) {
let x = "hi".to_owned();
let y = "ho".to_owned();
let x = "hi".to_strbuf();
let y = "ho".to_strbuf();
let _y = if cond {
x
} else {
@ -48,8 +48,8 @@ fn f30(cond: bool) {
}
fn f40(cond: bool) {
let x = "hi".to_owned();
let y = "ho".to_owned();
let x = "hi".to_strbuf();
let y = "ho".to_strbuf();
let _y = match cond {
true => x,
false => y
@ -59,8 +59,8 @@ fn f40(cond: bool) {
}
fn f50(cond: bool) {
let x = "hi".to_owned();
let y = "ho".to_owned();
let x = "hi".to_strbuf();
let y = "ho".to_strbuf();
let _y = match cond {
_ if guard(x) => 10,
true => 10,
@ -71,31 +71,31 @@ fn f50(cond: bool) {
}
fn f70() {
let x = "hi".to_owned();
let x = "hi".to_strbuf();
let _y = [x];
touch(&x); //~ ERROR use of moved value: `x`
}
fn f80() {
let x = "hi".to_owned();
let x = "hi".to_strbuf();
let _y = vec!(x);
touch(&x); //~ ERROR use of moved value: `x`
}
fn f100() {
let x = vec!("hi".to_owned());
let x = vec!("hi".to_strbuf());
let _y = x.move_iter().next().unwrap();
touch(&x); //~ ERROR use of moved value: `x`
}
fn f110() {
let x = vec!("hi".to_owned());
let x = vec!("hi".to_strbuf());
let _y = [x.move_iter().next().unwrap(), ..1];
touch(&x); //~ ERROR use of moved value: `x`
}
fn f120() {
let mut x = vec!("hi".to_owned(), "ho".to_owned());
let mut x = vec!("hi".to_strbuf(), "ho".to_strbuf());
x.as_mut_slice().swap(0, 1);
touch(x.get(0));
touch(x.get(1));

View File

@ -13,7 +13,7 @@
// terms of the binding, not the discriminant.
struct Foo<A> { f: A }
fn guard(_s: ~str) -> bool {fail!()}
fn guard(_s: StrBuf) -> bool {fail!()}
fn touch<A>(_a: &A) {}
fn f10() {

View File

@ -14,5 +14,5 @@ struct S {
impl Cmp, ToStr for S { //~ ERROR: expected `{` but found `,`
fn eq(&&other: S) { false }
fn to_str(&self) -> ~str { "hi".to_owned() }
fn to_str(&self) -> StrBuf { "hi".to_owned() }
}

View File

@ -15,10 +15,10 @@
struct foo {
i: int,
j: @~str,
j: @StrBuf,
}
fn foo(i:int, j: @~str) -> foo {
fn foo(i:int, j: @StrBuf) -> foo {
foo {
i: i,
j: j
@ -26,7 +26,7 @@ fn foo(i:int, j: @~str) -> foo {
}
fn main() {
let cat = "kitty".to_owned();
let cat = "kitty".to_strbuf();
let (tx, _) = channel(); //~ ERROR does not fulfill `Send`
tx.send(foo(42, @(cat))); //~ ERROR does not fulfill `Send`
}

View File

@ -13,7 +13,7 @@
// ignore-test
fn main() {
let args : ~[~str] = ::std::os::args();
let args : ~[StrBuf] = ::std::os::args();
::std::io::println(args[0]);
}
@ -25,6 +25,6 @@ fn main() {
// compile-flags:-g
// gdb-command:list
// gdb-check:1[...]fn main() {
// gdb-check:2[...]let args : ~[~str] = ::std::os::args();
// gdb-check:2[...]let args : ~[StrBuf] = ::std::os::args();
// gdb-check:3[...]::std::io::println(args[0]);
// gdb-check:4[...]}

View File

@ -13,7 +13,7 @@
// pp-exact
fn call_it(f: proc(~str) -> ~str) { }
fn call_it(f: proc(StrBuf) -> StrBuf) { }
fn call_this(f: |&str|: Send) { }

View File

@ -9,5 +9,5 @@
// except according to those terms.
// error-pattern:quux
fn my_err(s: ~str) -> ! { println!("{}", s); fail!("quux"); }
fn main() { 3u == my_err("bye".to_owned()); }
fn my_err(s: StrBuf) -> ! { println!("{}", s); fail!("quux"); }
fn main() { 3u == my_err("bye".to_strbuf()); }

View File

@ -9,5 +9,5 @@
// except according to those terms.
// error-pattern:quux
fn my_err(s: ~str) -> ! { println!("{}", s); fail!("quux"); }
fn main() { 3u == my_err("bye".to_owned()); }
fn my_err(s: StrBuf) -> ! { println!("{}", s); fail!("quux"); }
fn main() { 3u == my_err("bye".to_strbuf()); }

View File

@ -10,4 +10,7 @@
// error-pattern:meh
fn main() { let str_var: ~str = "meh".to_owned(); fail!("{}", str_var); }
fn main() {
let str_var: StrBuf = "meh".to_strbuf();
fail!("{}", str_var);
}

View File

@ -9,5 +9,5 @@
// except according to those terms.
// error-pattern:quux
fn my_err(s: ~str) -> ! { println!("{}", s); fail!("quux"); }
fn main() { if my_err("bye".to_owned()) { } }
fn my_err(s: StrBuf) -> ! { println!("{}", s); fail!("quux"); }
fn main() { if my_err("bye".to_strbuf()) { } }

View File

@ -13,7 +13,7 @@
#![allow(unreachable_code)]
#![allow(unused_variable)]
fn foo(s: ~str) { }
fn foo(s: StrBuf) { }
fn main() {
let i =

View File

@ -13,5 +13,5 @@
use std::result;
fn main() {
println!("{:?}", result::Err::<int,~str>("kitty".to_owned()).unwrap());
println!("{:?}", result::Err::<int,StrBuf>("kitty".to_strbuf()).unwrap());
}

View File

@ -15,7 +15,7 @@
#![allow(unreachable_code)]
#![allow(unused_variable)]
struct T { t: ~str }
struct T { t: StrBuf }
fn main() {
let pth = fail!("bye");

View File

@ -11,8 +11,8 @@
// error-pattern:index out of bounds: the len is 5 but the index is 5
fn main() {
let s: ~str = "hello".to_owned();
let s: StrBuf = "hello".to_strbuf();
// Bounds-check failure.
assert_eq!(s[5], 0x0 as u8);
assert_eq!(s.as_slice()[5], 0x0 as u8);
}

View File

@ -13,17 +13,17 @@
// error-pattern:fail
fn main() {
let cheese = "roquefort".to_owned();
let carrots = @"crunchy".to_owned();
let cheese = "roquefort".to_strbuf();
let carrots = @"crunchy".to_strbuf();
let result: |@~str, |~str||: 'static = (|tasties, macerate| {
let result: |@StrBuf, |StrBuf||: 'static = (|tasties, macerate| {
macerate((*tasties).clone());
});
result(carrots, |food| {
let mush = food + cheese;
let mush = format_strbuf!("{}{}", food, cheese);
let cheese = cheese.clone();
let f: || = || {
let _chew = mush + cheese;
let _chew = format_strbuf!("{}{}", mush, cheese);
fail!("so yummy")
};
f();

View File

@ -48,7 +48,7 @@ fn main() {
let _ = write!(&mut File::create(&main_file).unwrap(),
r"\#![feature(non_ascii_idents)] fn main() \{ {} \}",
// random string of length n
range(0, n).map(|_| random_char()).collect::<~str>());
range(0, n).map(|_| random_char()).collect::<StrBuf>());
}
// rustc is passed to us with --out-dir and -L etc., so we

View File

@ -75,7 +75,7 @@ fn main() {
}
fn check_pp<T>(cx: fake_ext_ctxt,
expr: T, f: |pprust::ps, T|, expect: ~str) {
expr: T, f: |pprust::ps, T|, expect: StrBuf) {
let s = io::with_str_writer(|wr| {
let pp = pprust::rust_printer(wr, cx.parse_sess().interner);
f(pp, expr);

View File

@ -14,10 +14,10 @@
enum sty { ty_nil, }
struct RawT {struct_: sty, cname: Option<~str>, hash: uint}
struct RawT {struct_: sty, cname: Option<StrBuf>, hash: uint}
fn mk_raw_ty(st: sty, cname: Option<~str>) -> RawT {
fn mk_raw_ty(st: sty, cname: Option<StrBuf>) -> RawT {
return RawT {struct_: st, cname: cname, hash: 0u};
}
pub fn main() { mk_raw_ty(ty_nil, None::<~str>); }
pub fn main() { mk_raw_ty(ty_nil, None::<StrBuf>); }

View File

@ -15,6 +15,7 @@ fn g(act: |Vec<int> | -> int) -> int { return act(vec!(1, 2, 3)); }
pub fn main() {
assert_eq!(g(f), 1);
let f1: |Vec<~str> | -> ~str = f;
assert_eq!(f1(vec!("x".to_owned(), "y".to_owned(), "z".to_owned())), "x".to_owned());
let f1: |Vec<StrBuf>| -> StrBuf = f;
assert_eq!(f1(vec!["x".to_strbuf(), "y".to_strbuf(), "z".to_strbuf()]),
"x".to_strbuf());
}

View File

@ -11,22 +11,22 @@
#![feature(managed_boxes)]
trait Foo {
fn foo(&self) -> ~str;
fn foo(&self) -> StrBuf;
}
impl<T:Foo> Foo for @T {
fn foo(&self) -> ~str {
format!("@{}", (**self).foo())
fn foo(&self) -> StrBuf {
format_strbuf!("@{}", (**self).foo())
}
}
impl Foo for uint {
fn foo(&self) -> ~str {
format!("{}", *self)
fn foo(&self) -> StrBuf {
format_strbuf!("{}", *self)
}
}
pub fn main() {
let x = @3u;
assert_eq!(x.foo(), "@3".to_owned());
assert_eq!(x.foo(), "@3".to_strbuf());
}

View File

@ -36,14 +36,21 @@ fn double() {
}
fn runtest(me: &str) {
let mut env = os::env().move_iter().collect::<Vec<(~str, ~str)>>();
match env.iter().position(|&(ref s, _)| "RUST_BACKTRACE" == *s) {
let mut env = os::env().move_iter()
.map(|(ref k, ref v)| {
(k.to_strbuf(), v.to_strbuf())
}).collect::<Vec<(StrBuf,StrBuf)>>();
match env.iter()
.position(|&(ref s, _)| "RUST_BACKTRACE" == s.as_slice()) {
Some(i) => { env.remove(i); }
None => {}
}
env.push(("RUST_BACKTRACE".to_owned(), "1".to_owned()));
env.push(("RUST_BACKTRACE".to_strbuf(), "1".to_strbuf()));
// Make sure that the stack trace is printed
let env = env.iter()
.map(|&(ref k, ref v)| (k.to_owned(), v.to_owned()))
.collect::<Vec<_>>();
let mut p = Process::configure(ProcessConfig {
program: me,
args: ["fail".to_owned()],

View File

@ -9,6 +9,6 @@
// except according to those terms.
pub fn main() {
fn as_buf<T>(s: ~str, f: |~str| -> T) -> T { f(s) }
as_buf("foo".to_owned(), |foo: ~str| -> () println!("{}", foo) );
fn as_buf<T>(s: StrBuf, f: |StrBuf| -> T) -> T { f(s) }
as_buf("foo".to_strbuf(), |foo: StrBuf| -> () println!("{}", foo) );
}

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn foo(s: &~str) -> bool {
fn foo(s: &StrBuf) -> bool {
match s.as_slice() {
"kitty" => true,
_ => false
@ -16,6 +16,6 @@ fn foo(s: &~str) -> bool {
}
pub fn main() {
assert!(foo(&"kitty".to_owned()));
assert!(!foo(&"gata".to_owned()));
assert!(foo(&"kitty".to_strbuf()));
assert!(!foo(&"gata".to_strbuf()));
}

View File

@ -9,35 +9,36 @@
// except according to those terms.
trait Speak {
fn say(&self, s:&str) -> ~str;
fn hi(&self) -> ~str { hello(self) }
fn say(&self, s:&str) -> StrBuf;
fn hi(&self) -> StrBuf { hello(self) }
}
fn hello<S:Speak>(s:&S) -> ~str{
fn hello<S:Speak>(s:&S) -> StrBuf{
s.say("hello")
}
impl Speak for int {
fn say(&self, s:&str) -> ~str {
format!("{}: {}", s, *self)
fn say(&self, s:&str) -> StrBuf {
format_strbuf!("{}: {}", s, *self)
}
}
impl<T: Speak> Speak for Option<T> {
fn say(&self, s:&str) -> ~str {
fn say(&self, s:&str) -> StrBuf {
match *self {
None => format!("{} - none", s),
Some(ref x) => { "something!".to_owned() + x.say(s) }
None => format_strbuf!("{} - none", s),
Some(ref x) => { format_strbuf!("something!{}", x.say(s)) }
}
}
}
pub fn main() {
assert_eq!(3.hi(), "hello: 3".to_owned());
assert_eq!(Some(Some(3)).hi(), "something!something!hello: 3".to_owned());
assert_eq!(None::<int>.hi(), "hello - none".to_owned());
assert_eq!(3.hi(), "hello: 3".to_strbuf());
assert_eq!(Some(Some(3)).hi(),
"something!something!hello: 3".to_strbuf());
assert_eq!(None::<int>.hi(), "hello - none".to_strbuf());
assert_eq!(Some(None::<int>).hi(), "something!hello - none".to_owned());
assert_eq!(Some(3).hi(), "something!hello: 3".to_owned());
assert_eq!(Some(None::<int>).hi(), "something!hello - none".to_strbuf());
assert_eq!(Some(3).hi(), "something!hello: 3".to_strbuf());
}

View File

@ -21,15 +21,16 @@ mod mlibc {
}
}
fn atol(s: ~str) -> int {
s.with_c_str(|x| unsafe { mlibc::atol(x) as int })
fn atol(s: StrBuf) -> int {
s.as_slice().with_c_str(|x| unsafe { mlibc::atol(x) as int })
}
fn atoll(s: ~str) -> i64 {
s.with_c_str(|x| unsafe { mlibc::atoll(x) as i64 })
fn atoll(s: StrBuf) -> i64 {
s.as_slice().with_c_str(|x| unsafe { mlibc::atoll(x) as i64 })
}
pub fn main() {
assert_eq!(atol("1024".to_owned()) * 10, atol("10240".to_owned()));
assert!((atoll("11111111111111111".to_owned()) * 10) == atoll("111111111111111110".to_owned()));
assert_eq!(atol("1024".to_strbuf()) * 10, atol("10240".to_strbuf()));
assert!((atoll("11111111111111111".to_strbuf()) * 10) ==
atoll("111111111111111110".to_strbuf()));
}

View File

@ -12,8 +12,8 @@
use std::task;
fn child2(_s: ~str) { }
fn child2(_s: StrBuf) { }
pub fn main() {
let _x = task::spawn(proc() child2("hi".to_owned()));
let _x = task::spawn(proc() child2("hi".to_strbuf()));
}

View File

@ -11,7 +11,7 @@
// pp-exact - Make sure we actually print the attributes
struct cat {
name: ~str,
name: StrBuf,
}
impl Drop for cat {
@ -21,6 +21,6 @@ impl Drop for cat {
#[cat_maker]
fn cat(name: ~str) -> cat { cat{name: name,} }
fn cat(name: StrBuf) -> cat { cat{name: name,} }
pub fn main() { let _kitty = cat("Spotty".to_owned()); }
pub fn main() { let _kitty = cat("Spotty".to_strbuf()); }

View File

@ -9,7 +9,7 @@
// except according to those terms.
struct cat {
name: ~str,
name: StrBuf,
}
impl Drop for cat {
@ -26,12 +26,12 @@ impl Drop for cat {
/**
Maybe it should technically be a kitten_maker.
*/
fn cat(name: ~str) -> cat {
fn cat(name: StrBuf) -> cat {
cat {
name: name
}
}
pub fn main() {
let _kitty = cat("Spotty".to_owned());
let _kitty = cat("Spotty".to_strbuf());
}

View File

@ -14,13 +14,13 @@ extern crate cci_class_cast;
use std::to_str::ToStr;
use cci_class_cast::kitty::cat;
fn print_out(thing: Box<ToStr>, expected: ~str) {
fn print_out(thing: Box<ToStr>, expected: StrBuf) {
let actual = thing.to_str();
println!("{}", actual);
assert_eq!(actual, expected);
assert_eq!(actual.to_strbuf(), expected);
}
pub fn main() {
let nyan: Box<ToStr> = box cat(0u, 2, "nyan".to_owned()) as Box<ToStr>;
print_out(nyan, "nyan".to_owned());
let nyan: Box<ToStr> = box cat(0u, 2, "nyan".to_strbuf()) as Box<ToStr>;
print_out(nyan, "nyan".to_strbuf());
}

View File

@ -53,7 +53,7 @@ struct cat {
meows: uint,
how_hungry: int,
name: ~str,
name: StrBuf,
}
impl noisy for cat {
@ -79,7 +79,7 @@ impl cat {
}
}
fn cat(in_x: uint, in_y: int, in_name: ~str) -> cat {
fn cat(in_x: uint, in_y: int, in_name: StrBuf) -> cat {
cat {
meows: in_x,
how_hungry: in_y,
@ -93,7 +93,7 @@ fn annoy_neighbors(critter: &mut noisy) {
}
pub fn main() {
let mut nyan: cat = cat(0u, 2, "nyan".to_owned());
let mut nyan: cat = cat(0u, 2, "nyan".to_strbuf());
let mut whitefang: dog = dog();
annoy_neighbors(&mut nyan);
annoy_neighbors(&mut whitefang);

View File

@ -19,7 +19,7 @@ trait noisy {
struct cat {
meows: uint,
how_hungry: int,
name: ~str,
name: StrBuf,
}
impl noisy for cat {
@ -50,7 +50,7 @@ impl cat {
}
}
fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
fn cat(in_x : uint, in_y : int, in_name: StrBuf) -> cat {
cat {
meows: in_x,
how_hungry: in_y,
@ -60,7 +60,7 @@ fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
pub fn main() {
let mut nyan = cat(0u, 2, "nyan".to_owned());
let mut nyan = cat(0u, 2, "nyan".to_strbuf());
let mut nyan: &mut noisy = &mut nyan;
nyan.speak();
}

View File

@ -17,14 +17,14 @@ use kitty::cat;
mod kitty {
pub struct cat {
meows: uint,
name: ~str,
name: StrBuf,
}
impl cat {
pub fn get_name(&self) -> ~str { self.name.clone() }
pub fn get_name(&self) -> StrBuf { self.name.clone() }
}
pub fn cat(in_name: ~str) -> cat {
pub fn cat(in_name: StrBuf) -> cat {
cat {
name: in_name,
meows: 0u
@ -33,5 +33,6 @@ mod kitty {
}
pub fn main() {
assert_eq!(cat("Spreckles".to_owned()).get_name(), "Spreckles".to_owned());
assert_eq!(cat("Spreckles".to_strbuf()).get_name(),
"Spreckles".to_strbuf());
}

View File

@ -114,9 +114,9 @@ impl<T> cat<T> {
}
pub fn main() {
let mut nyan: cat<~str> = cat::new(0, 2, "nyan".to_owned());
let mut nyan: cat<StrBuf> = cat::new(0, 2, "nyan".to_strbuf());
for _ in range(1u, 5) { nyan.speak(); }
assert!(*nyan.find(&1).unwrap() == "nyan".to_owned());
assert!(*nyan.find(&1).unwrap() == "nyan".to_strbuf());
assert_eq!(nyan.find(&10), None);
let mut spotty: cat<cat_type> = cat::new(2, 57, tuxedo);
for _ in range(0u, 6) { spotty.speak(); }

View File

@ -16,7 +16,7 @@ struct cat {
meows: uint,
how_hungry : int,
name : ~str,
name : StrBuf,
}
impl cat {
@ -47,7 +47,7 @@ impl cat {
}
}
fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
fn cat(in_x : uint, in_y : int, in_name: StrBuf) -> cat {
cat {
meows: in_x,
how_hungry: in_y,
@ -57,7 +57,7 @@ fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
pub fn main() {
let mut nyan = cat(0u, 2, "nyan".to_owned());
let mut nyan = cat(0u, 2, "nyan".to_strbuf());
nyan.eat();
assert!((!nyan.eat()));
for _ in range(1u, 10u) { nyan.speak(); };

View File

@ -18,7 +18,7 @@ struct cat {
meows : uint,
how_hungry : int,
name : ~str,
name : StrBuf,
}
impl cat {
@ -48,7 +48,7 @@ impl noisy for cat {
fn speak(&mut self) { self.meow(); }
}
fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
fn cat(in_x : uint, in_y : int, in_name: StrBuf) -> cat {
cat {
meows: in_x,
how_hungry: in_y,
@ -62,7 +62,7 @@ fn make_speak<C:noisy>(mut c: C) {
}
pub fn main() {
let mut nyan = cat(0u, 2, "nyan".to_owned());
let mut nyan = cat(0u, 2, "nyan".to_strbuf());
nyan.eat();
assert!((!nyan.eat()));
for _ in range(1u, 10u) {

View File

@ -14,7 +14,7 @@ struct cat {
meows : uint,
how_hungry : int,
name : ~str,
name : StrBuf,
}
impl cat {
@ -43,7 +43,7 @@ impl cat {
}
}
fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
fn cat(in_x : uint, in_y : int, in_name: StrBuf) -> cat {
cat {
meows: in_x,
how_hungry: in_y,
@ -57,13 +57,13 @@ impl fmt::Show for cat {
}
}
fn print_out(thing: Box<ToStr>, expected: ~str) {
fn print_out(thing: Box<ToStr>, expected: StrBuf) {
let actual = thing.to_str();
println!("{}", actual);
assert_eq!(actual, expected);
assert_eq!(actual.to_strbuf(), expected);
}
pub fn main() {
let nyan: Box<ToStr> = box cat(0u, 2, "nyan".to_owned()) as Box<ToStr>;
print_out(nyan, "nyan".to_owned());
let nyan: Box<ToStr> = box cat(0u, 2, "nyan".to_strbuf()) as Box<ToStr>;
print_out(nyan, "nyan".to_strbuf());
}

View File

@ -10,16 +10,16 @@
struct cat {
name : ~str,
name : StrBuf,
}
fn cat(in_name: ~str) -> cat {
fn cat(in_name: StrBuf) -> cat {
cat {
name: in_name
}
}
pub fn main() {
let _nyan = cat("nyan".to_owned());
let _nyan = cat("nyan".to_strbuf());
}

View File

@ -13,7 +13,7 @@ extern crate cci_class_4;
use cci_class_4::kitties::cat;
pub fn main() {
let mut nyan = cat(0u, 2, "nyan".to_owned());
let mut nyan = cat(0u, 2, "nyan".to_strbuf());
nyan.eat();
assert!((!nyan.eat()));
for _ in range(1u, 10u) { nyan.speak(); };

Some files were not shown because too many files have changed in this diff Show More