Skip to content
8 changes: 4 additions & 4 deletions src/compiletest/procsrv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ pub fn run(lib_path: &str,
for input.each |input| {
proc.input().write_str(*input);
}
let output = proc.finish_with_output();
let run::ProcessOutput { status, output, error, _ } = proc.finish_with_output();

Result {
status: output.status,
out: str::from_bytes(output.output),
err: str::from_bytes(output.error)
status: status,
out: str::from_bytes(output),
err: str::from_bytes(error)
}
}
2 changes: 1 addition & 1 deletion src/libextra/ebml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ pub mod writer {
}

pub fn wr_tagged_str(&mut self, tag_id: uint, v: &str) {
str::byte_slice(v, |b| self.wr_tagged_bytes(tag_id, b));
self.wr_tagged_bytes(tag_id, str::as_bytes_slice(v));
}

pub fn wr_bytes(&mut self, b: &[u8]) {
Expand Down
8 changes: 3 additions & 5 deletions src/libextra/net_tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1810,11 +1810,9 @@ mod test {

fn buf_write<W:io::Writer>(w: &W, val: &str) {
debug!("BUF_WRITE: val len %?", str::len(val));
do str::byte_slice(val) |b_slice| {
debug!("BUF_WRITE: b_slice len %?",
b_slice.len());
w.write(b_slice)
}
let b_slice = str::as_bytes_slice(val);
debug!("BUF_WRITE: b_slice len %?", b_slice.len());
w.write(b_slice)
}

fn buf_read<R:io::Reader>(r: &R, len: uint) -> ~str {
Expand Down
12 changes: 8 additions & 4 deletions src/libfuzzer/fuzzer.rc
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,12 @@ pub fn check_running(exe_filename: &Path) -> happiness {
let p = run::process_output(
"/Users/jruderman/scripts/timed_run_rust_program.py",
[exe_filename.to_str()]);
let comb = str::from_bytes(p.output) + "\n" + str::from_bytes(p.error);
if str::len(comb) > 1u {

let out = str::from_bytes_slice(p.output);
let err = str::from_bytes_slice(p.error);

let comb = fmt!("%s\n%s", out, err);
if comb.len() > 1u {
error!("comb comb comb: %?", comb);
}

Expand Down Expand Up @@ -473,8 +477,8 @@ pub fn check_compiling(filename: &Path) -> happiness {
"/Users/jruderman/code/rust/build/x86_64-apple-darwin/stage1/bin/rustc",
[filename.to_str()]);

let out = str::from_bytes(p.output);
let err = str::from_bytes(p.error);
let out = str::from_bytes_slice(p.output);
let err = str::from_bytes_slice(p.error);

//error!("Status: %d", p.status);
if p.status == 0 {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ fn read_path(d: ebml::Doc) -> (~str, uint) {
do reader::with_doc_data(d) |desc| {
let pos = io::u64_from_be_bytes(desc, 0u, 4u) as uint;
let pathbytes = desc.slice(4u, desc.len());
let path = str::from_bytes(pathbytes);
let path = str::from_bytes_slice(pathbytes).to_owned();

(path, pos)
}
Expand Down
21 changes: 12 additions & 9 deletions src/librustc/metadata/tydecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,18 @@ fn scan<R>(st: &mut PState, is_last: &fn(char) -> bool,
}
let end_pos = st.pos;
st.pos += 1;
return op(st.data.slice(start_pos, end_pos));
op(st.data.slice(start_pos, end_pos))
}

pub fn parse_ident(st: &mut PState, last: char) -> ast::ident {
fn is_last(b: char, c: char) -> bool { return c == b; }
return parse_ident_(st, |a| is_last(last, a) );
}

fn parse_ident_(st: &mut PState, is_last: @fn(char) -> bool) ->
ast::ident {
let rslt = scan(st, is_last, str::from_bytes);
return st.tcx.sess.ident_of(rslt);
fn parse_ident_(st: &mut PState, is_last: @fn(char) -> bool) -> ast::ident {
do scan(st, is_last) |v| {
st.tcx.sess.ident_of(str::from_bytes_slice(v))
}
}

pub fn parse_state_from_data<'a>(data: &'a [u8], crate_num: int,
Expand Down Expand Up @@ -409,7 +409,9 @@ fn parse_mt(st: &mut PState, conv: conv_did) -> ty::mt {

fn parse_def(st: &mut PState, source: DefIdSource,
conv: conv_did) -> ast::def_id {
return conv(source, scan(st, |c| { c == '|' }, parse_def_id));
do scan(st, |c| { c == '|' }) |v| {
conv(source, parse_def_id(v))
}
}

fn parse_uint(st: &mut PState) -> uint {
Expand Down Expand Up @@ -450,9 +452,10 @@ fn parse_abi_set(st: &mut PState) -> AbiSet {
assert_eq!(next(st), '[');
let mut abis = AbiSet::empty();
while peek(st) != ']' {
// FIXME(#5422) str API should not force this copy
let abi_str = scan(st, |c| c == ',', str::from_bytes);
let abi = abi::lookup(abi_str).expect(abi_str);
let abi = do scan(st, |c| c == ',') |v| {
let abi_str = str::from_bytes_slice(v);
abi::lookup(abi_str).expect(abi_str)
};
abis.add(abi);
}
assert_eq!(next(st), ']');
Expand Down
7 changes: 2 additions & 5 deletions src/librustc/util/ppaux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,12 +432,9 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str {
ty_err => ~"[type error]",
ty_param(param_ty {idx: id, def_id: did}) => {
if cx.sess.verbose() {
fmt!("'%s:%?",
str::from_bytes([('a' as u8) + (id as u8)]),
did)
fmt!("'%s:%?", str::from_byte(('a' as u8) + (id as u8)), did)
} else {
fmt!("'%s",
str::from_bytes([('a' as u8) + (id as u8)]))
fmt!("'%s", str::from_byte(('a' as u8) + (id as u8)))
}
}
ty_self(*) => ~"Self",
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/markdown_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ fn pandoc_writer(

debug!("pandoc result: %i", output.status);
if output.status != 0 {
error!("pandoc-out: %s", str::from_bytes(output.output));
error!("pandoc-err: %s", str::from_bytes(output.error));
error!("pandoc-out: %s", str::from_bytes_slice(output.output));
error!("pandoc-err: %s", str::from_bytes_slice(output.error));
fail!("pandoc failed");
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustpkg/rustpkg.rc
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl<'self> PkgScript<'self> {
let output = run::process_output(exe.to_str(), [root.to_str(), ~"configs"]);
// Run the configs() function to get the configs
let mut cfgs = ~[];
for str::each_word(str::from_bytes(output.output)) |w| {
for str::each_word(str::from_bytes_slice(output.output)) |w| {
cfgs.push(w.to_owned());
}
(cfgs, output.status)
Expand Down
8 changes: 4 additions & 4 deletions src/librustpkg/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ pub fn try_getting_version(remote_path: &RemotePath) -> Option<Version> {
tmp_dir.to_str()]);
if outp.status == 0 {
debug!("Cloned it... ( %s, %s )",
str::from_bytes(outp.output),
str::from_bytes(outp.error));
str::from_bytes_slice(outp.output),
str::from_bytes_slice(outp.error));
let mut output = None;
debug!("executing {git --git-dir=%s tag -l}", tmp_dir.push(".git").to_str());
let outp = run::process_output("git",
[fmt!("--git-dir=%s", tmp_dir.push(".git").to_str()),
~"tag", ~"-l"]);
let output_text = str::from_bytes(outp.output);
let output_text = str::from_bytes_slice(outp.output);
debug!("Full output: ( %s ) [%?]", output_text, outp.status);
for output_text.each_split_char('\n') |l| {
debug!("A line of output: %s", l);
Expand Down Expand Up @@ -212,4 +212,4 @@ fn test_split_version() {
let s = "a#1.2";
assert!(split_version(s) == Some((s.slice(0, 1), ExactRevision(~"1.2"))));
assert!(split_version("a#a#3.4") == None);
}
}
4 changes: 2 additions & 2 deletions src/libstd/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ pub fn with_bytes_reader<T>(bytes: &[u8], f: &fn(@Reader) -> T) -> T {
}

pub fn with_str_reader<T>(s: &str, f: &fn(@Reader) -> T) -> T {
str::byte_slice(s, |bytes| with_bytes_reader(bytes, f))
with_bytes_reader(str::as_bytes_slice(s), f)
}

// Writing
Expand Down Expand Up @@ -1462,7 +1462,7 @@ impl<T:Writer> WriterUtil for T {
self.write_str(str::from_char(ch));
}
}
fn write_str(&self, s: &str) { str::byte_slice(s, |v| self.write(v)) }
fn write_str(&self, s: &str) { self.write(str::as_bytes_slice(s)) }
fn write_line(&self, s: &str) {
self.write_str(s);
self.write_str(&"\n");
Expand Down
152 changes: 80 additions & 72 deletions src/libstd/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,90 +376,98 @@ impl<T:Copy + Zero> Option<T> {
}
}

#[test]
fn test_unwrap_ptr() {
unsafe {
let x = ~0;
let addr_x: *int = ::cast::transmute(&*x);
#[cfg(test)]
mod tests {
use super::*;
use std::str;
use std::util;

#[test]
fn test_unwrap_ptr() {
unsafe {
let x = ~0;
let addr_x: *int = ::cast::transmute(&*x);
let opt = Some(x);
let y = opt.unwrap();
let addr_y: *int = ::cast::transmute(&*y);
assert_eq!(addr_x, addr_y);
}
}

#[test]
fn test_unwrap_str() {
let x = ~"test";
let addr_x = str::as_buf(x, |buf, _len| buf);
let opt = Some(x);
let y = opt.unwrap();
let addr_y: *int = ::cast::transmute(&*y);
let addr_y = str::as_buf(y, |buf, _len| buf);
assert_eq!(addr_x, addr_y);
}
}

#[test]
fn test_unwrap_str() {
let x = ~"test";
let addr_x = str::as_buf(x, |buf, _len| buf);
let opt = Some(x);
let y = opt.unwrap();
let addr_y = str::as_buf(y, |buf, _len| buf);
assert_eq!(addr_x, addr_y);
}

#[test]
fn test_unwrap_resource() {
struct R {
i: @mut int,
}

#[unsafe_destructor]
impl ::ops::Drop for R {
fn finalize(&self) { *(self.i) += 1; }
}
#[test]
fn test_unwrap_resource() {
struct R {
i: @mut int,
}

fn R(i: @mut int) -> R {
R {
i: i
#[unsafe_destructor]
impl ::ops::Drop for R {
fn finalize(&self) { *(self.i) += 1; }
}
}

let i = @mut 0;
{
let x = R(i);
let opt = Some(x);
let _y = opt.unwrap();
}
assert_eq!(*i, 1);
}
fn R(i: @mut int) -> R {
R {
i: i
}
}

#[test]
fn test_option_dance() {
let x = Some(());
let mut y = Some(5);
let mut y2 = 0;
for x.each |_x| {
y2 = y.swap_unwrap();
let i = @mut 0;
{
let x = R(i);
let opt = Some(x);
let _y = opt.unwrap();
}
assert_eq!(*i, 1);
}
assert_eq!(y2, 5);
assert!(y.is_none());
}
#[test] #[should_fail] #[ignore(cfg(windows))]
fn test_option_too_much_dance() {
let mut y = Some(util::NonCopyable::new());
let _y2 = y.swap_unwrap();
let _y3 = y.swap_unwrap();
}

#[test]
fn test_option_while_some() {
let mut i = 0;
do Some(10).while_some |j| {
i += 1;
if (j > 0) {
Some(j-1)
} else {
None
#[test]
fn test_option_dance() {
let x = Some(());
let mut y = Some(5);
let mut y2 = 0;
for x.each |_x| {
y2 = y.swap_unwrap();
}
assert_eq!(y2, 5);
assert!(y.is_none());
}

#[test] #[should_fail] #[ignore(cfg(windows))]
fn test_option_too_much_dance() {
let mut y = Some(util::NonCopyable::new());
let _y2 = y.swap_unwrap();
let _y3 = y.swap_unwrap();
}

#[test]
fn test_option_while_some() {
let mut i = 0;
do Some(10).while_some |j| {
i += 1;
if (j > 0) {
Some(j-1)
} else {
None
}
}
assert_eq!(i, 11);
}
assert_eq!(i, 11);
}

#[test]
fn test_get_or_zero() {
let some_stuff = Some(42);
assert_eq!(some_stuff.get_or_zero(), 42);
let no_stuff: Option<int> = None;
assert_eq!(no_stuff.get_or_zero(), 0);
#[test]
fn test_get_or_zero() {
let some_stuff = Some(42);
assert_eq!(some_stuff.get_or_zero(), 42);
let no_stuff: Option<int> = None;
assert_eq!(no_stuff.get_or_zero(), 0);
}
}
2 changes: 1 addition & 1 deletion src/libstd/rt/io/flate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ mod test {
let mut out_bytes = [0, .. 100];
let bytes_read = inflate_reader.read(out_bytes).get();
assert_eq!(bytes_read, in_bytes.len());
let out_msg = str::from_bytes(out_bytes);
let out_msg = str::from_bytes_slice(out_bytes);
assert!(in_msg == out_msg);
}
}
Loading