auto merge of #19027 : nick29581/rust/coercions-4, r=alexcrichton
The forwards compatible parts of #18645, rebased. Converts implicit coercions from `[T, ..n]` to `&[T]` into explicit references.
This commit is contained in:
commit
0047dbe59c
142 changed files with 1269 additions and 1283 deletions
|
@ -399,7 +399,7 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
|
|||
procsrv::run("",
|
||||
config.adb_path.as_slice(),
|
||||
None,
|
||||
[
|
||||
&[
|
||||
"push".to_string(),
|
||||
exe_file.as_str().unwrap().to_string(),
|
||||
config.adb_test_dir.clone()
|
||||
|
@ -411,7 +411,7 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
|
|||
procsrv::run("",
|
||||
config.adb_path.as_slice(),
|
||||
None,
|
||||
[
|
||||
&[
|
||||
"forward".to_string(),
|
||||
"tcp:5039".to_string(),
|
||||
"tcp:5039".to_string()
|
||||
|
@ -432,7 +432,7 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
|
|||
config.adb_path
|
||||
.as_slice(),
|
||||
None,
|
||||
[
|
||||
&[
|
||||
"shell".to_string(),
|
||||
adb_arg.clone()
|
||||
],
|
||||
|
@ -746,7 +746,7 @@ fn run_debuginfo_lldb_test(config: &Config, props: &TestProps, testfile: &Path)
|
|||
cmd.arg(lldb_script_path)
|
||||
.arg(test_executable)
|
||||
.arg(debugger_script)
|
||||
.env_set_all([("PYTHONPATH", config.lldb_python_dir.clone().unwrap().as_slice())]);
|
||||
.env_set_all(&[("PYTHONPATH", config.lldb_python_dir.clone().unwrap().as_slice())]);
|
||||
|
||||
let (status, out, err) = match cmd.spawn() {
|
||||
Ok(process) => {
|
||||
|
@ -1142,11 +1142,11 @@ struct ProcRes {
|
|||
|
||||
fn compile_test(config: &Config, props: &TestProps,
|
||||
testfile: &Path) -> ProcRes {
|
||||
compile_test_(config, props, testfile, [])
|
||||
compile_test_(config, props, testfile, &[])
|
||||
}
|
||||
|
||||
fn jit_test(config: &Config, props: &TestProps, testfile: &Path) -> ProcRes {
|
||||
compile_test_(config, props, testfile, ["--jit".to_string()])
|
||||
compile_test_(config, props, testfile, &["--jit".to_string()])
|
||||
}
|
||||
|
||||
fn compile_test_(config: &Config, props: &TestProps,
|
||||
|
@ -1507,7 +1507,7 @@ fn _arm_exec_compiled_test(config: &Config,
|
|||
let copy_result = procsrv::run("",
|
||||
config.adb_path.as_slice(),
|
||||
None,
|
||||
[
|
||||
&[
|
||||
"push".to_string(),
|
||||
args.prog.clone(),
|
||||
config.adb_test_dir.clone()
|
||||
|
@ -1624,7 +1624,7 @@ fn _arm_push_aux_shared_library(config: &Config, testfile: &Path) {
|
|||
let copy_result = procsrv::run("",
|
||||
config.adb_path.as_slice(),
|
||||
None,
|
||||
[
|
||||
&[
|
||||
"push".to_string(),
|
||||
file.as_str()
|
||||
.unwrap()
|
||||
|
|
|
@ -84,7 +84,7 @@ will be counted as a failure. For example:
|
|||
#[test]
|
||||
#[should_fail]
|
||||
fn test_out_of_bounds_failure() {
|
||||
let v: &[int] = [];
|
||||
let v: &[int] = &[];
|
||||
v[0];
|
||||
}
|
||||
~~~
|
||||
|
|
|
@ -267,7 +267,7 @@ impl Bitv {
|
|||
/// ```
|
||||
/// use std::collections::bitv;
|
||||
///
|
||||
/// let bv = bitv::from_bytes([0b01100000]);
|
||||
/// let bv = bitv::from_bytes(&[0b01100000]);
|
||||
/// assert_eq!(bv.get(0), false);
|
||||
/// assert_eq!(bv.get(1), true);
|
||||
///
|
||||
|
@ -319,9 +319,9 @@ impl Bitv {
|
|||
/// let before = 0b01100000;
|
||||
/// let after = 0b11111111;
|
||||
///
|
||||
/// let mut bv = bitv::from_bytes([before]);
|
||||
/// let mut bv = bitv::from_bytes(&[before]);
|
||||
/// bv.set_all();
|
||||
/// assert_eq!(bv, bitv::from_bytes([after]));
|
||||
/// assert_eq!(bv, bitv::from_bytes(&[after]));
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn set_all(&mut self) {
|
||||
|
@ -338,9 +338,9 @@ impl Bitv {
|
|||
/// let before = 0b01100000;
|
||||
/// let after = 0b10011111;
|
||||
///
|
||||
/// let mut bv = bitv::from_bytes([before]);
|
||||
/// let mut bv = bitv::from_bytes(&[before]);
|
||||
/// bv.negate();
|
||||
/// assert_eq!(bv, bitv::from_bytes([after]));
|
||||
/// assert_eq!(bv, bitv::from_bytes(&[after]));
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn negate(&mut self) {
|
||||
|
@ -366,11 +366,11 @@ impl Bitv {
|
|||
/// let b = 0b01011010;
|
||||
/// let res = 0b01111110;
|
||||
///
|
||||
/// let mut a = bitv::from_bytes([a]);
|
||||
/// let b = bitv::from_bytes([b]);
|
||||
/// let mut a = bitv::from_bytes(&[a]);
|
||||
/// let b = bitv::from_bytes(&[b]);
|
||||
///
|
||||
/// assert!(a.union(&b));
|
||||
/// assert_eq!(a, bitv::from_bytes([res]));
|
||||
/// assert_eq!(a, bitv::from_bytes(&[res]));
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn union(&mut self, other: &Bitv) -> bool {
|
||||
|
@ -396,11 +396,11 @@ impl Bitv {
|
|||
/// let b = 0b01011010;
|
||||
/// let res = 0b01000000;
|
||||
///
|
||||
/// let mut a = bitv::from_bytes([a]);
|
||||
/// let b = bitv::from_bytes([b]);
|
||||
/// let mut a = bitv::from_bytes(&[a]);
|
||||
/// let b = bitv::from_bytes(&[b]);
|
||||
///
|
||||
/// assert!(a.intersect(&b));
|
||||
/// assert_eq!(a, bitv::from_bytes([res]));
|
||||
/// assert_eq!(a, bitv::from_bytes(&[res]));
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn intersect(&mut self, other: &Bitv) -> bool {
|
||||
|
@ -427,17 +427,17 @@ impl Bitv {
|
|||
/// let a_b = 0b00100100; // a - b
|
||||
/// let b_a = 0b00011010; // b - a
|
||||
///
|
||||
/// let mut bva = bitv::from_bytes([a]);
|
||||
/// let bvb = bitv::from_bytes([b]);
|
||||
/// let mut bva = bitv::from_bytes(&[a]);
|
||||
/// let bvb = bitv::from_bytes(&[b]);
|
||||
///
|
||||
/// assert!(bva.difference(&bvb));
|
||||
/// assert_eq!(bva, bitv::from_bytes([a_b]));
|
||||
/// assert_eq!(bva, bitv::from_bytes(&[a_b]));
|
||||
///
|
||||
/// let bva = bitv::from_bytes([a]);
|
||||
/// let mut bvb = bitv::from_bytes([b]);
|
||||
/// let bva = bitv::from_bytes(&[a]);
|
||||
/// let mut bvb = bitv::from_bytes(&[b]);
|
||||
///
|
||||
/// assert!(bvb.difference(&bva));
|
||||
/// assert_eq!(bvb, bitv::from_bytes([b_a]));
|
||||
/// assert_eq!(bvb, bitv::from_bytes(&[b_a]));
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn difference(&mut self, other: &Bitv) -> bool {
|
||||
|
@ -474,7 +474,7 @@ impl Bitv {
|
|||
/// ```
|
||||
/// use std::collections::bitv;
|
||||
///
|
||||
/// let bv = bitv::from_bytes([0b01110100, 0b10010010]);
|
||||
/// let bv = bitv::from_bytes(&[0b01110100, 0b10010010]);
|
||||
/// assert_eq!(bv.iter().filter(|x| *x).count(), 7);
|
||||
/// ```
|
||||
#[inline]
|
||||
|
@ -569,7 +569,7 @@ impl Bitv {
|
|||
/// ```
|
||||
/// use std::collections::bitv;
|
||||
///
|
||||
/// let bv = bitv::from_bytes([0b10100000]);
|
||||
/// let bv = bitv::from_bytes(&[0b10100000]);
|
||||
/// assert_eq!(bv.to_bools(), vec!(true, false, true, false,
|
||||
/// false, false, false, false));
|
||||
/// ```
|
||||
|
@ -589,10 +589,10 @@ impl Bitv {
|
|||
/// ```
|
||||
/// use std::collections::bitv;
|
||||
///
|
||||
/// let bv = bitv::from_bytes([0b10100000]);
|
||||
/// let bv = bitv::from_bytes(&[0b10100000]);
|
||||
///
|
||||
/// assert!(bv.eq_vec([true, false, true, false,
|
||||
/// false, false, false, false]));
|
||||
/// assert!(bv.eq_vec(&[true, false, true, false,
|
||||
/// false, false, false, false]));
|
||||
/// ```
|
||||
pub fn eq_vec(&self, v: &[bool]) -> bool {
|
||||
assert_eq!(self.nbits, v.len());
|
||||
|
@ -614,9 +614,9 @@ impl Bitv {
|
|||
/// ```
|
||||
/// use std::collections::bitv;
|
||||
///
|
||||
/// let mut bv = bitv::from_bytes([0b01001011]);
|
||||
/// let mut bv = bitv::from_bytes(&[0b01001011]);
|
||||
/// bv.truncate(2);
|
||||
/// assert!(bv.eq_vec([false, true]));
|
||||
/// assert!(bv.eq_vec(&[false, true]));
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn truncate(&mut self, len: uint) {
|
||||
|
@ -675,7 +675,7 @@ impl Bitv {
|
|||
/// ```
|
||||
/// use std::collections::bitv;
|
||||
///
|
||||
/// let mut bv = bitv::from_bytes([0b01001011]);
|
||||
/// let mut bv = bitv::from_bytes(&[0b01001011]);
|
||||
/// bv.grow(2, true);
|
||||
/// assert_eq!(bv.len(), 10);
|
||||
/// assert_eq!(bv.to_bytes(), vec!(0b01001011, 0b11000000));
|
||||
|
@ -727,7 +727,7 @@ impl Bitv {
|
|||
/// ```
|
||||
/// use std::collections::bitv;
|
||||
///
|
||||
/// let mut bv = bitv::from_bytes([0b01001001]);
|
||||
/// let mut bv = bitv::from_bytes(&[0b01001001]);
|
||||
/// assert_eq!(bv.pop(), true);
|
||||
/// assert_eq!(bv.pop(), false);
|
||||
/// assert_eq!(bv.len(), 6);
|
||||
|
@ -753,7 +753,7 @@ impl Bitv {
|
|||
/// let mut bv = Bitv::new();
|
||||
/// bv.push(true);
|
||||
/// bv.push(false);
|
||||
/// assert!(bv.eq_vec([true, false]));
|
||||
/// assert!(bv.eq_vec(&[true, false]));
|
||||
/// ```
|
||||
pub fn push(&mut self, elem: bool) {
|
||||
let insert_pos = self.nbits;
|
||||
|
@ -791,11 +791,11 @@ impl Bitv {
|
|||
/// ```
|
||||
/// use std::collections::bitv;
|
||||
///
|
||||
/// let bv = bitv::from_bytes([0b10100000, 0b00010010]);
|
||||
/// assert!(bv.eq_vec([true, false, true, false,
|
||||
/// false, false, false, false,
|
||||
/// false, false, false, true,
|
||||
/// false, false, true, false]));
|
||||
/// let bv = bitv::from_bytes(&[0b10100000, 0b00010010]);
|
||||
/// assert!(bv.eq_vec(&[true, false, true, false,
|
||||
/// false, false, false, false,
|
||||
/// false, false, false, true,
|
||||
/// false, false, true, false]));
|
||||
/// ```
|
||||
pub fn from_bytes(bytes: &[u8]) -> Bitv {
|
||||
from_fn(bytes.len() * 8, |i| {
|
||||
|
@ -814,7 +814,7 @@ pub fn from_bytes(bytes: &[u8]) -> Bitv {
|
|||
/// use std::collections::bitv::from_fn;
|
||||
///
|
||||
/// let bv = from_fn(5, |i| { i % 2 == 0 });
|
||||
/// assert!(bv.eq_vec([true, false, true, false, true]));
|
||||
/// assert!(bv.eq_vec(&[true, false, true, false, true]));
|
||||
/// ```
|
||||
pub fn from_fn(len: uint, f: |index: uint| -> bool) -> Bitv {
|
||||
let mut bitv = Bitv::with_capacity(len, false);
|
||||
|
@ -987,7 +987,7 @@ impl<'a> RandomAccessIterator<bool> for Bits<'a> {
|
|||
/// }
|
||||
///
|
||||
/// // Can initialize from a `Bitv`
|
||||
/// let other = BitvSet::from_bitv(bitv::from_bytes([0b11010000]));
|
||||
/// let other = BitvSet::from_bitv(bitv::from_bytes(&[0b11010000]));
|
||||
///
|
||||
/// s.union_with(&other);
|
||||
///
|
||||
|
@ -1089,7 +1089,7 @@ impl BitvSet {
|
|||
/// ```
|
||||
/// use std::collections::{bitv, BitvSet};
|
||||
///
|
||||
/// let bv = bitv::from_bytes([0b01100000]);
|
||||
/// let bv = bitv::from_bytes(&[0b01100000]);
|
||||
/// let s = BitvSet::from_bitv(bv);
|
||||
///
|
||||
/// // Print 1, 2 in arbitrary order
|
||||
|
@ -1244,7 +1244,7 @@ impl BitvSet {
|
|||
/// use std::collections::BitvSet;
|
||||
/// use std::collections::bitv;
|
||||
///
|
||||
/// let s = BitvSet::from_bitv(bitv::from_bytes([0b01001010]));
|
||||
/// let s = BitvSet::from_bitv(bitv::from_bytes(&[0b01001010]));
|
||||
///
|
||||
/// // Print 1, 4, 6 in arbitrary order
|
||||
/// for x in s.iter() {
|
||||
|
@ -1266,8 +1266,8 @@ impl BitvSet {
|
|||
/// use std::collections::BitvSet;
|
||||
/// use std::collections::bitv;
|
||||
///
|
||||
/// let a = BitvSet::from_bitv(bitv::from_bytes([0b01101000]));
|
||||
/// let b = BitvSet::from_bitv(bitv::from_bytes([0b10100000]));
|
||||
/// let a = BitvSet::from_bitv(bitv::from_bytes(&[0b01101000]));
|
||||
/// let b = BitvSet::from_bitv(bitv::from_bytes(&[0b10100000]));
|
||||
///
|
||||
/// // Print 0, 1, 2, 4 in arbitrary order
|
||||
/// for x in a.union(&b) {
|
||||
|
@ -1295,8 +1295,8 @@ impl BitvSet {
|
|||
/// use std::collections::BitvSet;
|
||||
/// use std::collections::bitv;
|
||||
///
|
||||
/// let a = BitvSet::from_bitv(bitv::from_bytes([0b01101000]));
|
||||
/// let b = BitvSet::from_bitv(bitv::from_bytes([0b10100000]));
|
||||
/// let a = BitvSet::from_bitv(bitv::from_bytes(&[0b01101000]));
|
||||
/// let b = BitvSet::from_bitv(bitv::from_bytes(&[0b10100000]));
|
||||
///
|
||||
/// // Print 2
|
||||
/// for x in a.intersection(&b) {
|
||||
|
@ -1325,8 +1325,8 @@ impl BitvSet {
|
|||
/// use std::collections::BitvSet;
|
||||
/// use std::collections::bitv;
|
||||
///
|
||||
/// let a = BitvSet::from_bitv(bitv::from_bytes([0b01101000]));
|
||||
/// let b = BitvSet::from_bitv(bitv::from_bytes([0b10100000]));
|
||||
/// let a = BitvSet::from_bitv(bitv::from_bytes(&[0b01101000]));
|
||||
/// let b = BitvSet::from_bitv(bitv::from_bytes(&[0b10100000]));
|
||||
///
|
||||
/// // Print 1, 4 in arbitrary order
|
||||
/// for x in a.difference(&b) {
|
||||
|
@ -1362,8 +1362,8 @@ impl BitvSet {
|
|||
/// use std::collections::BitvSet;
|
||||
/// use std::collections::bitv;
|
||||
///
|
||||
/// let a = BitvSet::from_bitv(bitv::from_bytes([0b01101000]));
|
||||
/// let b = BitvSet::from_bitv(bitv::from_bytes([0b10100000]));
|
||||
/// let a = BitvSet::from_bitv(bitv::from_bytes(&[0b01101000]));
|
||||
/// let b = BitvSet::from_bitv(bitv::from_bytes(&[0b10100000]));
|
||||
///
|
||||
/// // Print 0, 1, 4 in arbitrary order
|
||||
/// for x in a.symmetric_difference(&b) {
|
||||
|
@ -1394,9 +1394,9 @@ impl BitvSet {
|
|||
/// let b = 0b10100000;
|
||||
/// let res = 0b11101000;
|
||||
///
|
||||
/// let mut a = BitvSet::from_bitv(bitv::from_bytes([a]));
|
||||
/// let b = BitvSet::from_bitv(bitv::from_bytes([b]));
|
||||
/// let res = BitvSet::from_bitv(bitv::from_bytes([res]));
|
||||
/// let mut a = BitvSet::from_bitv(bitv::from_bytes(&[a]));
|
||||
/// let b = BitvSet::from_bitv(bitv::from_bytes(&[b]));
|
||||
/// let res = BitvSet::from_bitv(bitv::from_bytes(&[res]));
|
||||
///
|
||||
/// a.union_with(&b);
|
||||
/// assert_eq!(a, res);
|
||||
|
@ -1418,9 +1418,9 @@ impl BitvSet {
|
|||
/// let b = 0b10100000;
|
||||
/// let res = 0b00100000;
|
||||
///
|
||||
/// let mut a = BitvSet::from_bitv(bitv::from_bytes([a]));
|
||||
/// let b = BitvSet::from_bitv(bitv::from_bytes([b]));
|
||||
/// let res = BitvSet::from_bitv(bitv::from_bytes([res]));
|
||||
/// let mut a = BitvSet::from_bitv(bitv::from_bytes(&[a]));
|
||||
/// let b = BitvSet::from_bitv(bitv::from_bytes(&[b]));
|
||||
/// let res = BitvSet::from_bitv(bitv::from_bytes(&[res]));
|
||||
///
|
||||
/// a.intersect_with(&b);
|
||||
/// assert_eq!(a, res);
|
||||
|
@ -1444,16 +1444,16 @@ impl BitvSet {
|
|||
/// let a_b = 0b01001000; // a - b
|
||||
/// let b_a = 0b10000000; // b - a
|
||||
///
|
||||
/// let mut bva = BitvSet::from_bitv(bitv::from_bytes([a]));
|
||||
/// let bvb = BitvSet::from_bitv(bitv::from_bytes([b]));
|
||||
/// let bva_b = BitvSet::from_bitv(bitv::from_bytes([a_b]));
|
||||
/// let bvb_a = BitvSet::from_bitv(bitv::from_bytes([b_a]));
|
||||
/// let mut bva = BitvSet::from_bitv(bitv::from_bytes(&[a]));
|
||||
/// let bvb = BitvSet::from_bitv(bitv::from_bytes(&[b]));
|
||||
/// let bva_b = BitvSet::from_bitv(bitv::from_bytes(&[a_b]));
|
||||
/// let bvb_a = BitvSet::from_bitv(bitv::from_bytes(&[b_a]));
|
||||
///
|
||||
/// bva.difference_with(&bvb);
|
||||
/// assert_eq!(bva, bva_b);
|
||||
///
|
||||
/// let bva = BitvSet::from_bitv(bitv::from_bytes([a]));
|
||||
/// let mut bvb = BitvSet::from_bitv(bitv::from_bytes([b]));
|
||||
/// let bva = BitvSet::from_bitv(bitv::from_bytes(&[a]));
|
||||
/// let mut bvb = BitvSet::from_bitv(bitv::from_bytes(&[b]));
|
||||
///
|
||||
/// bvb.difference_with(&bva);
|
||||
/// assert_eq!(bvb, bvb_a);
|
||||
|
@ -1476,9 +1476,9 @@ impl BitvSet {
|
|||
/// let b = 0b10100000;
|
||||
/// let res = 0b11001000;
|
||||
///
|
||||
/// let mut a = BitvSet::from_bitv(bitv::from_bytes([a]));
|
||||
/// let b = BitvSet::from_bitv(bitv::from_bytes([b]));
|
||||
/// let res = BitvSet::from_bitv(bitv::from_bytes([res]));
|
||||
/// let mut a = BitvSet::from_bitv(bitv::from_bytes(&[a]));
|
||||
/// let b = BitvSet::from_bitv(bitv::from_bytes(&[b]));
|
||||
/// let res = BitvSet::from_bitv(bitv::from_bytes(&[res]));
|
||||
///
|
||||
/// a.symmetric_difference_with(&b);
|
||||
/// assert_eq!(a, res);
|
||||
|
@ -1708,9 +1708,9 @@ mod tests {
|
|||
#[test]
|
||||
fn test_1_element() {
|
||||
let mut act = Bitv::with_capacity(1u, false);
|
||||
assert!(act.eq_vec([false]));
|
||||
assert!(act.eq_vec(&[false]));
|
||||
act = Bitv::with_capacity(1u, true);
|
||||
assert!(act.eq_vec([true]));
|
||||
assert!(act.eq_vec(&[true]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1728,11 +1728,11 @@ mod tests {
|
|||
|
||||
act = Bitv::with_capacity(10u, false);
|
||||
assert!((act.eq_vec(
|
||||
[false, false, false, false, false, false, false, false, false, false])));
|
||||
&[false, false, false, false, false, false, false, false, false, false])));
|
||||
// all 1
|
||||
|
||||
act = Bitv::with_capacity(10u, true);
|
||||
assert!((act.eq_vec([true, true, true, true, true, true, true, true, true, true])));
|
||||
assert!((act.eq_vec(&[true, true, true, true, true, true, true, true, true, true])));
|
||||
// mixed
|
||||
|
||||
act = Bitv::with_capacity(10u, false);
|
||||
|
@ -1741,7 +1741,7 @@ mod tests {
|
|||
act.set(2u, true);
|
||||
act.set(3u, true);
|
||||
act.set(4u, true);
|
||||
assert!((act.eq_vec([true, true, true, true, true, false, false, false, false, false])));
|
||||
assert!((act.eq_vec(&[true, true, true, true, true, false, false, false, false, false])));
|
||||
// mixed
|
||||
|
||||
act = Bitv::with_capacity(10u, false);
|
||||
|
@ -1750,7 +1750,7 @@ mod tests {
|
|||
act.set(7u, true);
|
||||
act.set(8u, true);
|
||||
act.set(9u, true);
|
||||
assert!((act.eq_vec([false, false, false, false, false, true, true, true, true, true])));
|
||||
assert!((act.eq_vec(&[false, false, false, false, false, true, true, true, true, true])));
|
||||
// mixed
|
||||
|
||||
act = Bitv::with_capacity(10u, false);
|
||||
|
@ -1758,7 +1758,7 @@ mod tests {
|
|||
act.set(3u, true);
|
||||
act.set(6u, true);
|
||||
act.set(9u, true);
|
||||
assert!((act.eq_vec([true, false, false, true, false, false, true, false, false, true])));
|
||||
assert!((act.eq_vec(&[true, false, false, true, false, false, true, false, false, true])));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1768,16 +1768,16 @@ mod tests {
|
|||
|
||||
act = Bitv::with_capacity(31u, false);
|
||||
assert!(act.eq_vec(
|
||||
[false, false, false, false, false, false, false, false, false, false, false,
|
||||
false, false, false, false, false, false, false, false, false, false, false, false,
|
||||
false, false, false, false, false, false, false, false]));
|
||||
&[false, false, false, false, false, false, false, false, false, false, false,
|
||||
false, false, false, false, false, false, false, false, false, false, false,
|
||||
false, false, false, false, false, false, false, false, false]));
|
||||
// all 1
|
||||
|
||||
act = Bitv::with_capacity(31u, true);
|
||||
assert!(act.eq_vec(
|
||||
[true, true, true, true, true, true, true, true, true, true, true, true, true,
|
||||
true, true, true, true, true, true, true, true, true, true, true, true, true, true,
|
||||
true, true, true, true]));
|
||||
&[true, true, true, true, true, true, true, true, true, true, true, true, true,
|
||||
true, true, true, true, true, true, true, true, true, true, true, true, true,
|
||||
true, true, true, true, true]));
|
||||
// mixed
|
||||
|
||||
act = Bitv::with_capacity(31u, false);
|
||||
|
@ -1790,9 +1790,9 @@ mod tests {
|
|||
act.set(6u, true);
|
||||
act.set(7u, true);
|
||||
assert!(act.eq_vec(
|
||||
[true, true, true, true, true, true, true, true, false, false, false, false, false,
|
||||
false, false, false, false, false, false, false, false, false, false, false, false,
|
||||
false, false, false, false, false, false]));
|
||||
&[true, true, true, true, true, true, true, true, false, false, false, false, false,
|
||||
false, false, false, false, false, false, false, false, false, false, false,
|
||||
false, false, false, false, false, false, false]));
|
||||
// mixed
|
||||
|
||||
act = Bitv::with_capacity(31u, false);
|
||||
|
@ -1805,9 +1805,9 @@ mod tests {
|
|||
act.set(22u, true);
|
||||
act.set(23u, true);
|
||||
assert!(act.eq_vec(
|
||||
[false, false, false, false, false, false, false, false, false, false, false,
|
||||
false, false, false, false, false, true, true, true, true, true, true, true, true,
|
||||
false, false, false, false, false, false, false]));
|
||||
&[false, false, false, false, false, false, false, false, false, false, false,
|
||||
false, false, false, false, false, true, true, true, true, true, true, true, true,
|
||||
false, false, false, false, false, false, false]));
|
||||
// mixed
|
||||
|
||||
act = Bitv::with_capacity(31u, false);
|
||||
|
@ -1819,9 +1819,9 @@ mod tests {
|
|||
act.set(29u, true);
|
||||
act.set(30u, true);
|
||||
assert!(act.eq_vec(
|
||||
[false, false, false, false, false, false, false, false, false, false, false,
|
||||
false, false, false, false, false, false, false, false, false, false, false, false,
|
||||
false, true, true, true, true, true, true, true]));
|
||||
&[false, false, false, false, false, false, false, false, false, false, false,
|
||||
false, false, false, false, false, false, false, false, false, false, false,
|
||||
false, false, true, true, true, true, true, true, true]));
|
||||
// mixed
|
||||
|
||||
act = Bitv::with_capacity(31u, false);
|
||||
|
@ -1829,9 +1829,9 @@ mod tests {
|
|||
act.set(17u, true);
|
||||
act.set(30u, true);
|
||||
assert!(act.eq_vec(
|
||||
[false, false, false, true, false, false, false, false, false, false, false, false,
|
||||
false, false, false, false, false, true, false, false, false, false, false, false,
|
||||
false, false, false, false, false, false, true]));
|
||||
&[false, false, false, true, false, false, false, false, false, false, false, false,
|
||||
false, false, false, false, false, true, false, false, false, false, false, false,
|
||||
false, false, false, false, false, false, true]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1841,16 +1841,16 @@ mod tests {
|
|||
|
||||
act = Bitv::with_capacity(32u, false);
|
||||
assert!(act.eq_vec(
|
||||
[false, false, false, false, false, false, false, false, false, false, false,
|
||||
false, false, false, false, false, false, false, false, false, false, false, false,
|
||||
false, false, false, false, false, false, false, false, false]));
|
||||
&[false, false, false, false, false, false, false, false, false, false, false,
|
||||
false, false, false, false, false, false, false, false, false, false, false,
|
||||
false, false, false, false, false, false, false, false, false, false]));
|
||||
// all 1
|
||||
|
||||
act = Bitv::with_capacity(32u, true);
|
||||
assert!(act.eq_vec(
|
||||
[true, true, true, true, true, true, true, true, true, true, true, true, true,
|
||||
true, true, true, true, true, true, true, true, true, true, true, true, true, true,
|
||||
true, true, true, true, true]));
|
||||
&[true, true, true, true, true, true, true, true, true, true, true, true, true,
|
||||
true, true, true, true, true, true, true, true, true, true, true, true, true,
|
||||
true, true, true, true, true, true]));
|
||||
// mixed
|
||||
|
||||
act = Bitv::with_capacity(32u, false);
|
||||
|
@ -1863,9 +1863,9 @@ mod tests {
|
|||
act.set(6u, true);
|
||||
act.set(7u, true);
|
||||
assert!(act.eq_vec(
|
||||
[true, true, true, true, true, true, true, true, false, false, false, false, false,
|
||||
false, false, false, false, false, false, false, false, false, false, false, false,
|
||||
false, false, false, false, false, false, false]));
|
||||
&[true, true, true, true, true, true, true, true, false, false, false, false, false,
|
||||
false, false, false, false, false, false, false, false, false, false, false,
|
||||
false, false, false, false, false, false, false, false]));
|
||||
// mixed
|
||||
|
||||
act = Bitv::with_capacity(32u, false);
|
||||
|
@ -1878,9 +1878,9 @@ mod tests {
|
|||
act.set(22u, true);
|
||||
act.set(23u, true);
|
||||
assert!(act.eq_vec(
|
||||
[false, false, false, false, false, false, false, false, false, false, false,
|
||||
false, false, false, false, false, true, true, true, true, true, true, true, true,
|
||||
false, false, false, false, false, false, false, false]));
|
||||
&[false, false, false, false, false, false, false, false, false, false, false,
|
||||
false, false, false, false, false, true, true, true, true, true, true, true, true,
|
||||
false, false, false, false, false, false, false, false]));
|
||||
// mixed
|
||||
|
||||
act = Bitv::with_capacity(32u, false);
|
||||
|
@ -1893,9 +1893,9 @@ mod tests {
|
|||
act.set(30u, true);
|
||||
act.set(31u, true);
|
||||
assert!(act.eq_vec(
|
||||
[false, false, false, false, false, false, false, false, false, false, false,
|
||||
false, false, false, false, false, false, false, false, false, false, false, false,
|
||||
false, true, true, true, true, true, true, true, true]));
|
||||
&[false, false, false, false, false, false, false, false, false, false, false,
|
||||
false, false, false, false, false, false, false, false, false, false, false,
|
||||
false, false, true, true, true, true, true, true, true, true]));
|
||||
// mixed
|
||||
|
||||
act = Bitv::with_capacity(32u, false);
|
||||
|
@ -1904,9 +1904,9 @@ mod tests {
|
|||
act.set(30u, true);
|
||||
act.set(31u, true);
|
||||
assert!(act.eq_vec(
|
||||
[false, false, false, true, false, false, false, false, false, false, false, false,
|
||||
false, false, false, false, false, true, false, false, false, false, false, false,
|
||||
false, false, false, false, false, false, true, true]));
|
||||
&[false, false, false, true, false, false, false, false, false, false, false, false,
|
||||
false, false, false, false, false, true, false, false, false, false, false, false,
|
||||
false, false, false, false, false, false, true, true]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1916,16 +1916,16 @@ mod tests {
|
|||
|
||||
act = Bitv::with_capacity(33u, false);
|
||||
assert!(act.eq_vec(
|
||||
[false, false, false, false, false, false, false, false, false, false, false,
|
||||
false, false, false, false, false, false, false, false, false, false, false, false,
|
||||
false, false, false, false, false, false, false, false, false, false]));
|
||||
&[false, false, false, false, false, false, false, false, false, false, false,
|
||||
false, false, false, false, false, false, false, false, false, false, false,
|
||||
false, false, false, false, false, false, false, false, false, false, false]));
|
||||
// all 1
|
||||
|
||||
act = Bitv::with_capacity(33u, true);
|
||||
assert!(act.eq_vec(
|
||||
[true, true, true, true, true, true, true, true, true, true, true, true, true,
|
||||
true, true, true, true, true, true, true, true, true, true, true, true, true, true,
|
||||
true, true, true, true, true, true]));
|
||||
&[true, true, true, true, true, true, true, true, true, true, true, true, true,
|
||||
true, true, true, true, true, true, true, true, true, true, true, true, true,
|
||||
true, true, true, true, true, true, true]));
|
||||
// mixed
|
||||
|
||||
act = Bitv::with_capacity(33u, false);
|
||||
|
@ -1938,9 +1938,9 @@ mod tests {
|
|||
act.set(6u, true);
|
||||
act.set(7u, true);
|
||||
assert!(act.eq_vec(
|
||||
[true, true, true, true, true, true, true, true, false, false, false, false, false,
|
||||
false, false, false, false, false, false, false, false, false, false, false, false,
|
||||
false, false, false, false, false, false, false, false]));
|
||||
&[true, true, true, true, true, true, true, true, false, false, false, false, false,
|
||||
false, false, false, false, false, false, false, false, false, false, false,
|
||||
false, false, false, false, false, false, false, false, false]));
|
||||
// mixed
|
||||
|
||||
act = Bitv::with_capacity(33u, false);
|
||||
|
@ -1953,9 +1953,9 @@ mod tests {
|
|||
act.set(22u, true);
|
||||
act.set(23u, true);
|
||||
assert!(act.eq_vec(
|
||||
[false, false, false, false, false, false, false, false, false, false, false,
|
||||
false, false, false, false, false, true, true, true, true, true, true, true, true,
|
||||
false, false, false, false, false, false, false, false, false]));
|
||||
&[false, false, false, false, false, false, false, false, false, false, false,
|
||||
false, false, false, false, false, true, true, true, true, true, true, true, true,
|
||||
false, false, false, false, false, false, false, false, false]));
|
||||
// mixed
|
||||
|
||||
act = Bitv::with_capacity(33u, false);
|
||||
|
@ -1968,9 +1968,9 @@ mod tests {
|
|||
act.set(30u, true);
|
||||
act.set(31u, true);
|
||||
assert!(act.eq_vec(
|
||||
[false, false, false, false, false, false, false, false, false, false, false,
|
||||
false, false, false, false, false, false, false, false, false, false, false, false,
|
||||
false, true, true, true, true, true, true, true, true, false]));
|
||||
&[false, false, false, false, false, false, false, false, false, false, false,
|
||||
false, false, false, false, false, false, false, false, false, false, false,
|
||||
false, false, true, true, true, true, true, true, true, true, false]));
|
||||
// mixed
|
||||
|
||||
act = Bitv::with_capacity(33u, false);
|
||||
|
@ -1980,9 +1980,9 @@ mod tests {
|
|||
act.set(31u, true);
|
||||
act.set(32u, true);
|
||||
assert!(act.eq_vec(
|
||||
[false, false, false, true, false, false, false, false, false, false, false, false,
|
||||
false, false, false, false, false, true, false, false, false, false, false, false,
|
||||
false, false, false, false, false, false, true, true, true]));
|
||||
&[false, false, false, true, false, false, false, false, false, false, false, false,
|
||||
false, false, false, false, false, true, false, false, false, false, false, false,
|
||||
false, false, false, false, false, false, true, true, true]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2027,7 +2027,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_from_bytes() {
|
||||
let bitv = from_bytes([0b10110110, 0b00000000, 0b11111111]);
|
||||
let bitv = from_bytes(&[0b10110110, 0b00000000, 0b11111111]);
|
||||
let str = format!("{}{}{}", "10110110", "00000000", "11111111");
|
||||
assert_eq!(bitv.to_string().as_slice(), str.as_slice());
|
||||
}
|
||||
|
@ -2065,7 +2065,7 @@ mod tests {
|
|||
#[test]
|
||||
fn test_to_bools() {
|
||||
let bools = vec!(false, false, true, false, false, true, true, false);
|
||||
assert_eq!(from_bytes([0b00100110]).iter().collect::<Vec<bool>>(), bools);
|
||||
assert_eq!(from_bytes(&[0b00100110]).iter().collect::<Vec<bool>>(), bools);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2303,10 +2303,10 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_bitv_set_is_disjoint() {
|
||||
let a = BitvSet::from_bitv(from_bytes([0b10100010]));
|
||||
let b = BitvSet::from_bitv(from_bytes([0b01000000]));
|
||||
let a = BitvSet::from_bitv(from_bytes(&[0b10100010]));
|
||||
let b = BitvSet::from_bitv(from_bytes(&[0b01000000]));
|
||||
let c = BitvSet::new();
|
||||
let d = BitvSet::from_bitv(from_bytes([0b00110000]));
|
||||
let d = BitvSet::from_bitv(from_bytes(&[0b00110000]));
|
||||
|
||||
assert!(!a.is_disjoint(&d));
|
||||
assert!(!d.is_disjoint(&a));
|
||||
|
@ -2326,13 +2326,13 @@ mod tests {
|
|||
a.insert(0);
|
||||
let mut b = BitvSet::new();
|
||||
b.insert(5);
|
||||
let expected = BitvSet::from_bitv(from_bytes([0b10000100]));
|
||||
let expected = BitvSet::from_bitv(from_bytes(&[0b10000100]));
|
||||
a.union_with(&b);
|
||||
assert_eq!(a, expected);
|
||||
|
||||
// Standard
|
||||
let mut a = BitvSet::from_bitv(from_bytes([0b10100010]));
|
||||
let mut b = BitvSet::from_bitv(from_bytes([0b01100010]));
|
||||
let mut a = BitvSet::from_bitv(from_bytes(&[0b10100010]));
|
||||
let mut b = BitvSet::from_bitv(from_bytes(&[0b01100010]));
|
||||
let c = a.clone();
|
||||
a.union_with(&b);
|
||||
b.union_with(&c);
|
||||
|
@ -2343,8 +2343,8 @@ mod tests {
|
|||
#[test]
|
||||
fn test_bitv_set_intersect_with() {
|
||||
// Explicitly 0'ed bits
|
||||
let mut a = BitvSet::from_bitv(from_bytes([0b10100010]));
|
||||
let mut b = BitvSet::from_bitv(from_bytes([0b00000000]));
|
||||
let mut a = BitvSet::from_bitv(from_bytes(&[0b10100010]));
|
||||
let mut b = BitvSet::from_bitv(from_bytes(&[0b00000000]));
|
||||
let c = a.clone();
|
||||
a.intersect_with(&b);
|
||||
b.intersect_with(&c);
|
||||
|
@ -2352,7 +2352,7 @@ mod tests {
|
|||
assert!(b.is_empty());
|
||||
|
||||
// Uninitialized bits should behave like 0's
|
||||
let mut a = BitvSet::from_bitv(from_bytes([0b10100010]));
|
||||
let mut a = BitvSet::from_bitv(from_bytes(&[0b10100010]));
|
||||
let mut b = BitvSet::new();
|
||||
let c = a.clone();
|
||||
a.intersect_with(&b);
|
||||
|
@ -2361,8 +2361,8 @@ mod tests {
|
|||
assert!(b.is_empty());
|
||||
|
||||
// Standard
|
||||
let mut a = BitvSet::from_bitv(from_bytes([0b10100010]));
|
||||
let mut b = BitvSet::from_bitv(from_bytes([0b01100010]));
|
||||
let mut a = BitvSet::from_bitv(from_bytes(&[0b10100010]));
|
||||
let mut b = BitvSet::from_bitv(from_bytes(&[0b01100010]));
|
||||
let c = a.clone();
|
||||
a.intersect_with(&b);
|
||||
b.intersect_with(&c);
|
||||
|
@ -2373,20 +2373,20 @@ mod tests {
|
|||
#[test]
|
||||
fn test_bitv_set_difference_with() {
|
||||
// Explicitly 0'ed bits
|
||||
let mut a = BitvSet::from_bitv(from_bytes([0b00000000]));
|
||||
let b = BitvSet::from_bitv(from_bytes([0b10100010]));
|
||||
let mut a = BitvSet::from_bitv(from_bytes(&[0b00000000]));
|
||||
let b = BitvSet::from_bitv(from_bytes(&[0b10100010]));
|
||||
a.difference_with(&b);
|
||||
assert!(a.is_empty());
|
||||
|
||||
// Uninitialized bits should behave like 0's
|
||||
let mut a = BitvSet::new();
|
||||
let b = BitvSet::from_bitv(from_bytes([0b11111111]));
|
||||
let b = BitvSet::from_bitv(from_bytes(&[0b11111111]));
|
||||
a.difference_with(&b);
|
||||
assert!(a.is_empty());
|
||||
|
||||
// Standard
|
||||
let mut a = BitvSet::from_bitv(from_bytes([0b10100010]));
|
||||
let mut b = BitvSet::from_bitv(from_bytes([0b01100010]));
|
||||
let mut a = BitvSet::from_bitv(from_bytes(&[0b10100010]));
|
||||
let mut b = BitvSet::from_bitv(from_bytes(&[0b01100010]));
|
||||
let c = a.clone();
|
||||
a.difference_with(&b);
|
||||
b.difference_with(&c);
|
||||
|
@ -2403,19 +2403,19 @@ mod tests {
|
|||
let mut b = BitvSet::new();
|
||||
b.insert(1);
|
||||
b.insert(5);
|
||||
let expected = BitvSet::from_bitv(from_bytes([0b10000100]));
|
||||
let expected = BitvSet::from_bitv(from_bytes(&[0b10000100]));
|
||||
a.symmetric_difference_with(&b);
|
||||
assert_eq!(a, expected);
|
||||
|
||||
let mut a = BitvSet::from_bitv(from_bytes([0b10100010]));
|
||||
let mut a = BitvSet::from_bitv(from_bytes(&[0b10100010]));
|
||||
let b = BitvSet::new();
|
||||
let c = a.clone();
|
||||
a.symmetric_difference_with(&b);
|
||||
assert_eq!(a, c);
|
||||
|
||||
// Standard
|
||||
let mut a = BitvSet::from_bitv(from_bytes([0b11100010]));
|
||||
let mut b = BitvSet::from_bitv(from_bytes([0b01101010]));
|
||||
let mut a = BitvSet::from_bitv(from_bytes(&[0b11100010]));
|
||||
let mut b = BitvSet::from_bitv(from_bytes(&[0b01101010]));
|
||||
let c = a.clone();
|
||||
a.symmetric_difference_with(&b);
|
||||
b.symmetric_difference_with(&c);
|
||||
|
@ -2425,8 +2425,8 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_bitv_set_eq() {
|
||||
let a = BitvSet::from_bitv(from_bytes([0b10100010]));
|
||||
let b = BitvSet::from_bitv(from_bytes([0b00000000]));
|
||||
let a = BitvSet::from_bitv(from_bytes(&[0b10100010]));
|
||||
let b = BitvSet::from_bitv(from_bytes(&[0b00000000]));
|
||||
let c = BitvSet::new();
|
||||
|
||||
assert!(a == a);
|
||||
|
@ -2439,8 +2439,8 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_bitv_set_cmp() {
|
||||
let a = BitvSet::from_bitv(from_bytes([0b10100010]));
|
||||
let b = BitvSet::from_bitv(from_bytes([0b00000000]));
|
||||
let a = BitvSet::from_bitv(from_bytes(&[0b10100010]));
|
||||
let b = BitvSet::from_bitv(from_bytes(&[0b00000000]));
|
||||
let c = BitvSet::new();
|
||||
|
||||
assert_eq!(a.cmp(&b), Greater);
|
||||
|
@ -2519,17 +2519,17 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_small_bitv_tests() {
|
||||
let v = from_bytes([0]);
|
||||
let v = from_bytes(&[0]);
|
||||
assert!(!v.all());
|
||||
assert!(!v.any());
|
||||
assert!(v.none());
|
||||
|
||||
let v = from_bytes([0b00010100]);
|
||||
let v = from_bytes(&[0b00010100]);
|
||||
assert!(!v.all());
|
||||
assert!(v.any());
|
||||
assert!(!v.none());
|
||||
|
||||
let v = from_bytes([0xFF]);
|
||||
let v = from_bytes(&[0xFF]);
|
||||
assert!(v.all());
|
||||
assert!(v.any());
|
||||
assert!(!v.none());
|
||||
|
@ -2537,7 +2537,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_big_bitv_tests() {
|
||||
let v = from_bytes([ // 88 bits
|
||||
let v = from_bytes(&[ // 88 bits
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0]);
|
||||
|
@ -2545,7 +2545,7 @@ mod tests {
|
|||
assert!(!v.any());
|
||||
assert!(v.none());
|
||||
|
||||
let v = from_bytes([ // 88 bits
|
||||
let v = from_bytes(&[ // 88 bits
|
||||
0, 0, 0b00010100, 0,
|
||||
0, 0, 0, 0b00110100,
|
||||
0, 0, 0]);
|
||||
|
@ -2553,7 +2553,7 @@ mod tests {
|
|||
assert!(v.any());
|
||||
assert!(!v.none());
|
||||
|
||||
let v = from_bytes([ // 88 bits
|
||||
let v = from_bytes(&[ // 88 bits
|
||||
0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF]);
|
||||
|
@ -2632,24 +2632,24 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_bitv_grow() {
|
||||
let mut bitv = from_bytes([0b10110110, 0b00000000, 0b10101010]);
|
||||
let mut bitv = from_bytes(&[0b10110110, 0b00000000, 0b10101010]);
|
||||
bitv.grow(32, true);
|
||||
assert_eq!(bitv, from_bytes([0b10110110, 0b00000000, 0b10101010,
|
||||
assert_eq!(bitv, from_bytes(&[0b10110110, 0b00000000, 0b10101010,
|
||||
0xFF, 0xFF, 0xFF, 0xFF]));
|
||||
bitv.grow(64, false);
|
||||
assert_eq!(bitv, from_bytes([0b10110110, 0b00000000, 0b10101010,
|
||||
assert_eq!(bitv, from_bytes(&[0b10110110, 0b00000000, 0b10101010,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0, 0, 0, 0, 0, 0, 0, 0]));
|
||||
bitv.grow(16, true);
|
||||
assert_eq!(bitv, from_bytes([0b10110110, 0b00000000, 0b10101010,
|
||||
assert_eq!(bitv, from_bytes(&[0b10110110, 0b00000000, 0b10101010,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_bitv_extend() {
|
||||
let mut bitv = from_bytes([0b10110110, 0b00000000, 0b11111111]);
|
||||
let ext = from_bytes([0b01001001, 0b10010010, 0b10111101]);
|
||||
let mut bitv = from_bytes(&[0b10110110, 0b00000000, 0b11111111]);
|
||||
let ext = from_bytes(&[0b01001001, 0b10010010, 0b10111101]);
|
||||
bitv.extend(ext.iter());
|
||||
assert_eq!(bitv, from_bytes([0b10110110, 0b00000000, 0b11111111,
|
||||
assert_eq!(bitv, from_bytes(&[0b10110110, 0b00000000, 0b11111111,
|
||||
0b01001001, 0b10010010, 0b10111101]));
|
||||
}
|
||||
|
||||
|
|
|
@ -467,14 +467,14 @@ mod test {
|
|||
check(a, b, expected, |x, y, f| x.intersection(y).all(f))
|
||||
}
|
||||
|
||||
check_intersection([], [], []);
|
||||
check_intersection([1, 2, 3], [], []);
|
||||
check_intersection([], [1, 2, 3], []);
|
||||
check_intersection([2], [1, 2, 3], [2]);
|
||||
check_intersection([1, 2, 3], [2], [2]);
|
||||
check_intersection([11, 1, 3, 77, 103, 5, -5],
|
||||
[2, 11, 77, -9, -42, 5, 3],
|
||||
[3, 5, 11, 77]);
|
||||
check_intersection(&[], &[], &[]);
|
||||
check_intersection(&[1, 2, 3], &[], &[]);
|
||||
check_intersection(&[], &[1, 2, 3], &[]);
|
||||
check_intersection(&[2], &[1, 2, 3], &[2]);
|
||||
check_intersection(&[1, 2, 3], &[2], &[2]);
|
||||
check_intersection(&[11, 1, 3, 77, 103, 5, -5],
|
||||
&[2, 11, 77, -9, -42, 5, 3],
|
||||
&[3, 5, 11, 77]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -483,15 +483,15 @@ mod test {
|
|||
check(a, b, expected, |x, y, f| x.difference(y).all(f))
|
||||
}
|
||||
|
||||
check_difference([], [], []);
|
||||
check_difference([1, 12], [], [1, 12]);
|
||||
check_difference([], [1, 2, 3, 9], []);
|
||||
check_difference([1, 3, 5, 9, 11],
|
||||
[3, 9],
|
||||
[1, 5, 11]);
|
||||
check_difference([-5, 11, 22, 33, 40, 42],
|
||||
[-12, -5, 14, 23, 34, 38, 39, 50],
|
||||
[11, 22, 33, 40, 42]);
|
||||
check_difference(&[], &[], &[]);
|
||||
check_difference(&[1, 12], &[], &[1, 12]);
|
||||
check_difference(&[], &[1, 2, 3, 9], &[]);
|
||||
check_difference(&[1, 3, 5, 9, 11],
|
||||
&[3, 9],
|
||||
&[1, 5, 11]);
|
||||
check_difference(&[-5, 11, 22, 33, 40, 42],
|
||||
&[-12, -5, 14, 23, 34, 38, 39, 50],
|
||||
&[11, 22, 33, 40, 42]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -501,12 +501,12 @@ mod test {
|
|||
check(a, b, expected, |x, y, f| x.symmetric_difference(y).all(f))
|
||||
}
|
||||
|
||||
check_symmetric_difference([], [], []);
|
||||
check_symmetric_difference([1, 2, 3], [2], [1, 3]);
|
||||
check_symmetric_difference([2], [1, 2, 3], [1, 3]);
|
||||
check_symmetric_difference([1, 3, 5, 9, 11],
|
||||
[-2, 3, 9, 14, 22],
|
||||
[-2, 1, 5, 11, 14, 22]);
|
||||
check_symmetric_difference(&[], &[], &[]);
|
||||
check_symmetric_difference(&[1, 2, 3], &[2], &[1, 3]);
|
||||
check_symmetric_difference(&[2], &[1, 2, 3], &[1, 3]);
|
||||
check_symmetric_difference(&[1, 3, 5, 9, 11],
|
||||
&[-2, 3, 9, 14, 22],
|
||||
&[-2, 1, 5, 11, 14, 22]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -516,12 +516,12 @@ mod test {
|
|||
check(a, b, expected, |x, y, f| x.union(y).all(f))
|
||||
}
|
||||
|
||||
check_union([], [], []);
|
||||
check_union([1, 2, 3], [2], [1, 2, 3]);
|
||||
check_union([2], [1, 2, 3], [1, 2, 3]);
|
||||
check_union([1, 3, 5, 9, 11, 16, 19, 24],
|
||||
[-2, 1, 5, 9, 13, 19],
|
||||
[-2, 1, 3, 5, 9, 11, 13, 16, 19, 24]);
|
||||
check_union(&[], &[], &[]);
|
||||
check_union(&[1, 2, 3], &[2], &[1, 2, 3]);
|
||||
check_union(&[2], &[1, 2, 3], &[1, 2, 3]);
|
||||
check_union(&[1, 3, 5, 9, 11, 16, 19, 24],
|
||||
&[-2, 1, 5, 9, 13, 19],
|
||||
&[-2, 1, 3, 5, 9, 11, 13, 16, 19, 24]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -1088,8 +1088,8 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_merge() {
|
||||
let mut m = list_from([0i, 1, 3, 5, 6, 7, 2]);
|
||||
let n = list_from([-1i, 0, 0, 7, 7, 9]);
|
||||
let mut m = list_from(&[0i, 1, 3, 5, 6, 7, 2]);
|
||||
let n = list_from(&[-1i, 0, 0, 7, 7, 9]);
|
||||
let len = m.len() + n.len();
|
||||
m.merge(n, |a, b| a <= b);
|
||||
assert_eq!(m.len(), len);
|
||||
|
@ -1129,7 +1129,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_send() {
|
||||
let n = list_from([1i,2,3]);
|
||||
let n = list_from(&[1i,2,3]);
|
||||
spawn(proc() {
|
||||
check_links(&n);
|
||||
let a: &[_] = &[&1,&2,&3];
|
||||
|
@ -1139,16 +1139,16 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_eq() {
|
||||
let mut n: DList<u8> = list_from([]);
|
||||
let mut m = list_from([]);
|
||||
let mut n: DList<u8> = list_from(&[]);
|
||||
let mut m = list_from(&[]);
|
||||
assert!(n == m);
|
||||
n.push_front(1);
|
||||
assert!(n != m);
|
||||
m.push_back(1);
|
||||
assert!(n == m);
|
||||
|
||||
let n = list_from([2i,3,4]);
|
||||
let m = list_from([1i,2,3]);
|
||||
let n = list_from(&[2i,3,4]);
|
||||
let m = list_from(&[1i,2,3]);
|
||||
assert!(n != m);
|
||||
}
|
||||
|
||||
|
@ -1172,8 +1172,8 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_ord() {
|
||||
let n: DList<int> = list_from([]);
|
||||
let m = list_from([1i,2,3]);
|
||||
let n: DList<int> = list_from(&[]);
|
||||
let m = list_from(&[1i,2,3]);
|
||||
assert!(n < m);
|
||||
assert!(m > n);
|
||||
assert!(n <= n);
|
||||
|
@ -1183,29 +1183,29 @@ mod tests {
|
|||
#[test]
|
||||
fn test_ord_nan() {
|
||||
let nan = 0.0f64/0.0;
|
||||
let n = list_from([nan]);
|
||||
let m = list_from([nan]);
|
||||
let n = list_from(&[nan]);
|
||||
let m = list_from(&[nan]);
|
||||
assert!(!(n < m));
|
||||
assert!(!(n > m));
|
||||
assert!(!(n <= m));
|
||||
assert!(!(n >= m));
|
||||
|
||||
let n = list_from([nan]);
|
||||
let one = list_from([1.0f64]);
|
||||
let n = list_from(&[nan]);
|
||||
let one = list_from(&[1.0f64]);
|
||||
assert!(!(n < one));
|
||||
assert!(!(n > one));
|
||||
assert!(!(n <= one));
|
||||
assert!(!(n >= one));
|
||||
|
||||
let u = list_from([1.0f64,2.0,nan]);
|
||||
let v = list_from([1.0f64,2.0,3.0]);
|
||||
let u = list_from(&[1.0f64,2.0,nan]);
|
||||
let v = list_from(&[1.0f64,2.0,3.0]);
|
||||
assert!(!(u < v));
|
||||
assert!(!(u > v));
|
||||
assert!(!(u <= v));
|
||||
assert!(!(u >= v));
|
||||
|
||||
let s = list_from([1.0f64,2.0,4.0,2.0]);
|
||||
let t = list_from([1.0f64,2.0,3.0,2.0]);
|
||||
let s = list_from(&[1.0f64,2.0,4.0,2.0]);
|
||||
let t = list_from(&[1.0f64,2.0,3.0,2.0]);
|
||||
assert!(!(s < t));
|
||||
assert!(s > one);
|
||||
assert!(!(s <= one));
|
||||
|
|
|
@ -151,7 +151,7 @@ macro_rules! impl_hash_tuple(
|
|||
impl<S: Writer> Hash<S> for () {
|
||||
#[inline]
|
||||
fn hash(&self, state: &mut S) {
|
||||
state.write([]);
|
||||
state.write(&[]);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
|
@ -414,7 +414,7 @@ mod tests {
|
|||
assert_eq!(f, v);
|
||||
|
||||
buf.push(t as u8);
|
||||
state_inc.write([t as u8]);
|
||||
state_inc.write(&[t as u8]);
|
||||
|
||||
t += 1;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
//! let vec = vec!(1i, 2, 3);
|
||||
//! let int_slice = vec.as_slice();
|
||||
//! // coercing an array to a slice
|
||||
//! let str_slice: &[&str] = ["one", "two", "three"];
|
||||
//! let str_slice: &[&str] = &["one", "two", "three"];
|
||||
//! ```
|
||||
//!
|
||||
//! Slices are either mutable or shared. The shared slice type is `&[T]`,
|
||||
|
@ -26,7 +26,7 @@
|
|||
//! block of memory that a mutable slice points to:
|
||||
//!
|
||||
//! ```rust
|
||||
//! let x: &mut[int] = [1i, 2, 3];
|
||||
//! let x: &mut[int] = &mut [1i, 2, 3];
|
||||
//! x[1] = 7;
|
||||
//! assert_eq!(x[0], 1);
|
||||
//! assert_eq!(x[1], 7);
|
||||
|
@ -1962,7 +1962,7 @@ mod tests {
|
|||
assert!(!b"foo".starts_with(b"foobar"));
|
||||
assert!(!b"bar".starts_with(b"foobar"));
|
||||
assert!(b"foobar".starts_with(b"foobar"));
|
||||
let empty: &[u8] = [];
|
||||
let empty: &[u8] = &[];
|
||||
assert!(empty.starts_with(empty));
|
||||
assert!(!empty.starts_with(b"foo"));
|
||||
assert!(b"foobar".starts_with(empty));
|
||||
|
@ -1976,7 +1976,7 @@ mod tests {
|
|||
assert!(!b"foo".ends_with(b"foobar"));
|
||||
assert!(!b"bar".ends_with(b"foobar"));
|
||||
assert!(b"foobar".ends_with(b"foobar"));
|
||||
let empty: &[u8] = [];
|
||||
let empty: &[u8] = &[];
|
||||
assert!(empty.ends_with(empty));
|
||||
assert!(!empty.ends_with(b"foo"));
|
||||
assert!(b"foobar".ends_with(empty));
|
||||
|
@ -2054,7 +2054,7 @@ mod tests {
|
|||
let h = x.last_mut();
|
||||
assert_eq!(*h.unwrap(), 5);
|
||||
|
||||
let y: &mut [int] = [];
|
||||
let y: &mut [int] = &mut [];
|
||||
assert!(y.last_mut().is_none());
|
||||
}
|
||||
|
||||
|
|
|
@ -923,13 +923,13 @@ mod tests {
|
|||
fn t(v: &[String], s: &str) {
|
||||
assert_eq!(v.concat().as_slice(), s);
|
||||
}
|
||||
t([String::from_str("you"), String::from_str("know"),
|
||||
String::from_str("I'm"),
|
||||
String::from_str("no"), String::from_str("good")],
|
||||
t(&[String::from_str("you"), String::from_str("know"),
|
||||
String::from_str("I'm"),
|
||||
String::from_str("no"), String::from_str("good")],
|
||||
"youknowI'mnogood");
|
||||
let v: &[String] = [];
|
||||
let v: &[String] = &[];
|
||||
t(v, "");
|
||||
t([String::from_str("hi")], "hi");
|
||||
t(&[String::from_str("hi")], "hi");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -937,13 +937,13 @@ mod tests {
|
|||
fn t(v: &[String], sep: &str, s: &str) {
|
||||
assert_eq!(v.connect(sep).as_slice(), s);
|
||||
}
|
||||
t([String::from_str("you"), String::from_str("know"),
|
||||
String::from_str("I'm"),
|
||||
String::from_str("no"), String::from_str("good")],
|
||||
t(&[String::from_str("you"), String::from_str("know"),
|
||||
String::from_str("I'm"),
|
||||
String::from_str("no"), String::from_str("good")],
|
||||
" ", "you know I'm no good");
|
||||
let v: &[String] = [];
|
||||
let v: &[String] = &[];
|
||||
t(v, " ", "");
|
||||
t([String::from_str("hi")], " ", "hi");
|
||||
t(&[String::from_str("hi")], " ", "hi");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -951,10 +951,10 @@ mod tests {
|
|||
fn t(v: &[&str], s: &str) {
|
||||
assert_eq!(v.concat().as_slice(), s);
|
||||
}
|
||||
t(["you", "know", "I'm", "no", "good"], "youknowI'mnogood");
|
||||
let v: &[&str] = [];
|
||||
t(&["you", "know", "I'm", "no", "good"], "youknowI'mnogood");
|
||||
let v: &[&str] = &[];
|
||||
t(v, "");
|
||||
t(["hi"], "hi");
|
||||
t(&["hi"], "hi");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -962,10 +962,10 @@ mod tests {
|
|||
fn t(v: &[&str], sep: &str, s: &str) {
|
||||
assert_eq!(v.connect(sep).as_slice(), s);
|
||||
}
|
||||
t(["you", "know", "I'm", "no", "good"],
|
||||
t(&["you", "know", "I'm", "no", "good"],
|
||||
" ", "you know I'm no good");
|
||||
t([], " ", "");
|
||||
t(["hi"], " ", "hi");
|
||||
t(&[], " ", "");
|
||||
t(&["hi"], " ", "hi");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1266,26 +1266,26 @@ mod tests {
|
|||
#[test]
|
||||
fn test_is_utf8() {
|
||||
// deny overlong encodings
|
||||
assert!(!is_utf8([0xc0, 0x80]));
|
||||
assert!(!is_utf8([0xc0, 0xae]));
|
||||
assert!(!is_utf8([0xe0, 0x80, 0x80]));
|
||||
assert!(!is_utf8([0xe0, 0x80, 0xaf]));
|
||||
assert!(!is_utf8([0xe0, 0x81, 0x81]));
|
||||
assert!(!is_utf8([0xf0, 0x82, 0x82, 0xac]));
|
||||
assert!(!is_utf8([0xf4, 0x90, 0x80, 0x80]));
|
||||
assert!(!is_utf8(&[0xc0, 0x80]));
|
||||
assert!(!is_utf8(&[0xc0, 0xae]));
|
||||
assert!(!is_utf8(&[0xe0, 0x80, 0x80]));
|
||||
assert!(!is_utf8(&[0xe0, 0x80, 0xaf]));
|
||||
assert!(!is_utf8(&[0xe0, 0x81, 0x81]));
|
||||
assert!(!is_utf8(&[0xf0, 0x82, 0x82, 0xac]));
|
||||
assert!(!is_utf8(&[0xf4, 0x90, 0x80, 0x80]));
|
||||
|
||||
// deny surrogates
|
||||
assert!(!is_utf8([0xED, 0xA0, 0x80]));
|
||||
assert!(!is_utf8([0xED, 0xBF, 0xBF]));
|
||||
assert!(!is_utf8(&[0xED, 0xA0, 0x80]));
|
||||
assert!(!is_utf8(&[0xED, 0xBF, 0xBF]));
|
||||
|
||||
assert!(is_utf8([0xC2, 0x80]));
|
||||
assert!(is_utf8([0xDF, 0xBF]));
|
||||
assert!(is_utf8([0xE0, 0xA0, 0x80]));
|
||||
assert!(is_utf8([0xED, 0x9F, 0xBF]));
|
||||
assert!(is_utf8([0xEE, 0x80, 0x80]));
|
||||
assert!(is_utf8([0xEF, 0xBF, 0xBF]));
|
||||
assert!(is_utf8([0xF0, 0x90, 0x80, 0x80]));
|
||||
assert!(is_utf8([0xF4, 0x8F, 0xBF, 0xBF]));
|
||||
assert!(is_utf8(&[0xC2, 0x80]));
|
||||
assert!(is_utf8(&[0xDF, 0xBF]));
|
||||
assert!(is_utf8(&[0xE0, 0xA0, 0x80]));
|
||||
assert!(is_utf8(&[0xED, 0x9F, 0xBF]));
|
||||
assert!(is_utf8(&[0xEE, 0x80, 0x80]));
|
||||
assert!(is_utf8(&[0xEF, 0xBF, 0xBF]));
|
||||
assert!(is_utf8(&[0xF0, 0x90, 0x80, 0x80]));
|
||||
assert!(is_utf8(&[0xF4, 0x8F, 0xBF, 0xBF]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1293,58 +1293,58 @@ mod tests {
|
|||
macro_rules! pos ( ($($e:expr),*) => { { $(assert!(is_utf16($e));)* } });
|
||||
|
||||
// non-surrogates
|
||||
pos!([0x0000],
|
||||
[0x0001, 0x0002],
|
||||
[0xD7FF],
|
||||
[0xE000]);
|
||||
pos!(&[0x0000],
|
||||
&[0x0001, 0x0002],
|
||||
&[0xD7FF],
|
||||
&[0xE000]);
|
||||
|
||||
// surrogate pairs (randomly generated with Python 3's
|
||||
// .encode('utf-16be'))
|
||||
pos!([0xdb54, 0xdf16, 0xd880, 0xdee0, 0xdb6a, 0xdd45],
|
||||
[0xd91f, 0xdeb1, 0xdb31, 0xdd84, 0xd8e2, 0xde14],
|
||||
[0xdb9f, 0xdc26, 0xdb6f, 0xde58, 0xd850, 0xdfae]);
|
||||
pos!(&[0xdb54, 0xdf16, 0xd880, 0xdee0, 0xdb6a, 0xdd45],
|
||||
&[0xd91f, 0xdeb1, 0xdb31, 0xdd84, 0xd8e2, 0xde14],
|
||||
&[0xdb9f, 0xdc26, 0xdb6f, 0xde58, 0xd850, 0xdfae]);
|
||||
|
||||
// mixtures (also random)
|
||||
pos!([0xd921, 0xdcc2, 0x002d, 0x004d, 0xdb32, 0xdf65],
|
||||
[0xdb45, 0xdd2d, 0x006a, 0xdacd, 0xddfe, 0x0006],
|
||||
[0x0067, 0xd8ff, 0xddb7, 0x000f, 0xd900, 0xdc80]);
|
||||
pos!(&[0xd921, 0xdcc2, 0x002d, 0x004d, 0xdb32, 0xdf65],
|
||||
&[0xdb45, 0xdd2d, 0x006a, 0xdacd, 0xddfe, 0x0006],
|
||||
&[0x0067, 0xd8ff, 0xddb7, 0x000f, 0xd900, 0xdc80]);
|
||||
|
||||
// negative tests
|
||||
macro_rules! neg ( ($($e:expr),*) => { { $(assert!(!is_utf16($e));)* } });
|
||||
|
||||
neg!(
|
||||
// surrogate + regular unit
|
||||
[0xdb45, 0x0000],
|
||||
&[0xdb45, 0x0000],
|
||||
// surrogate + lead surrogate
|
||||
[0xd900, 0xd900],
|
||||
&[0xd900, 0xd900],
|
||||
// unterminated surrogate
|
||||
[0xd8ff],
|
||||
&[0xd8ff],
|
||||
// trail surrogate without a lead
|
||||
[0xddb7]);
|
||||
&[0xddb7]);
|
||||
|
||||
// random byte sequences that Python 3's .decode('utf-16be')
|
||||
// failed on
|
||||
neg!([0x5b3d, 0x0141, 0xde9e, 0x8fdc, 0xc6e7],
|
||||
[0xdf5a, 0x82a5, 0x62b9, 0xb447, 0x92f3],
|
||||
[0xda4e, 0x42bc, 0x4462, 0xee98, 0xc2ca],
|
||||
[0xbe00, 0xb04a, 0x6ecb, 0xdd89, 0xe278],
|
||||
[0x0465, 0xab56, 0xdbb6, 0xa893, 0x665e],
|
||||
[0x6b7f, 0x0a19, 0x40f4, 0xa657, 0xdcc5],
|
||||
[0x9b50, 0xda5e, 0x24ec, 0x03ad, 0x6dee],
|
||||
[0x8d17, 0xcaa7, 0xf4ae, 0xdf6e, 0xbed7],
|
||||
[0xdaee, 0x2584, 0x7d30, 0xa626, 0x121a],
|
||||
[0xd956, 0x4b43, 0x7570, 0xccd6, 0x4f4a],
|
||||
[0x9dcf, 0x1b49, 0x4ba5, 0xfce9, 0xdffe],
|
||||
[0x6572, 0xce53, 0xb05a, 0xf6af, 0xdacf],
|
||||
[0x1b90, 0x728c, 0x9906, 0xdb68, 0xf46e],
|
||||
[0x1606, 0xbeca, 0xbe76, 0x860f, 0xdfa5],
|
||||
[0x8b4f, 0xde7a, 0xd220, 0x9fac, 0x2b6f],
|
||||
[0xb8fe, 0xebbe, 0xda32, 0x1a5f, 0x8b8b],
|
||||
[0x934b, 0x8956, 0xc434, 0x1881, 0xddf7],
|
||||
[0x5a95, 0x13fc, 0xf116, 0xd89b, 0x93f9],
|
||||
[0xd640, 0x71f1, 0xdd7d, 0x77eb, 0x1cd8],
|
||||
[0x348b, 0xaef0, 0xdb2c, 0xebf1, 0x1282],
|
||||
[0x50d7, 0xd824, 0x5010, 0xb369, 0x22ea]);
|
||||
neg!(&[0x5b3d, 0x0141, 0xde9e, 0x8fdc, 0xc6e7],
|
||||
&[0xdf5a, 0x82a5, 0x62b9, 0xb447, 0x92f3],
|
||||
&[0xda4e, 0x42bc, 0x4462, 0xee98, 0xc2ca],
|
||||
&[0xbe00, 0xb04a, 0x6ecb, 0xdd89, 0xe278],
|
||||
&[0x0465, 0xab56, 0xdbb6, 0xa893, 0x665e],
|
||||
&[0x6b7f, 0x0a19, 0x40f4, 0xa657, 0xdcc5],
|
||||
&[0x9b50, 0xda5e, 0x24ec, 0x03ad, 0x6dee],
|
||||
&[0x8d17, 0xcaa7, 0xf4ae, 0xdf6e, 0xbed7],
|
||||
&[0xdaee, 0x2584, 0x7d30, 0xa626, 0x121a],
|
||||
&[0xd956, 0x4b43, 0x7570, 0xccd6, 0x4f4a],
|
||||
&[0x9dcf, 0x1b49, 0x4ba5, 0xfce9, 0xdffe],
|
||||
&[0x6572, 0xce53, 0xb05a, 0xf6af, 0xdacf],
|
||||
&[0x1b90, 0x728c, 0x9906, 0xdb68, 0xf46e],
|
||||
&[0x1606, 0xbeca, 0xbe76, 0x860f, 0xdfa5],
|
||||
&[0x8b4f, 0xde7a, 0xd220, 0x9fac, 0x2b6f],
|
||||
&[0xb8fe, 0xebbe, 0xda32, 0x1a5f, 0x8b8b],
|
||||
&[0x934b, 0x8956, 0xc434, 0x1881, 0xddf7],
|
||||
&[0x5a95, 0x13fc, 0xf116, 0xd89b, 0x93f9],
|
||||
&[0xd640, 0x71f1, 0xdd7d, 0x77eb, 0x1cd8],
|
||||
&[0x348b, 0xaef0, 0xdb2c, 0xebf1, 0x1282],
|
||||
&[0x50d7, 0xd824, 0x5010, 0xb369, 0x22ea]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1456,22 +1456,22 @@ mod tests {
|
|||
fn test_truncate_utf16_at_nul() {
|
||||
let v = [];
|
||||
let b: &[u16] = &[];
|
||||
assert_eq!(truncate_utf16_at_nul(v), b);
|
||||
assert_eq!(truncate_utf16_at_nul(&v), b);
|
||||
|
||||
let v = [0, 2, 3];
|
||||
assert_eq!(truncate_utf16_at_nul(v), b);
|
||||
assert_eq!(truncate_utf16_at_nul(&v), b);
|
||||
|
||||
let v = [1, 0, 3];
|
||||
let b: &[u16] = &[1];
|
||||
assert_eq!(truncate_utf16_at_nul(v), b);
|
||||
assert_eq!(truncate_utf16_at_nul(&v), b);
|
||||
|
||||
let v = [1, 2, 0];
|
||||
let b: &[u16] = &[1, 2];
|
||||
assert_eq!(truncate_utf16_at_nul(v), b);
|
||||
assert_eq!(truncate_utf16_at_nul(&v), b);
|
||||
|
||||
let v = [1, 2, 3];
|
||||
let b: &[u16] = &[1, 2, 3];
|
||||
assert_eq!(truncate_utf16_at_nul(v), b);
|
||||
assert_eq!(truncate_utf16_at_nul(&v), b);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1585,7 +1585,7 @@ mod tests {
|
|||
fn test_chars_decoding() {
|
||||
let mut bytes = [0u8, ..4];
|
||||
for c in range(0u32, 0x110000).filter_map(|c| ::core::char::from_u32(c)) {
|
||||
let len = c.encode_utf8(bytes).unwrap_or(0);
|
||||
let len = c.encode_utf8(&mut bytes).unwrap_or(0);
|
||||
let s = ::core::str::from_utf8(bytes[..len]).unwrap();
|
||||
if Some(c) != s.chars().next() {
|
||||
panic!("character {:x}={} does not decode correctly", c as u32, c);
|
||||
|
@ -1597,7 +1597,7 @@ mod tests {
|
|||
fn test_chars_rev_decoding() {
|
||||
let mut bytes = [0u8, ..4];
|
||||
for c in range(0u32, 0x110000).filter_map(|c| ::core::char::from_u32(c)) {
|
||||
let len = c.encode_utf8(bytes).unwrap_or(0);
|
||||
let len = c.encode_utf8(&mut bytes).unwrap_or(0);
|
||||
let s = ::core::str::from_utf8(bytes[..len]).unwrap();
|
||||
if Some(c) != s.chars().rev().next() {
|
||||
panic!("character {:x}={} does not decode correctly", c as u32, c);
|
||||
|
@ -2114,20 +2114,20 @@ mod tests {
|
|||
let v: Vec<&str> = s.split_str(sep).collect();
|
||||
assert_eq!(v.as_slice(), u.as_slice());
|
||||
}
|
||||
t("--1233345--", "12345", ["--1233345--"]);
|
||||
t("abc::hello::there", "::", ["abc", "hello", "there"]);
|
||||
t("::hello::there", "::", ["", "hello", "there"]);
|
||||
t("hello::there::", "::", ["hello", "there", ""]);
|
||||
t("::hello::there::", "::", ["", "hello", "there", ""]);
|
||||
t("ประเทศไทย中华Việt Nam", "中华", ["ประเทศไทย", "Việt Nam"]);
|
||||
t("zzXXXzzYYYzz", "zz", ["", "XXX", "YYY", ""]);
|
||||
t("zzXXXzYYYz", "XXX", ["zz", "zYYYz"]);
|
||||
t(".XXX.YYY.", ".", ["", "XXX", "YYY", ""]);
|
||||
t("", ".", [""]);
|
||||
t("zz", "zz", ["",""]);
|
||||
t("ok", "z", ["ok"]);
|
||||
t("zzz", "zz", ["","z"]);
|
||||
t("zzzzz", "zz", ["","","z"]);
|
||||
t("--1233345--", "12345", &["--1233345--"]);
|
||||
t("abc::hello::there", "::", &["abc", "hello", "there"]);
|
||||
t("::hello::there", "::", &["", "hello", "there"]);
|
||||
t("hello::there::", "::", &["hello", "there", ""]);
|
||||
t("::hello::there::", "::", &["", "hello", "there", ""]);
|
||||
t("ประเทศไทย中华Việt Nam", "中华", &["ประเทศไทย", "Việt Nam"]);
|
||||
t("zzXXXzzYYYzz", "zz", &["", "XXX", "YYY", ""]);
|
||||
t("zzXXXzYYYz", "XXX", &["zz", "zYYYz"]);
|
||||
t(".XXX.YYY.", ".", &["", "XXX", "YYY", ""]);
|
||||
t("", ".", &[""]);
|
||||
t("zz", "zz", &["",""]);
|
||||
t("ok", "z", &["ok"]);
|
||||
t("zzz", "zz", &["","z"]);
|
||||
t("zzzzz", "zz", &["","","z"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2149,12 +2149,12 @@ mod tests {
|
|||
}
|
||||
|
||||
let s = String::from_str("01234");
|
||||
assert_eq!(5, sum_len(["012", "", "34"]));
|
||||
assert_eq!(5, sum_len([String::from_str("01").as_slice(),
|
||||
String::from_str("2").as_slice(),
|
||||
String::from_str("34").as_slice(),
|
||||
String::from_str("").as_slice()]));
|
||||
assert_eq!(5, sum_len([s.as_slice()]));
|
||||
assert_eq!(5, sum_len(&["012", "", "34"]));
|
||||
assert_eq!(5, sum_len(&[String::from_str("01").as_slice(),
|
||||
String::from_str("2").as_slice(),
|
||||
String::from_str("34").as_slice(),
|
||||
String::from_str("").as_slice()]));
|
||||
assert_eq!(5, sum_len(&[s.as_slice()]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -244,8 +244,8 @@ impl String {
|
|||
///
|
||||
/// ```rust
|
||||
/// // 𝄞music
|
||||
/// let mut v = [0xD834, 0xDD1E, 0x006d, 0x0075,
|
||||
/// 0x0073, 0x0069, 0x0063];
|
||||
/// let mut v = &mut [0xD834, 0xDD1E, 0x006d, 0x0075,
|
||||
/// 0x0073, 0x0069, 0x0063];
|
||||
/// assert_eq!(String::from_utf16(v), Some("𝄞music".to_string()));
|
||||
///
|
||||
/// // 𝄞mu<invalid>ic
|
||||
|
@ -270,9 +270,9 @@ impl String {
|
|||
/// # Example
|
||||
/// ```rust
|
||||
/// // 𝄞mus<invalid>ic<invalid>
|
||||
/// let v = [0xD834, 0xDD1E, 0x006d, 0x0075,
|
||||
/// 0x0073, 0xDD1E, 0x0069, 0x0063,
|
||||
/// 0xD834];
|
||||
/// let v = &[0xD834, 0xDD1E, 0x006d, 0x0075,
|
||||
/// 0x0073, 0xDD1E, 0x0069, 0x0063,
|
||||
/// 0xD834];
|
||||
///
|
||||
/// assert_eq!(String::from_utf16_lossy(v),
|
||||
/// "𝄞mus\uFFFDic\uFFFD".to_string());
|
||||
|
@ -287,7 +287,7 @@ impl String {
|
|||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// let chars = ['h', 'e', 'l', 'l', 'o'];
|
||||
/// let chars = &['h', 'e', 'l', 'l', 'o'];
|
||||
/// let s = String::from_chars(chars);
|
||||
/// assert_eq!(s.as_slice(), "hello");
|
||||
/// ```
|
||||
|
@ -600,7 +600,7 @@ impl String {
|
|||
assert!(self.as_slice().is_char_boundary(idx));
|
||||
self.vec.reserve(4);
|
||||
let mut bits = [0, ..4];
|
||||
let amt = ch.encode_utf8(bits).unwrap();
|
||||
let amt = ch.encode_utf8(&mut bits).unwrap();
|
||||
|
||||
unsafe {
|
||||
ptr::copy_memory(self.vec.as_mut_ptr().offset((idx + amt) as int),
|
||||
|
@ -1016,30 +1016,30 @@ mod tests {
|
|||
fn test_utf16_invalid() {
|
||||
// completely positive cases tested above.
|
||||
// lead + eof
|
||||
assert_eq!(String::from_utf16([0xD800]), None);
|
||||
assert_eq!(String::from_utf16(&[0xD800]), None);
|
||||
// lead + lead
|
||||
assert_eq!(String::from_utf16([0xD800, 0xD800]), None);
|
||||
assert_eq!(String::from_utf16(&[0xD800, 0xD800]), None);
|
||||
|
||||
// isolated trail
|
||||
assert_eq!(String::from_utf16([0x0061, 0xDC00]), None);
|
||||
assert_eq!(String::from_utf16(&[0x0061, 0xDC00]), None);
|
||||
|
||||
// general
|
||||
assert_eq!(String::from_utf16([0xD800, 0xd801, 0xdc8b, 0xD800]), None);
|
||||
assert_eq!(String::from_utf16(&[0xD800, 0xd801, 0xdc8b, 0xD800]), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_from_utf16_lossy() {
|
||||
// completely positive cases tested above.
|
||||
// lead + eof
|
||||
assert_eq!(String::from_utf16_lossy([0xD800]), String::from_str("\uFFFD"));
|
||||
assert_eq!(String::from_utf16_lossy(&[0xD800]), String::from_str("\uFFFD"));
|
||||
// lead + lead
|
||||
assert_eq!(String::from_utf16_lossy([0xD800, 0xD800]), String::from_str("\uFFFD\uFFFD"));
|
||||
assert_eq!(String::from_utf16_lossy(&[0xD800, 0xD800]), String::from_str("\uFFFD\uFFFD"));
|
||||
|
||||
// isolated trail
|
||||
assert_eq!(String::from_utf16_lossy([0x0061, 0xDC00]), String::from_str("a\uFFFD"));
|
||||
assert_eq!(String::from_utf16_lossy(&[0x0061, 0xDC00]), String::from_str("a\uFFFD"));
|
||||
|
||||
// general
|
||||
assert_eq!(String::from_utf16_lossy([0xD800, 0xd801, 0xdc8b, 0xD800]),
|
||||
assert_eq!(String::from_utf16_lossy(&[0xD800, 0xd801, 0xdc8b, 0xD800]),
|
||||
String::from_str("\uFFFD𐒋\uFFFD"));
|
||||
}
|
||||
|
||||
|
@ -1066,7 +1066,7 @@ mod tests {
|
|||
let mut s = String::from_str("ABC");
|
||||
unsafe {
|
||||
let mv = s.as_mut_vec();
|
||||
mv.push_all([b'D']);
|
||||
mv.push_all(&[b'D']);
|
||||
}
|
||||
assert_eq!(s.as_slice(), "ABCD");
|
||||
}
|
||||
|
|
|
@ -860,14 +860,14 @@ mod test {
|
|||
check(a, b, expected, |x, y, f| x.intersection(y).all(f))
|
||||
}
|
||||
|
||||
check_intersection([], [], []);
|
||||
check_intersection([1, 2, 3], [], []);
|
||||
check_intersection([], [1, 2, 3], []);
|
||||
check_intersection([2], [1, 2, 3], [2]);
|
||||
check_intersection([1, 2, 3], [2], [2]);
|
||||
check_intersection([11, 1, 3, 77, 103, 5, -5],
|
||||
[2, 11, 77, -9, -42, 5, 3],
|
||||
[3, 5, 11, 77]);
|
||||
check_intersection(&[], &[], &[]);
|
||||
check_intersection(&[1, 2, 3], &[], &[]);
|
||||
check_intersection(&[], &[1, 2, 3], &[]);
|
||||
check_intersection(&[2], &[1, 2, 3], &[2]);
|
||||
check_intersection(&[1, 2, 3], &[2], &[2]);
|
||||
check_intersection(&[11, 1, 3, 77, 103, 5, -5],
|
||||
&[2, 11, 77, -9, -42, 5, 3],
|
||||
&[3, 5, 11, 77]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -876,15 +876,15 @@ mod test {
|
|||
check(a, b, expected, |x, y, f| x.difference(y).all(f))
|
||||
}
|
||||
|
||||
check_difference([], [], []);
|
||||
check_difference([1, 12], [], [1, 12]);
|
||||
check_difference([], [1, 2, 3, 9], []);
|
||||
check_difference([1, 3, 5, 9, 11],
|
||||
[3, 9],
|
||||
[1, 5, 11]);
|
||||
check_difference([-5, 11, 22, 33, 40, 42],
|
||||
[-12, -5, 14, 23, 34, 38, 39, 50],
|
||||
[11, 22, 33, 40, 42]);
|
||||
check_difference(&[], &[], &[]);
|
||||
check_difference(&[1, 12], &[], &[1, 12]);
|
||||
check_difference(&[], &[1, 2, 3, 9], &[]);
|
||||
check_difference(&[1, 3, 5, 9, 11],
|
||||
&[3, 9],
|
||||
&[1, 5, 11]);
|
||||
check_difference(&[-5, 11, 22, 33, 40, 42],
|
||||
&[-12, -5, 14, 23, 34, 38, 39, 50],
|
||||
&[11, 22, 33, 40, 42]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -894,12 +894,12 @@ mod test {
|
|||
check(a, b, expected, |x, y, f| x.symmetric_difference(y).all(f))
|
||||
}
|
||||
|
||||
check_symmetric_difference([], [], []);
|
||||
check_symmetric_difference([1, 2, 3], [2], [1, 3]);
|
||||
check_symmetric_difference([2], [1, 2, 3], [1, 3]);
|
||||
check_symmetric_difference([1, 3, 5, 9, 11],
|
||||
[-2, 3, 9, 14, 22],
|
||||
[-2, 1, 5, 11, 14, 22]);
|
||||
check_symmetric_difference(&[], &[], &[]);
|
||||
check_symmetric_difference(&[1, 2, 3], &[2], &[1, 3]);
|
||||
check_symmetric_difference(&[2], &[1, 2, 3], &[1, 3]);
|
||||
check_symmetric_difference(&[1, 3, 5, 9, 11],
|
||||
&[-2, 3, 9, 14, 22],
|
||||
&[-2, 1, 5, 11, 14, 22]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -909,12 +909,12 @@ mod test {
|
|||
check(a, b, expected, |x, y, f| x.union(y).all(f))
|
||||
}
|
||||
|
||||
check_union([], [], []);
|
||||
check_union([1, 2, 3], [2], [1, 2, 3]);
|
||||
check_union([2], [1, 2, 3], [1, 2, 3]);
|
||||
check_union([1, 3, 5, 9, 11, 16, 19, 24],
|
||||
[-2, 1, 5, 9, 13, 19],
|
||||
[-2, 1, 3, 5, 9, 11, 13, 16, 19, 24]);
|
||||
check_union(&[], &[], &[]);
|
||||
check_union(&[1, 2, 3], &[2], &[1, 2, 3]);
|
||||
check_union(&[2], &[1, 2, 3], &[1, 2, 3]);
|
||||
check_union(&[1, 3, 5, 9, 11, 16, 19, 24],
|
||||
&[-2, 1, 5, 9, 13, 19],
|
||||
&[-2, 1, 3, 5, 9, 11, 13, 16, 19, 24]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -47,7 +47,7 @@ use slice::{CloneSliceAllocPrelude};
|
|||
/// vec[0] = 7i;
|
||||
/// assert_eq!(vec[0], 7);
|
||||
///
|
||||
/// vec.push_all([1, 2, 3]);
|
||||
/// vec.push_all(&[1, 2, 3]);
|
||||
///
|
||||
/// for x in vec.iter() {
|
||||
/// println!("{}", x);
|
||||
|
@ -306,7 +306,7 @@ impl<T: Clone> Vec<T> {
|
|||
///
|
||||
/// ```
|
||||
/// let mut vec = vec![1i];
|
||||
/// vec.push_all([2i, 3, 4]);
|
||||
/// vec.push_all(&[2i, 3, 4]);
|
||||
/// assert_eq!(vec, vec![1, 2, 3, 4]);
|
||||
/// ```
|
||||
#[inline]
|
||||
|
@ -639,7 +639,7 @@ impl<T> Vec<T> {
|
|||
///
|
||||
/// ```
|
||||
/// let mut vec: Vec<int> = Vec::with_capacity(10);
|
||||
/// vec.push_all([1, 2, 3]);
|
||||
/// vec.push_all(&[1, 2, 3]);
|
||||
/// assert_eq!(vec.capacity(), 10);
|
||||
/// vec.shrink_to_fit();
|
||||
/// assert!(vec.capacity() >= 3);
|
||||
|
@ -1682,7 +1682,7 @@ mod tests {
|
|||
#[test]
|
||||
fn test_as_vec() {
|
||||
let xs = [1u8, 2u8, 3u8];
|
||||
assert_eq!(as_vec(xs).as_slice(), xs.as_slice());
|
||||
assert_eq!(as_vec(&xs).as_slice(), xs.as_slice());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1772,13 +1772,13 @@ mod tests {
|
|||
let mut values = vec![1u8,2,3,4,5];
|
||||
{
|
||||
let slice = values.slice_from_mut(2);
|
||||
assert!(slice == [3, 4, 5]);
|
||||
assert!(slice == &mut [3, 4, 5]);
|
||||
for p in slice.iter_mut() {
|
||||
*p += 2;
|
||||
}
|
||||
}
|
||||
|
||||
assert!(values.as_slice() == [1, 2, 5, 6, 7]);
|
||||
assert!(values.as_slice() == &[1, 2, 5, 6, 7]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1786,13 +1786,13 @@ mod tests {
|
|||
let mut values = vec![1u8,2,3,4,5];
|
||||
{
|
||||
let slice = values.slice_to_mut(2);
|
||||
assert!(slice == [1, 2]);
|
||||
assert!(slice == &mut [1, 2]);
|
||||
for p in slice.iter_mut() {
|
||||
*p += 1;
|
||||
}
|
||||
}
|
||||
|
||||
assert!(values.as_slice() == [2, 3, 3, 4, 5]);
|
||||
assert!(values.as_slice() == &[2, 3, 3, 4, 5]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -79,7 +79,7 @@ impl<T> Finally<T> for fn() -> T {
|
|||
*
|
||||
* struct State<'a> { buffer: &'a mut [u8], len: uint }
|
||||
* # let mut buf = [];
|
||||
* let mut state = State { buffer: buf, len: 0 };
|
||||
* let mut state = State { buffer: &mut buf, len: 0 };
|
||||
* try_finally(
|
||||
* &mut state, (),
|
||||
* |state, ()| {
|
||||
|
|
|
@ -315,7 +315,7 @@ pub fn float_to_str_bytes_common<T: Float, U>(
|
|||
}
|
||||
}
|
||||
|
||||
let mut filler = Filler { buf: buf, end: &mut end };
|
||||
let mut filler = Filler { buf: &mut buf, end: &mut end };
|
||||
match sign {
|
||||
SignNeg => {
|
||||
let _ = format_args!(|args| {
|
||||
|
|
|
@ -392,7 +392,7 @@ impl<'a> Formatter<'a> {
|
|||
let write_prefix = |f: &mut Formatter| {
|
||||
for c in sign.into_iter() {
|
||||
let mut b = [0, ..4];
|
||||
let n = c.encode_utf8(b).unwrap_or(0);
|
||||
let n = c.encode_utf8(&mut b).unwrap_or(0);
|
||||
try!(f.buf.write(b[..n]));
|
||||
}
|
||||
if prefixed { f.buf.write(prefix.as_bytes()) }
|
||||
|
@ -497,7 +497,7 @@ impl<'a> Formatter<'a> {
|
|||
};
|
||||
|
||||
let mut fill = [0u8, ..4];
|
||||
let len = self.fill.encode_utf8(fill).unwrap_or(0);
|
||||
let len = self.fill.encode_utf8(&mut fill).unwrap_or(0);
|
||||
|
||||
for _ in range(0, pre_pad) {
|
||||
try!(self.buf.write(fill[..len]));
|
||||
|
@ -586,7 +586,7 @@ impl Char for char {
|
|||
use char::Char;
|
||||
|
||||
let mut utf8 = [0u8, ..4];
|
||||
let amt = self.encode_utf8(utf8).unwrap_or(0);
|
||||
let amt = self.encode_utf8(&mut utf8).unwrap_or(0);
|
||||
let s: &str = unsafe { mem::transmute(utf8[..amt]) };
|
||||
String::fmt(s, f)
|
||||
}
|
||||
|
|
|
@ -228,7 +228,7 @@ extern "rust-intrinsic" {
|
|||
/// use std::mem;
|
||||
///
|
||||
/// let v: &[u8] = unsafe { mem::transmute("L") };
|
||||
/// assert!(v == [76u8]);
|
||||
/// assert!(v == &[76u8]);
|
||||
/// ```
|
||||
pub fn transmute<T,U>(e: T) -> U;
|
||||
|
||||
|
|
|
@ -271,9 +271,9 @@ impl<T> Option<T> {
|
|||
/// let mut x = Some("Diamonds");
|
||||
/// {
|
||||
/// let v = x.as_mut_slice();
|
||||
/// assert!(v == ["Diamonds"]);
|
||||
/// assert!(v == &mut ["Diamonds"]);
|
||||
/// v[0] = "Dirt";
|
||||
/// assert!(v == ["Dirt"]);
|
||||
/// assert!(v == &mut ["Dirt"]);
|
||||
/// }
|
||||
/// assert_eq!(x, Some("Dirt"));
|
||||
/// ```
|
||||
|
|
|
@ -451,14 +451,14 @@ impl<T, E> Result<T, E> {
|
|||
/// let mut x: Result<&str, uint> = Ok("Gold");
|
||||
/// {
|
||||
/// let v = x.as_mut_slice();
|
||||
/// assert!(v == ["Gold"]);
|
||||
/// assert!(v == &mut ["Gold"]);
|
||||
/// v[0] = "Silver";
|
||||
/// assert!(v == ["Silver"]);
|
||||
/// assert!(v == &mut ["Silver"]);
|
||||
/// }
|
||||
/// assert_eq!(x, Ok("Silver"));
|
||||
///
|
||||
/// let mut x: Result<&str, uint> = Err(45);
|
||||
/// assert!(x.as_mut_slice() == []);
|
||||
/// assert!(x.as_mut_slice() == &mut []);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "waiting for mut conventions"]
|
||||
|
|
|
@ -973,11 +973,11 @@ pub trait CloneSlicePrelude<T> for Sized? {
|
|||
/// let mut dst = [0i, 0, 0];
|
||||
/// let src = [1i, 2];
|
||||
///
|
||||
/// assert!(dst.clone_from_slice(src) == 2);
|
||||
/// assert!(dst.clone_from_slice(&src) == 2);
|
||||
/// assert!(dst == [1, 2, 0]);
|
||||
///
|
||||
/// let src2 = [3i, 4, 5, 6];
|
||||
/// assert!(dst.clone_from_slice(src2) == 3);
|
||||
/// assert!(dst.clone_from_slice(&src2) == 3);
|
||||
/// assert!(dst == [3i, 4, 5]);
|
||||
/// ```
|
||||
fn clone_from_slice(&mut self, &[T]) -> uint;
|
||||
|
|
|
@ -1008,7 +1008,7 @@ impl<'a> Iterator<Utf16Item> for Utf16Items<'a> {
|
|||
/// 0x0073, 0xDD1E, 0x0069, 0x0063,
|
||||
/// 0xD834];
|
||||
///
|
||||
/// assert_eq!(str::utf16_items(v).collect::<Vec<_>>(),
|
||||
/// assert_eq!(str::utf16_items(&v).collect::<Vec<_>>(),
|
||||
/// vec![ScalarValue('𝄞'),
|
||||
/// ScalarValue('m'), ScalarValue('u'), ScalarValue('s'),
|
||||
/// LoneSurrogate(0xDD1E),
|
||||
|
@ -1030,12 +1030,12 @@ pub fn utf16_items<'a>(v: &'a [u16]) -> Utf16Items<'a> {
|
|||
/// // "abcd"
|
||||
/// let mut v = ['a' as u16, 'b' as u16, 'c' as u16, 'd' as u16];
|
||||
/// // no NULs so no change
|
||||
/// assert_eq!(str::truncate_utf16_at_nul(v), v.as_slice());
|
||||
/// assert_eq!(str::truncate_utf16_at_nul(&v), v.as_slice());
|
||||
///
|
||||
/// // "ab\0d"
|
||||
/// v[2] = 0;
|
||||
/// let b: &[_] = &['a' as u16, 'b' as u16];
|
||||
/// assert_eq!(str::truncate_utf16_at_nul(v), b);
|
||||
/// assert_eq!(str::truncate_utf16_at_nul(&v), b);
|
||||
/// ```
|
||||
pub fn truncate_utf16_at_nul<'a>(v: &'a [u16]) -> &'a [u16] {
|
||||
match v.iter().position(|c| *c == 0) {
|
||||
|
|
|
@ -177,10 +177,10 @@ fn test_encode_utf8() {
|
|||
assert_eq!(buf[..n], expect);
|
||||
}
|
||||
|
||||
check('x', [0x78]);
|
||||
check('\u00e9', [0xc3, 0xa9]);
|
||||
check('\ua66e', [0xea, 0x99, 0xae]);
|
||||
check('\U0001f4a9', [0xf0, 0x9f, 0x92, 0xa9]);
|
||||
check('x', &[0x78]);
|
||||
check('\u00e9', &[0xc3, 0xa9]);
|
||||
check('\ua66e', &[0xea, 0x99, 0xae]);
|
||||
check('\U0001f4a9', &[0xf0, 0x9f, 0x92, 0xa9]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -191,10 +191,10 @@ fn test_encode_utf16() {
|
|||
assert_eq!(buf[..n], expect);
|
||||
}
|
||||
|
||||
check('x', [0x0078]);
|
||||
check('\u00e9', [0x00e9]);
|
||||
check('\ua66e', [0xa66e]);
|
||||
check('\U0001f4a9', [0xd83d, 0xdca9]);
|
||||
check('x', &[0x0078]);
|
||||
check('\u00e9', &[0x00e9]);
|
||||
check('\ua66e', &[0xa66e]);
|
||||
check('\U0001f4a9', &[0xd83d, 0xdca9]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -627,7 +627,7 @@ fn test_random_access_zip() {
|
|||
#[test]
|
||||
fn test_random_access_take() {
|
||||
let xs = [1i, 2, 3, 4, 5];
|
||||
let empty: &[int] = [];
|
||||
let empty: &[int] = &[];
|
||||
check_randacc_iter(xs.iter().take(3), 3);
|
||||
check_randacc_iter(xs.iter().take(20), xs.len());
|
||||
check_randacc_iter(xs.iter().take(0), 0);
|
||||
|
@ -637,7 +637,7 @@ fn test_random_access_take() {
|
|||
#[test]
|
||||
fn test_random_access_skip() {
|
||||
let xs = [1i, 2, 3, 4, 5];
|
||||
let empty: &[int] = [];
|
||||
let empty: &[int] = &[];
|
||||
check_randacc_iter(xs.iter().skip(2), xs.len() - 2);
|
||||
check_randacc_iter(empty.iter().skip(2), 0);
|
||||
}
|
||||
|
@ -669,7 +669,7 @@ fn test_random_access_map() {
|
|||
#[test]
|
||||
fn test_random_access_cycle() {
|
||||
let xs = [1i, 2, 3, 4, 5];
|
||||
let empty: &[int] = [];
|
||||
let empty: &[int] = &[];
|
||||
check_randacc_iter(xs.iter().cycle().take(27), 27);
|
||||
check_randacc_iter(empty.iter().cycle(), 0);
|
||||
}
|
||||
|
|
|
@ -454,12 +454,12 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn simple() {
|
||||
same("asdf", [String("asdf")]);
|
||||
same("a{{b", [String("a"), String("{b")]);
|
||||
same("a}}b", [String("a"), String("}b")]);
|
||||
same("a}}", [String("a"), String("}")]);
|
||||
same("}}", [String("}")]);
|
||||
same("\\}}", [String("\\"), String("}")]);
|
||||
same("asdf", &[String("asdf")]);
|
||||
same("a{{b", &[String("a"), String("{b")]);
|
||||
same("a}}b", &[String("a"), String("}b")]);
|
||||
same("a}}", &[String("a"), String("}")]);
|
||||
same("}}", &[String("}")]);
|
||||
same("\\}}", &[String("\\"), String("}")]);
|
||||
}
|
||||
|
||||
#[test] fn invalid01() { musterr("{") }
|
||||
|
@ -470,28 +470,28 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn format_nothing() {
|
||||
same("{}", [NextArgument(Argument {
|
||||
same("{}", &[NextArgument(Argument {
|
||||
position: ArgumentNext,
|
||||
format: fmtdflt(),
|
||||
})]);
|
||||
}
|
||||
#[test]
|
||||
fn format_position() {
|
||||
same("{3}", [NextArgument(Argument {
|
||||
same("{3}", &[NextArgument(Argument {
|
||||
position: ArgumentIs(3),
|
||||
format: fmtdflt(),
|
||||
})]);
|
||||
}
|
||||
#[test]
|
||||
fn format_position_nothing_else() {
|
||||
same("{3:}", [NextArgument(Argument {
|
||||
same("{3:}", &[NextArgument(Argument {
|
||||
position: ArgumentIs(3),
|
||||
format: fmtdflt(),
|
||||
})]);
|
||||
}
|
||||
#[test]
|
||||
fn format_type() {
|
||||
same("{3:a}", [NextArgument(Argument {
|
||||
same("{3:a}", &[NextArgument(Argument {
|
||||
position: ArgumentIs(3),
|
||||
format: FormatSpec {
|
||||
fill: None,
|
||||
|
@ -505,7 +505,7 @@ mod tests {
|
|||
}
|
||||
#[test]
|
||||
fn format_align_fill() {
|
||||
same("{3:>}", [NextArgument(Argument {
|
||||
same("{3:>}", &[NextArgument(Argument {
|
||||
position: ArgumentIs(3),
|
||||
format: FormatSpec {
|
||||
fill: None,
|
||||
|
@ -516,7 +516,7 @@ mod tests {
|
|||
ty: "",
|
||||
},
|
||||
})]);
|
||||
same("{3:0<}", [NextArgument(Argument {
|
||||
same("{3:0<}", &[NextArgument(Argument {
|
||||
position: ArgumentIs(3),
|
||||
format: FormatSpec {
|
||||
fill: Some('0'),
|
||||
|
@ -527,7 +527,7 @@ mod tests {
|
|||
ty: "",
|
||||
},
|
||||
})]);
|
||||
same("{3:*<abcd}", [NextArgument(Argument {
|
||||
same("{3:*<abcd}", &[NextArgument(Argument {
|
||||
position: ArgumentIs(3),
|
||||
format: FormatSpec {
|
||||
fill: Some('*'),
|
||||
|
@ -541,7 +541,7 @@ mod tests {
|
|||
}
|
||||
#[test]
|
||||
fn format_counts() {
|
||||
same("{:10s}", [NextArgument(Argument {
|
||||
same("{:10s}", &[NextArgument(Argument {
|
||||
position: ArgumentNext,
|
||||
format: FormatSpec {
|
||||
fill: None,
|
||||
|
@ -552,7 +552,7 @@ mod tests {
|
|||
ty: "s",
|
||||
},
|
||||
})]);
|
||||
same("{:10$.10s}", [NextArgument(Argument {
|
||||
same("{:10$.10s}", &[NextArgument(Argument {
|
||||
position: ArgumentNext,
|
||||
format: FormatSpec {
|
||||
fill: None,
|
||||
|
@ -563,7 +563,7 @@ mod tests {
|
|||
ty: "s",
|
||||
},
|
||||
})]);
|
||||
same("{:.*s}", [NextArgument(Argument {
|
||||
same("{:.*s}", &[NextArgument(Argument {
|
||||
position: ArgumentNext,
|
||||
format: FormatSpec {
|
||||
fill: None,
|
||||
|
@ -574,7 +574,7 @@ mod tests {
|
|||
ty: "s",
|
||||
},
|
||||
})]);
|
||||
same("{:.10$s}", [NextArgument(Argument {
|
||||
same("{:.10$s}", &[NextArgument(Argument {
|
||||
position: ArgumentNext,
|
||||
format: FormatSpec {
|
||||
fill: None,
|
||||
|
@ -585,7 +585,7 @@ mod tests {
|
|||
ty: "s",
|
||||
},
|
||||
})]);
|
||||
same("{:a$.b$s}", [NextArgument(Argument {
|
||||
same("{:a$.b$s}", &[NextArgument(Argument {
|
||||
position: ArgumentNext,
|
||||
format: FormatSpec {
|
||||
fill: None,
|
||||
|
@ -599,7 +599,7 @@ mod tests {
|
|||
}
|
||||
#[test]
|
||||
fn format_flags() {
|
||||
same("{:-}", [NextArgument(Argument {
|
||||
same("{:-}", &[NextArgument(Argument {
|
||||
position: ArgumentNext,
|
||||
format: FormatSpec {
|
||||
fill: None,
|
||||
|
@ -610,7 +610,7 @@ mod tests {
|
|||
ty: "",
|
||||
},
|
||||
})]);
|
||||
same("{:+#}", [NextArgument(Argument {
|
||||
same("{:+#}", &[NextArgument(Argument {
|
||||
position: ArgumentNext,
|
||||
format: FormatSpec {
|
||||
fill: None,
|
||||
|
@ -624,7 +624,7 @@ mod tests {
|
|||
}
|
||||
#[test]
|
||||
fn format_mixture() {
|
||||
same("abcd {3:a} efg", [String("abcd "), NextArgument(Argument {
|
||||
same("abcd {3:a} efg", &[String("abcd "), NextArgument(Argument {
|
||||
position: ArgumentIs(3),
|
||||
format: FormatSpec {
|
||||
fill: None,
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
//!
|
||||
//! let program = args[0].clone();
|
||||
//!
|
||||
//! let opts = [
|
||||
//! let opts = &[
|
||||
//! optopt("o", "", "set output file name", "NAME"),
|
||||
//! optflag("h", "help", "print this help menu")
|
||||
//! ];
|
||||
|
@ -942,16 +942,16 @@ fn test_split_within() {
|
|||
each_split_within(s, i, |s| { v.push(s.to_string()); true });
|
||||
assert!(v.iter().zip(u.iter()).all(|(a,b)| a == b));
|
||||
}
|
||||
t("", 0, []);
|
||||
t("", 15, []);
|
||||
t("hello", 15, ["hello".to_string()]);
|
||||
t("\nMary had a little lamb\nLittle lamb\n", 15, [
|
||||
t("", 0, &[]);
|
||||
t("", 15, &[]);
|
||||
t("hello", 15, &["hello".to_string()]);
|
||||
t("\nMary had a little lamb\nLittle lamb\n", 15, &[
|
||||
"Mary had a".to_string(),
|
||||
"little lamb".to_string(),
|
||||
"Little lamb".to_string()
|
||||
]);
|
||||
t("\nMary had a little lamb\nLittle lamb\n", ::std::uint::MAX,
|
||||
["Mary had a little lamb\nLittle lamb".to_string()]);
|
||||
&["Mary had a little lamb\nLittle lamb".to_string()]);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -1414,17 +1414,17 @@ mod tests {
|
|||
result::Ok(m) => m,
|
||||
result::Err(_) => panic!()
|
||||
};
|
||||
assert!(matches_single.opts_present(["e".to_string()]));
|
||||
assert!(matches_single.opts_present(["encrypt".to_string(), "e".to_string()]));
|
||||
assert!(matches_single.opts_present(["e".to_string(), "encrypt".to_string()]));
|
||||
assert!(!matches_single.opts_present(["encrypt".to_string()]));
|
||||
assert!(!matches_single.opts_present(["thing".to_string()]));
|
||||
assert!(!matches_single.opts_present([]));
|
||||
assert!(matches_single.opts_present(&["e".to_string()]));
|
||||
assert!(matches_single.opts_present(&["encrypt".to_string(), "e".to_string()]));
|
||||
assert!(matches_single.opts_present(&["e".to_string(), "encrypt".to_string()]));
|
||||
assert!(!matches_single.opts_present(&["encrypt".to_string()]));
|
||||
assert!(!matches_single.opts_present(&["thing".to_string()]));
|
||||
assert!(!matches_single.opts_present(&[]));
|
||||
|
||||
assert_eq!(matches_single.opts_str(["e".to_string()]).unwrap(), "foo".to_string());
|
||||
assert_eq!(matches_single.opts_str(["e".to_string(), "encrypt".to_string()]).unwrap(),
|
||||
assert_eq!(matches_single.opts_str(&["e".to_string()]).unwrap(), "foo".to_string());
|
||||
assert_eq!(matches_single.opts_str(&["e".to_string(), "encrypt".to_string()]).unwrap(),
|
||||
"foo".to_string());
|
||||
assert_eq!(matches_single.opts_str(["encrypt".to_string(), "e".to_string()]).unwrap(),
|
||||
assert_eq!(matches_single.opts_str(&["encrypt".to_string(), "e".to_string()]).unwrap(),
|
||||
"foo".to_string());
|
||||
|
||||
let args_both = vec!("-e".to_string(), "foo".to_string(), "--encrypt".to_string(),
|
||||
|
@ -1434,19 +1434,19 @@ mod tests {
|
|||
result::Ok(m) => m,
|
||||
result::Err(_) => panic!()
|
||||
};
|
||||
assert!(matches_both.opts_present(["e".to_string()]));
|
||||
assert!(matches_both.opts_present(["encrypt".to_string()]));
|
||||
assert!(matches_both.opts_present(["encrypt".to_string(), "e".to_string()]));
|
||||
assert!(matches_both.opts_present(["e".to_string(), "encrypt".to_string()]));
|
||||
assert!(!matches_both.opts_present(["f".to_string()]));
|
||||
assert!(!matches_both.opts_present(["thing".to_string()]));
|
||||
assert!(!matches_both.opts_present([]));
|
||||
assert!(matches_both.opts_present(&["e".to_string()]));
|
||||
assert!(matches_both.opts_present(&["encrypt".to_string()]));
|
||||
assert!(matches_both.opts_present(&["encrypt".to_string(), "e".to_string()]));
|
||||
assert!(matches_both.opts_present(&["e".to_string(), "encrypt".to_string()]));
|
||||
assert!(!matches_both.opts_present(&["f".to_string()]));
|
||||
assert!(!matches_both.opts_present(&["thing".to_string()]));
|
||||
assert!(!matches_both.opts_present(&[]));
|
||||
|
||||
assert_eq!(matches_both.opts_str(["e".to_string()]).unwrap(), "foo".to_string());
|
||||
assert_eq!(matches_both.opts_str(["encrypt".to_string()]).unwrap(), "foo".to_string());
|
||||
assert_eq!(matches_both.opts_str(["e".to_string(), "encrypt".to_string()]).unwrap(),
|
||||
assert_eq!(matches_both.opts_str(&["e".to_string()]).unwrap(), "foo".to_string());
|
||||
assert_eq!(matches_both.opts_str(&["encrypt".to_string()]).unwrap(), "foo".to_string());
|
||||
assert_eq!(matches_both.opts_str(&["e".to_string(), "encrypt".to_string()]).unwrap(),
|
||||
"foo".to_string());
|
||||
assert_eq!(matches_both.opts_str(["encrypt".to_string(), "e".to_string()]).unwrap(),
|
||||
assert_eq!(matches_both.opts_str(&["encrypt".to_string(), "e".to_string()]).unwrap(),
|
||||
"foo".to_string());
|
||||
}
|
||||
|
||||
|
@ -1459,10 +1459,10 @@ mod tests {
|
|||
result::Ok(m) => m,
|
||||
result::Err(_) => panic!()
|
||||
};
|
||||
assert!(matches.opts_present(["L".to_string()]));
|
||||
assert_eq!(matches.opts_str(["L".to_string()]).unwrap(), "foo".to_string());
|
||||
assert!(matches.opts_present(["M".to_string()]));
|
||||
assert_eq!(matches.opts_str(["M".to_string()]).unwrap(), ".".to_string());
|
||||
assert!(matches.opts_present(&["L".to_string()]));
|
||||
assert_eq!(matches.opts_str(&["L".to_string()]).unwrap(), "foo".to_string());
|
||||
assert!(matches.opts_present(&["M".to_string()]));
|
||||
assert_eq!(matches.opts_str(&["M".to_string()]).unwrap(), ".".to_string());
|
||||
|
||||
}
|
||||
|
||||
|
@ -1475,9 +1475,9 @@ mod tests {
|
|||
result::Ok(m) => m,
|
||||
result::Err(e) => panic!( "{}", e )
|
||||
};
|
||||
assert!(matches.opts_present(["L".to_string()]));
|
||||
assert_eq!(matches.opts_str(["L".to_string()]).unwrap(), "verbose".to_string());
|
||||
assert!(matches.opts_present(["v".to_string()]));
|
||||
assert!(matches.opts_present(&["L".to_string()]));
|
||||
assert_eq!(matches.opts_str(&["L".to_string()]).unwrap(), "verbose".to_string());
|
||||
assert!(matches.opts_present(&["v".to_string()]));
|
||||
assert_eq!(3, matches.opt_count("v"));
|
||||
}
|
||||
|
||||
|
|
|
@ -514,13 +514,13 @@ pub fn render<'a, N:'a, E:'a, G:Labeller<'a,N,E>+GraphWalk<'a,N,E>, W:Writer>(
|
|||
w.write_str(" ")
|
||||
}
|
||||
|
||||
try!(writeln(w, ["digraph ", g.graph_id().as_slice(), " {"]));
|
||||
try!(writeln(w, &["digraph ", g.graph_id().as_slice(), " {"]));
|
||||
for n in g.nodes().iter() {
|
||||
try!(indent(w));
|
||||
let id = g.node_id(n);
|
||||
let escaped = g.node_label(n).escape();
|
||||
try!(writeln(w, [id.as_slice(),
|
||||
"[label=\"", escaped.as_slice(), "\"];"]));
|
||||
try!(writeln(w, &[id.as_slice(),
|
||||
"[label=\"", escaped.as_slice(), "\"];"]));
|
||||
}
|
||||
|
||||
for e in g.edges().iter() {
|
||||
|
@ -530,11 +530,11 @@ pub fn render<'a, N:'a, E:'a, G:Labeller<'a,N,E>+GraphWalk<'a,N,E>, W:Writer>(
|
|||
let target = g.target(e);
|
||||
let source_id = g.node_id(&source);
|
||||
let target_id = g.node_id(&target);
|
||||
try!(writeln(w, [source_id.as_slice(), " -> ", target_id.as_slice(),
|
||||
"[label=\"", escaped_label.as_slice(), "\"];"]));
|
||||
try!(writeln(w, &[source_id.as_slice(), " -> ", target_id.as_slice(),
|
||||
"[label=\"", escaped_label.as_slice(), "\"];"]));
|
||||
}
|
||||
|
||||
writeln(w, ["}"])
|
||||
writeln(w, &["}"])
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -44,8 +44,8 @@ impl Stack {
|
|||
// allocation failure, which would fail to spawn the task. But there's
|
||||
// not many sensible things to do on OOM. Failure seems fine (and is
|
||||
// what the old stack allocation did).
|
||||
let stack = match MemoryMap::new(size, [MapReadable, MapWritable,
|
||||
MapNonStandardFlags(STACK_FLAGS)]) {
|
||||
let stack = match MemoryMap::new(size, &[MapReadable, MapWritable,
|
||||
MapNonStandardFlags(STACK_FLAGS)]) {
|
||||
Ok(map) => map,
|
||||
Err(e) => panic!("mmap for stack of size {} failed: {}", size, e)
|
||||
};
|
||||
|
|
|
@ -349,7 +349,7 @@ mod tests {
|
|||
|
||||
#[test] #[should_fail]
|
||||
fn test_weighted_choice_no_items() {
|
||||
WeightedChoice::<int>::new([]);
|
||||
WeightedChoice::<int>::new(&mut []);
|
||||
}
|
||||
#[test] #[should_fail]
|
||||
fn test_weighted_choice_zero_weight() {
|
||||
|
|
|
@ -185,9 +185,9 @@ mod tests {
|
|||
macro_rules! t (
|
||||
($($ty:ty),*) => {{
|
||||
$(
|
||||
let v: &[($ty, $ty)] = [(0, 10),
|
||||
(10, 127),
|
||||
(Int::min_value(), Int::max_value())];
|
||||
let v: &[($ty, $ty)] = &[(0, 10),
|
||||
(10, 127),
|
||||
(Int::min_value(), Int::max_value())];
|
||||
for &(low, high) in v.iter() {
|
||||
let mut sampler: Range<$ty> = Range::new(low, high);
|
||||
for _ in range(0u, 1000) {
|
||||
|
@ -210,10 +210,10 @@ mod tests {
|
|||
macro_rules! t (
|
||||
($($ty:ty),*) => {{
|
||||
$(
|
||||
let v: &[($ty, $ty)] = [(0.0, 100.0),
|
||||
(-1e35, -1e25),
|
||||
(1e-35, 1e-25),
|
||||
(-1e35, 1e35)];
|
||||
let v: &[($ty, $ty)] = &[(0.0, 100.0),
|
||||
(-1e35, -1e25),
|
||||
(1e-35, 1e-25),
|
||||
(-1e35, 1e35)];
|
||||
for &(low, high) in v.iter() {
|
||||
let mut sampler: Range<$ty> = Range::new(low, high);
|
||||
for _ in range(0u, 1000) {
|
||||
|
|
|
@ -142,7 +142,7 @@ pub trait Rng {
|
|||
/// use std::rand::{task_rng, Rng};
|
||||
///
|
||||
/// let mut v = [0u8, .. 13579];
|
||||
/// task_rng().fill_bytes(v);
|
||||
/// task_rng().fill_bytes(&mut v);
|
||||
/// println!("{}", v.as_slice());
|
||||
/// ```
|
||||
fn fill_bytes(&mut self, dest: &mut [u8]) {
|
||||
|
@ -268,7 +268,7 @@ pub trait Rng {
|
|||
///
|
||||
/// let choices = [1i, 2, 4, 8, 16, 32];
|
||||
/// let mut rng = task_rng();
|
||||
/// println!("{}", rng.choose(choices));
|
||||
/// println!("{}", rng.choose(&choices));
|
||||
/// assert_eq!(rng.choose(choices[..0]), None);
|
||||
/// ```
|
||||
fn choose<'a, T>(&mut self, values: &'a [T]) -> Option<&'a T> {
|
||||
|
@ -288,9 +288,9 @@ pub trait Rng {
|
|||
///
|
||||
/// let mut rng = task_rng();
|
||||
/// let mut y = [1i, 2, 3];
|
||||
/// rng.shuffle(y);
|
||||
/// rng.shuffle(&mut y);
|
||||
/// println!("{}", y.as_slice());
|
||||
/// rng.shuffle(y);
|
||||
/// rng.shuffle(&mut y);
|
||||
/// println!("{}", y.as_slice());
|
||||
/// ```
|
||||
fn shuffle<T>(&mut self, values: &mut [T]) {
|
||||
|
@ -347,7 +347,7 @@ pub trait SeedableRng<Seed>: Rng {
|
|||
/// let seed: &[_] = &[1, 2, 3, 4];
|
||||
/// let mut rng: StdRng = SeedableRng::from_seed(seed);
|
||||
/// println!("{}", rng.gen::<f64>());
|
||||
/// rng.reseed([5, 6, 7, 8]);
|
||||
/// rng.reseed(&[5, 6, 7, 8]);
|
||||
/// println!("{}", rng.gen::<f64>());
|
||||
/// ```
|
||||
fn reseed(&mut self, Seed);
|
||||
|
|
|
@ -42,7 +42,7 @@ fn combine(seek: SeekStyle, cur: uint, end: uint, offset: i64) -> IoResult<u64>
|
|||
/// use rbml::io::SeekableMemWriter;
|
||||
///
|
||||
/// let mut w = SeekableMemWriter::new();
|
||||
/// w.write([0, 1, 2]);
|
||||
/// w.write(&[0, 1, 2]);
|
||||
///
|
||||
/// assert_eq!(w.unwrap(), vec!(0, 1, 2));
|
||||
/// ```
|
||||
|
@ -138,32 +138,32 @@ mod tests {
|
|||
fn test_seekable_mem_writer() {
|
||||
let mut writer = SeekableMemWriter::new();
|
||||
assert_eq!(writer.tell(), Ok(0));
|
||||
writer.write([0]).unwrap();
|
||||
writer.write(&[0]).unwrap();
|
||||
assert_eq!(writer.tell(), Ok(1));
|
||||
writer.write([1, 2, 3]).unwrap();
|
||||
writer.write([4, 5, 6, 7]).unwrap();
|
||||
writer.write(&[1, 2, 3]).unwrap();
|
||||
writer.write(&[4, 5, 6, 7]).unwrap();
|
||||
assert_eq!(writer.tell(), Ok(8));
|
||||
let b: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7];
|
||||
assert_eq!(writer.get_ref(), b);
|
||||
|
||||
writer.seek(0, io::SeekSet).unwrap();
|
||||
assert_eq!(writer.tell(), Ok(0));
|
||||
writer.write([3, 4]).unwrap();
|
||||
writer.write(&[3, 4]).unwrap();
|
||||
let b: &[_] = &[3, 4, 2, 3, 4, 5, 6, 7];
|
||||
assert_eq!(writer.get_ref(), b);
|
||||
|
||||
writer.seek(1, io::SeekCur).unwrap();
|
||||
writer.write([0, 1]).unwrap();
|
||||
writer.write(&[0, 1]).unwrap();
|
||||
let b: &[_] = &[3, 4, 2, 0, 1, 5, 6, 7];
|
||||
assert_eq!(writer.get_ref(), b);
|
||||
|
||||
writer.seek(-1, io::SeekEnd).unwrap();
|
||||
writer.write([1, 2]).unwrap();
|
||||
writer.write(&[1, 2]).unwrap();
|
||||
let b: &[_] = &[3, 4, 2, 0, 1, 5, 6, 1, 2];
|
||||
assert_eq!(writer.get_ref(), b);
|
||||
|
||||
writer.seek(1, io::SeekEnd).unwrap();
|
||||
writer.write([1]).unwrap();
|
||||
writer.write(&[1]).unwrap();
|
||||
let b: &[_] = &[3, 4, 2, 0, 1, 5, 6, 1, 2, 0, 1];
|
||||
assert_eq!(writer.get_ref(), b);
|
||||
}
|
||||
|
@ -172,7 +172,7 @@ mod tests {
|
|||
fn seek_past_end() {
|
||||
let mut r = SeekableMemWriter::new();
|
||||
r.seek(10, io::SeekSet).unwrap();
|
||||
assert!(r.write([3]).is_ok());
|
||||
assert!(r.write(&[3]).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -599,7 +599,7 @@ pub mod reader {
|
|||
f: |&mut Decoder<'doc>, bool| -> DecodeResult<T>) -> DecodeResult<T> {
|
||||
debug!("read_option()");
|
||||
self.read_enum("Option", |this| {
|
||||
this.read_enum_variant(["None", "Some"], |this, idx| {
|
||||
this.read_enum_variant(&["None", "Some"], |this, idx| {
|
||||
match idx {
|
||||
0 => f(this, false),
|
||||
1 => f(this, true),
|
||||
|
@ -1062,7 +1062,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_vuint_at() {
|
||||
let data = [
|
||||
let data = &[
|
||||
0x80,
|
||||
0xff,
|
||||
0x40, 0x00,
|
||||
|
|
|
@ -879,7 +879,7 @@ fn link_args(cmd: &mut Command,
|
|||
v.push_all(morestack.as_vec());
|
||||
cmd.arg(v.as_slice());
|
||||
} else {
|
||||
cmd.args(["-Wl,--whole-archive", "-lmorestack", "-Wl,--no-whole-archive"]);
|
||||
cmd.args(&["-Wl,--whole-archive", "-lmorestack", "-Wl,--no-whole-archive"]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -997,7 +997,7 @@ fn link_args(cmd: &mut Command,
|
|||
if dylib {
|
||||
// On mac we need to tell the linker to let this library be rpathed
|
||||
if sess.target.target.options.is_like_osx {
|
||||
cmd.args(["-dynamiclib", "-Wl,-dylib"]);
|
||||
cmd.args(&["-dynamiclib", "-Wl,-dylib"]);
|
||||
|
||||
if sess.opts.cg.rpath {
|
||||
let mut v = "-Wl,-install_name,@rpath/".as_bytes().to_vec();
|
||||
|
|
|
@ -886,11 +886,11 @@ mod test {
|
|||
#[test]
|
||||
fn test_switch_implies_cfg_test() {
|
||||
let matches =
|
||||
&match getopts(["--test".to_string()], optgroups().as_slice()) {
|
||||
&match getopts(&["--test".to_string()], optgroups().as_slice()) {
|
||||
Ok(m) => m,
|
||||
Err(f) => panic!("test_switch_implies_cfg_test: {}", f)
|
||||
};
|
||||
let registry = diagnostics::registry::Registry::new([]);
|
||||
let registry = diagnostics::registry::Registry::new(&[]);
|
||||
let sessopts = build_session_options(matches);
|
||||
let sess = build_session(sessopts, None, registry);
|
||||
let cfg = build_configuration(&sess);
|
||||
|
@ -902,14 +902,14 @@ mod test {
|
|||
#[test]
|
||||
fn test_switch_implies_cfg_test_unless_cfg_test() {
|
||||
let matches =
|
||||
&match getopts(["--test".to_string(), "--cfg=test".to_string()],
|
||||
&match getopts(&["--test".to_string(), "--cfg=test".to_string()],
|
||||
optgroups().as_slice()) {
|
||||
Ok(m) => m,
|
||||
Err(f) => {
|
||||
panic!("test_switch_implies_cfg_test_unless_cfg_test: {}", f)
|
||||
}
|
||||
};
|
||||
let registry = diagnostics::registry::Registry::new([]);
|
||||
let registry = diagnostics::registry::Registry::new(&[]);
|
||||
let sessopts = build_session_options(matches);
|
||||
let sess = build_session(sessopts, None, registry);
|
||||
let cfg = build_configuration(&sess);
|
||||
|
|
|
@ -543,7 +543,7 @@ pub fn phase_5_run_llvm_passes(sess: &Session,
|
|||
let output_type = write::OutputTypeAssembly;
|
||||
|
||||
time(sess.time_passes(), "LLVM passes", (), |_|
|
||||
write::run_passes(sess, trans, [output_type], outputs));
|
||||
write::run_passes(sess, trans, &[output_type], outputs));
|
||||
|
||||
write::run_assembler(sess, outputs);
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ fn run_compiler(args: &[String]) {
|
|||
None => return
|
||||
};
|
||||
|
||||
let descriptions = diagnostics::registry::Registry::new(super::DIAGNOSTICS);
|
||||
let descriptions = diagnostics::registry::Registry::new(&super::DIAGNOSTICS);
|
||||
match matches.opt_str("explain") {
|
||||
Some(ref code) => {
|
||||
match descriptions.find_description(code.as_slice()) {
|
||||
|
|
|
@ -345,7 +345,7 @@ fn parse_str(st: &mut PState, term: char) -> String {
|
|||
let mut result = String::new();
|
||||
while peek(st) != term {
|
||||
unsafe {
|
||||
result.as_mut_vec().push_all([next_byte(st)])
|
||||
result.as_mut_vec().push_all(&[next_byte(st)])
|
||||
}
|
||||
}
|
||||
next(st);
|
||||
|
|
|
@ -748,10 +748,10 @@ impl<'a> vtable_decoder_helpers for reader::Decoder<'a> {
|
|||
tcx: &ty::ctxt, cdata: &cstore::crate_metadata)
|
||||
-> typeck::vtable_origin {
|
||||
self.read_enum("vtable_origin", |this| {
|
||||
this.read_enum_variant(["vtable_static",
|
||||
"vtable_param",
|
||||
"vtable_error",
|
||||
"vtable_unboxed_closure"],
|
||||
this.read_enum_variant(&["vtable_static",
|
||||
"vtable_param",
|
||||
"vtable_error",
|
||||
"vtable_unboxed_closure"],
|
||||
|this, i| {
|
||||
Ok(match i {
|
||||
0 => {
|
||||
|
@ -1401,8 +1401,8 @@ impl<'a> rbml_decoder_decoder_helpers for reader::Decoder<'a> {
|
|||
-> typeck::MethodOrigin
|
||||
{
|
||||
self.read_enum("MethodOrigin", |this| {
|
||||
let variants = ["MethodStatic", "MethodStaticUnboxedClosure",
|
||||
"MethodTypeParam", "MethodTraitObject"];
|
||||
let variants = &["MethodStatic", "MethodStaticUnboxedClosure",
|
||||
"MethodTypeParam", "MethodTraitObject"];
|
||||
this.read_enum_variant(variants, |this, i| {
|
||||
Ok(match i {
|
||||
0 => {
|
||||
|
@ -1576,7 +1576,7 @@ impl<'a> rbml_decoder_decoder_helpers for reader::Decoder<'a> {
|
|||
fn read_auto_adjustment(&mut self, dcx: &DecodeContext) -> ty::AutoAdjustment {
|
||||
self.read_enum("AutoAdjustment", |this| {
|
||||
let variants = ["AutoAddEnv", "AutoDerefRef"];
|
||||
this.read_enum_variant(variants, |this, i| {
|
||||
this.read_enum_variant(&variants, |this, i| {
|
||||
Ok(match i {
|
||||
0 => {
|
||||
let store: ty::TraitStore =
|
||||
|
@ -1622,7 +1622,7 @@ impl<'a> rbml_decoder_decoder_helpers for reader::Decoder<'a> {
|
|||
"AutoUnsize",
|
||||
"AutoUnsizeUniq",
|
||||
"AutoUnsafe"];
|
||||
this.read_enum_variant(variants, |this, i| {
|
||||
this.read_enum_variant(&variants, |this, i| {
|
||||
Ok(match i {
|
||||
0 => {
|
||||
let r: ty::Region =
|
||||
|
@ -1676,7 +1676,7 @@ impl<'a> rbml_decoder_decoder_helpers for reader::Decoder<'a> {
|
|||
|
||||
fn read_unsize_kind(&mut self, dcx: &DecodeContext) -> ty::UnsizeKind {
|
||||
self.read_enum("UnsizeKind", |this| {
|
||||
let variants = ["UnsizeLength", "UnsizeStruct", "UnsizeVtable"];
|
||||
let variants = &["UnsizeLength", "UnsizeStruct", "UnsizeVtable"];
|
||||
this.read_enum_variant(variants, |this, i| {
|
||||
Ok(match i {
|
||||
0 => {
|
||||
|
@ -1726,7 +1726,7 @@ impl<'a> rbml_decoder_decoder_helpers for reader::Decoder<'a> {
|
|||
dcx.tcx,
|
||||
|s, a| this.convert_def_id(dcx, s, a)))
|
||||
}).unwrap();
|
||||
let variants = [
|
||||
let variants = &[
|
||||
"FnUnboxedClosureKind",
|
||||
"FnMutUnboxedClosureKind",
|
||||
"FnOnceUnboxedClosureKind"
|
||||
|
|
|
@ -73,19 +73,19 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
|
|||
|
||||
let expr_exit = self.opt_expr(&blk.expr, stmts_exit);
|
||||
|
||||
self.add_node(blk.id, [expr_exit])
|
||||
self.add_node(blk.id, &[expr_exit])
|
||||
}
|
||||
|
||||
fn stmt(&mut self, stmt: &ast::Stmt, pred: CFGIndex) -> CFGIndex {
|
||||
match stmt.node {
|
||||
ast::StmtDecl(ref decl, id) => {
|
||||
let exit = self.decl(&**decl, pred);
|
||||
self.add_node(id, [exit])
|
||||
self.add_node(id, &[exit])
|
||||
}
|
||||
|
||||
ast::StmtExpr(ref expr, id) | ast::StmtSemi(ref expr, id) => {
|
||||
let exit = self.expr(&**expr, pred);
|
||||
self.add_node(id, [exit])
|
||||
self.add_node(id, &[exit])
|
||||
}
|
||||
|
||||
ast::StmtMac(..) => {
|
||||
|
@ -114,33 +114,33 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
|
|||
ast::PatLit(..) |
|
||||
ast::PatRange(..) |
|
||||
ast::PatWild(_) => {
|
||||
self.add_node(pat.id, [pred])
|
||||
self.add_node(pat.id, &[pred])
|
||||
}
|
||||
|
||||
ast::PatBox(ref subpat) |
|
||||
ast::PatRegion(ref subpat) |
|
||||
ast::PatIdent(_, _, Some(ref subpat)) => {
|
||||
let subpat_exit = self.pat(&**subpat, pred);
|
||||
self.add_node(pat.id, [subpat_exit])
|
||||
self.add_node(pat.id, &[subpat_exit])
|
||||
}
|
||||
|
||||
ast::PatEnum(_, Some(ref subpats)) |
|
||||
ast::PatTup(ref subpats) => {
|
||||
let pats_exit = self.pats_all(subpats.iter(), pred);
|
||||
self.add_node(pat.id, [pats_exit])
|
||||
self.add_node(pat.id, &[pats_exit])
|
||||
}
|
||||
|
||||
ast::PatStruct(_, ref subpats, _) => {
|
||||
let pats_exit =
|
||||
self.pats_all(subpats.iter().map(|f| &f.node.pat), pred);
|
||||
self.add_node(pat.id, [pats_exit])
|
||||
self.add_node(pat.id, &[pats_exit])
|
||||
}
|
||||
|
||||
ast::PatVec(ref pre, ref vec, ref post) => {
|
||||
let pre_exit = self.pats_all(pre.iter(), pred);
|
||||
let vec_exit = self.pats_all(vec.iter(), pre_exit);
|
||||
let post_exit = self.pats_all(post.iter(), vec_exit);
|
||||
self.add_node(pat.id, [post_exit])
|
||||
self.add_node(pat.id, &[post_exit])
|
||||
}
|
||||
|
||||
ast::PatMac(_) => {
|
||||
|
@ -165,7 +165,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
|
|||
if pats.len() == 1 {
|
||||
self.pat(&*pats[0], pred)
|
||||
} else {
|
||||
let collect = self.add_dummy_node([]);
|
||||
let collect = self.add_dummy_node(&[]);
|
||||
for pat in pats.iter() {
|
||||
let pat_exit = self.pat(&**pat, pred);
|
||||
self.add_contained_edge(pat_exit, collect);
|
||||
|
@ -178,7 +178,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
|
|||
match expr.node {
|
||||
ast::ExprBlock(ref blk) => {
|
||||
let blk_exit = self.block(&**blk, pred);
|
||||
self.add_node(expr.id, [blk_exit])
|
||||
self.add_node(expr.id, &[blk_exit])
|
||||
}
|
||||
|
||||
ast::ExprIf(ref cond, ref then, None) => {
|
||||
|
@ -198,7 +198,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
|
|||
//
|
||||
let cond_exit = self.expr(&**cond, pred); // 1
|
||||
let then_exit = self.block(&**then, cond_exit); // 2
|
||||
self.add_node(expr.id, [cond_exit, then_exit]) // 3,4
|
||||
self.add_node(expr.id, &[cond_exit, then_exit]) // 3,4
|
||||
}
|
||||
|
||||
ast::ExprIf(ref cond, ref then, Some(ref otherwise)) => {
|
||||
|
@ -219,7 +219,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
|
|||
let cond_exit = self.expr(&**cond, pred); // 1
|
||||
let then_exit = self.block(&**then, cond_exit); // 2
|
||||
let else_exit = self.expr(&**otherwise, cond_exit); // 3
|
||||
self.add_node(expr.id, [then_exit, else_exit]) // 4, 5
|
||||
self.add_node(expr.id, &[then_exit, else_exit]) // 4, 5
|
||||
}
|
||||
|
||||
ast::ExprIfLet(..) => {
|
||||
|
@ -245,9 +245,9 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
|
|||
// may cause additional edges.
|
||||
|
||||
// Is the condition considered part of the loop?
|
||||
let loopback = self.add_dummy_node([pred]); // 1
|
||||
let cond_exit = self.expr(&**cond, loopback); // 2
|
||||
let expr_exit = self.add_node(expr.id, [cond_exit]); // 3
|
||||
let loopback = self.add_dummy_node(&[pred]); // 1
|
||||
let cond_exit = self.expr(&**cond, loopback); // 2
|
||||
let expr_exit = self.add_node(expr.id, &[cond_exit]); // 3
|
||||
self.loop_scopes.push(LoopScope {
|
||||
loop_id: expr.id,
|
||||
continue_index: loopback,
|
||||
|
@ -286,10 +286,10 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
|
|||
// Note that `break` and `continue` statements
|
||||
// may cause additional edges.
|
||||
|
||||
let head = self.expr(&**head, pred); // 1
|
||||
let loopback = self.add_dummy_node([head]); // 2
|
||||
let cond = self.add_dummy_node([loopback]); // 3
|
||||
let expr_exit = self.add_node(expr.id, [cond]); // 4
|
||||
let head = self.expr(&**head, pred); // 1
|
||||
let loopback = self.add_dummy_node(&[head]); // 2
|
||||
let cond = self.add_dummy_node(&[loopback]); // 3
|
||||
let expr_exit = self.add_node(expr.id, &[cond]); // 4
|
||||
self.loop_scopes.push(LoopScope {
|
||||
loop_id: expr.id,
|
||||
continue_index: loopback,
|
||||
|
@ -317,8 +317,8 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
|
|||
// Note that `break` and `loop` statements
|
||||
// may cause additional edges.
|
||||
|
||||
let loopback = self.add_dummy_node([pred]); // 1
|
||||
let expr_exit = self.add_node(expr.id, []); // 2
|
||||
let loopback = self.add_dummy_node(&[pred]); // 1
|
||||
let expr_exit = self.add_node(expr.id, &[]); // 2
|
||||
self.loop_scopes.push(LoopScope {
|
||||
loop_id: expr.id,
|
||||
continue_index: loopback,
|
||||
|
@ -358,10 +358,10 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
|
|||
//
|
||||
let discr_exit = self.expr(&**discr, pred); // 1
|
||||
|
||||
let expr_exit = self.add_node(expr.id, []);
|
||||
let expr_exit = self.add_node(expr.id, &[]);
|
||||
let mut cond_exit = discr_exit;
|
||||
for arm in arms.iter() {
|
||||
cond_exit = self.add_dummy_node([cond_exit]); // 2
|
||||
cond_exit = self.add_dummy_node(&[cond_exit]); // 2
|
||||
let pats_exit = self.pats_any(arm.pats.as_slice(),
|
||||
cond_exit); // 3
|
||||
let guard_exit = self.opt_expr(&arm.guard,
|
||||
|
@ -389,30 +389,30 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
|
|||
//
|
||||
let l_exit = self.expr(&**l, pred); // 1
|
||||
let r_exit = self.expr(&**r, l_exit); // 2
|
||||
self.add_node(expr.id, [l_exit, r_exit]) // 3,4
|
||||
self.add_node(expr.id, &[l_exit, r_exit]) // 3,4
|
||||
}
|
||||
|
||||
ast::ExprRet(ref v) => {
|
||||
let v_exit = self.opt_expr(v, pred);
|
||||
let b = self.add_node(expr.id, [v_exit]);
|
||||
let b = self.add_node(expr.id, &[v_exit]);
|
||||
self.add_returning_edge(expr, b);
|
||||
self.add_node(ast::DUMMY_NODE_ID, [])
|
||||
self.add_node(ast::DUMMY_NODE_ID, &[])
|
||||
}
|
||||
|
||||
ast::ExprBreak(label) => {
|
||||
let loop_scope = self.find_scope(expr, label);
|
||||
let b = self.add_node(expr.id, [pred]);
|
||||
let b = self.add_node(expr.id, &[pred]);
|
||||
self.add_exiting_edge(expr, b,
|
||||
loop_scope, loop_scope.break_index);
|
||||
self.add_node(ast::DUMMY_NODE_ID, [])
|
||||
self.add_node(ast::DUMMY_NODE_ID, &[])
|
||||
}
|
||||
|
||||
ast::ExprAgain(label) => {
|
||||
let loop_scope = self.find_scope(expr, label);
|
||||
let a = self.add_node(expr.id, [pred]);
|
||||
let a = self.add_node(expr.id, &[pred]);
|
||||
self.add_exiting_edge(expr, a,
|
||||
loop_scope, loop_scope.continue_index);
|
||||
self.add_node(ast::DUMMY_NODE_ID, [])
|
||||
self.add_node(ast::DUMMY_NODE_ID, &[])
|
||||
}
|
||||
|
||||
ast::ExprVec(ref elems) => {
|
||||
|
@ -492,7 +492,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
|
|||
let &(_, ref expr, _) = a;
|
||||
&**expr
|
||||
}), post_inputs);
|
||||
self.add_node(expr.id, [post_outputs])
|
||||
self.add_node(expr.id, &[post_outputs])
|
||||
}
|
||||
|
||||
ast::ExprMac(..) |
|
||||
|
@ -520,7 +520,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
|
|||
let func_or_rcvr_exit = self.expr(func_or_rcvr, pred);
|
||||
let ret = self.straightline(call_expr, func_or_rcvr_exit, args);
|
||||
if return_ty == ty::FnDiverging {
|
||||
self.add_node(ast::DUMMY_NODE_ID, [])
|
||||
self.add_node(ast::DUMMY_NODE_ID, &[])
|
||||
} else {
|
||||
ret
|
||||
}
|
||||
|
@ -547,7 +547,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
|
|||
//! Handles case of an expression that evaluates `subexprs` in order
|
||||
|
||||
let subexprs_exit = self.exprs(subexprs, pred);
|
||||
self.add_node(expr.id, [subexprs_exit])
|
||||
self.add_node(expr.id, &[subexprs_exit])
|
||||
}
|
||||
|
||||
fn add_dummy_node(&mut self, preds: &[CFGIndex]) -> CFGIndex {
|
||||
|
|
|
@ -40,7 +40,7 @@ fn replace_newline_with_backslash_l(s: String) -> String {
|
|||
let mut last_two: Vec<_> =
|
||||
s.as_slice().chars().rev().take(2).collect();
|
||||
last_two.reverse();
|
||||
if last_two.as_slice() != ['\\', 'l'] {
|
||||
if last_two.as_slice() != &['\\', 'l'] {
|
||||
s.push_str("\\l");
|
||||
}
|
||||
s
|
||||
|
|
|
@ -932,7 +932,7 @@ fn check_fn(cx: &mut MatchCheckCtxt,
|
|||
|
||||
fn is_refutable<A>(cx: &MatchCheckCtxt, pat: &Pat, refutable: |&Pat| -> A) -> Option<A> {
|
||||
let pats = Matrix(vec!(vec!(pat)));
|
||||
match is_useful(cx, &pats, [DUMMY_WILD_PAT], ConstructWitness) {
|
||||
match is_useful(cx, &pats, &[DUMMY_WILD_PAT], ConstructWitness) {
|
||||
UsefulWithWitness(pats) => {
|
||||
assert_eq!(pats.len(), 1);
|
||||
Some(refutable(&*pats[0]))
|
||||
|
|
|
@ -419,31 +419,31 @@ mod test {
|
|||
fn each_adjacent_from_a() {
|
||||
let graph = create_graph();
|
||||
test_adjacent_edges(&graph, NodeIndex(0), "A",
|
||||
[],
|
||||
[("AB", "B")]);
|
||||
&[],
|
||||
&[("AB", "B")]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn each_adjacent_from_b() {
|
||||
let graph = create_graph();
|
||||
test_adjacent_edges(&graph, NodeIndex(1), "B",
|
||||
[("FB", "F"), ("AB", "A"),],
|
||||
[("BD", "D"), ("BC", "C"),]);
|
||||
&[("FB", "F"), ("AB", "A"),],
|
||||
&[("BD", "D"), ("BC", "C"),]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn each_adjacent_from_c() {
|
||||
let graph = create_graph();
|
||||
test_adjacent_edges(&graph, NodeIndex(2), "C",
|
||||
[("EC", "E"), ("BC", "B")],
|
||||
[]);
|
||||
&[("EC", "E"), ("BC", "B")],
|
||||
&[]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn each_adjacent_from_d() {
|
||||
let graph = create_graph();
|
||||
test_adjacent_edges(&graph, NodeIndex(3), "D",
|
||||
[("BD", "B")],
|
||||
[("DE", "E")]);
|
||||
&[("BD", "B")],
|
||||
&[("DE", "E")]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ pub fn supertraits<'cx, 'tcx>(tcx: &'cx ty::ctxt<'tcx>,
|
|||
* `supertraits(Baz)` yields `[Baz, Bar, Foo, Foo]` in some order.
|
||||
*/
|
||||
|
||||
transitive_bounds(tcx, [trait_ref])
|
||||
transitive_bounds(tcx, &[trait_ref])
|
||||
}
|
||||
|
||||
pub fn transitive_bounds<'cx, 'tcx>(tcx: &'cx ty::ctxt<'tcx>,
|
||||
|
|
|
@ -643,8 +643,8 @@ fn bind_subslice_pat(bcx: Block,
|
|||
ty::mt {ty: vt.unit_ty, mutbl: ast::MutImmutable});
|
||||
let scratch = rvalue_scratch_datum(bcx, slice_ty, "");
|
||||
Store(bcx, slice_begin,
|
||||
GEPi(bcx, scratch.val, [0u, abi::slice_elt_base]));
|
||||
Store(bcx, slice_len, GEPi(bcx, scratch.val, [0u, abi::slice_elt_len]));
|
||||
GEPi(bcx, scratch.val, &[0u, abi::slice_elt_base]));
|
||||
Store(bcx, slice_len, GEPi(bcx, scratch.val, &[0u, abi::slice_elt_len]));
|
||||
scratch.val
|
||||
}
|
||||
|
||||
|
@ -658,9 +658,9 @@ fn extract_vec_elems<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
let vec_datum = match_datum(val, left_ty);
|
||||
let (base, len) = vec_datum.get_vec_base_and_len(bcx);
|
||||
let mut elems = vec![];
|
||||
elems.extend(range(0, before).map(|i| GEPi(bcx, base, [i])));
|
||||
elems.extend(range(0, before).map(|i| GEPi(bcx, base, &[i])));
|
||||
elems.extend(range(0, after).rev().map(|i| {
|
||||
InBoundsGEP(bcx, base, [
|
||||
InBoundsGEP(bcx, base, &[
|
||||
Sub(bcx, len, C_uint(bcx.ccx(), i + 1))
|
||||
])
|
||||
}));
|
||||
|
@ -796,7 +796,7 @@ fn compare_values<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
|
|||
format!("comparison of `{}`",
|
||||
cx.ty_to_string(rhs_t)).as_slice(),
|
||||
StrEqFnLangItem);
|
||||
callee::trans_lang_call(cx, did, [lhs, rhs], None)
|
||||
callee::trans_lang_call(cx, did, &[lhs, rhs], None)
|
||||
}
|
||||
|
||||
let _icx = push_ctxt("compare_values");
|
||||
|
@ -1390,7 +1390,7 @@ fn trans_match_inner<'blk, 'tcx>(scope_cx: Block<'blk, 'tcx>,
|
|||
&& arm.pats.last().unwrap().node == ast::PatWild(ast::PatWildSingle)
|
||||
});
|
||||
|
||||
compile_submatch(bcx, matches.as_slice(), [discr_datum.val], &chk, has_default);
|
||||
compile_submatch(bcx, matches.as_slice(), &[discr_datum.val], &chk, has_default);
|
||||
|
||||
let mut arm_cxs = Vec::new();
|
||||
for arm_data in arm_datas.iter() {
|
||||
|
|
|
@ -635,7 +635,7 @@ pub fn trans_get_discr(bcx: Block, r: &Repr, scrutinee: ValueRef, cast_to: Optio
|
|||
signed = ity.is_signed();
|
||||
}
|
||||
General(ity, ref cases, _) => {
|
||||
let ptr = GEPi(bcx, scrutinee, [0, 0]);
|
||||
let ptr = GEPi(bcx, scrutinee, &[0, 0]);
|
||||
val = load_discr(bcx, ity, ptr, 0, (cases.len() - 1) as Disr);
|
||||
signed = ity.is_signed();
|
||||
}
|
||||
|
@ -663,8 +663,8 @@ pub fn trans_get_discr(bcx: Block, r: &Repr, scrutinee: ValueRef, cast_to: Optio
|
|||
fn struct_wrapped_nullable_bitdiscr(bcx: Block, nndiscr: Disr, ptrfield: PointerField,
|
||||
scrutinee: ValueRef) -> ValueRef {
|
||||
let llptrptr = match ptrfield {
|
||||
ThinPointer(field) => GEPi(bcx, scrutinee, [0, field]),
|
||||
FatPointer(field) => GEPi(bcx, scrutinee, [0, field, slice_elt_base])
|
||||
ThinPointer(field) => GEPi(bcx, scrutinee, &[0, field]),
|
||||
FatPointer(field) => GEPi(bcx, scrutinee, &[0, field, slice_elt_base])
|
||||
};
|
||||
let llptr = Load(bcx, llptrptr);
|
||||
let cmp = if nndiscr == 0 { IntEQ } else { IntNE };
|
||||
|
@ -739,13 +739,13 @@ pub fn trans_set_discr(bcx: Block, r: &Repr, val: ValueRef, discr: Disr) {
|
|||
Store(bcx, C_u8(bcx.ccx(), 1), ptr);
|
||||
}
|
||||
Store(bcx, C_integral(ll_inttype(bcx.ccx(), ity), discr as u64, true),
|
||||
GEPi(bcx, val, [0, 0]))
|
||||
GEPi(bcx, val, &[0, 0]))
|
||||
}
|
||||
Univariant(ref st, dtor) => {
|
||||
assert_eq!(discr, 0);
|
||||
if dtor {
|
||||
Store(bcx, C_u8(bcx.ccx(), 1),
|
||||
GEPi(bcx, val, [0, st.fields.len() - 1]));
|
||||
GEPi(bcx, val, &[0, st.fields.len() - 1]));
|
||||
}
|
||||
}
|
||||
RawNullablePointer { nndiscr, nnty, ..} => {
|
||||
|
@ -758,10 +758,10 @@ pub fn trans_set_discr(bcx: Block, r: &Repr, val: ValueRef, discr: Disr) {
|
|||
if discr != nndiscr {
|
||||
let (llptrptr, llptrty) = match ptrfield {
|
||||
ThinPointer(field) =>
|
||||
(GEPi(bcx, val, [0, field]),
|
||||
(GEPi(bcx, val, &[0, field]),
|
||||
type_of::type_of(bcx.ccx(), nonnull.fields[field])),
|
||||
FatPointer(field) => {
|
||||
let v = GEPi(bcx, val, [0, field, slice_elt_base]);
|
||||
let v = GEPi(bcx, val, &[0, field, slice_elt_base]);
|
||||
(v, val_ty(v).element_type())
|
||||
}
|
||||
};
|
||||
|
@ -853,7 +853,7 @@ pub fn struct_field_ptr(bcx: Block, st: &Struct, val: ValueRef,
|
|||
val
|
||||
};
|
||||
|
||||
GEPi(bcx, val, [0, ix])
|
||||
GEPi(bcx, val, &[0, ix])
|
||||
}
|
||||
|
||||
pub fn fold_variants<'blk, 'tcx>(
|
||||
|
@ -902,7 +902,7 @@ pub fn trans_drop_flag_ptr<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, r: &Repr, val
|
|||
let ptr_ty = ty::mk_imm_ptr(bcx.tcx(), ty::mk_bool());
|
||||
match *r {
|
||||
Univariant(ref st, true) => {
|
||||
let flag_ptr = GEPi(bcx, val, [0, st.fields.len() - 1]);
|
||||
let flag_ptr = GEPi(bcx, val, &[0, st.fields.len() - 1]);
|
||||
datum::immediate_rvalue_bcx(bcx, flag_ptr, ptr_ty).to_expr_datumblock()
|
||||
}
|
||||
General(_, _, true) => {
|
||||
|
@ -961,7 +961,7 @@ pub fn trans_const(ccx: &CrateContext, r: &Repr, discr: Disr,
|
|||
let mut f = vec![lldiscr];
|
||||
f.push_all(vals);
|
||||
let mut contents = build_const_struct(ccx, case, f.as_slice());
|
||||
contents.push_all([padding(ccx, max_sz - case.size)]);
|
||||
contents.push_all(&[padding(ccx, max_sz - case.size)]);
|
||||
C_struct(ccx, contents.as_slice(), false)
|
||||
}
|
||||
Univariant(ref st, _dro) => {
|
||||
|
@ -1079,8 +1079,8 @@ pub fn const_get_discrim(ccx: &CrateContext, r: &Repr, val: ValueRef)
|
|||
}
|
||||
General(ity, _, _) => {
|
||||
match ity {
|
||||
attr::SignedInt(..) => const_to_int(const_get_elt(ccx, val, [0])) as Disr,
|
||||
attr::UnsignedInt(..) => const_to_uint(const_get_elt(ccx, val, [0])) as Disr
|
||||
attr::SignedInt(..) => const_to_int(const_get_elt(ccx, val, &[0])) as Disr,
|
||||
attr::UnsignedInt(..) => const_to_uint(const_get_elt(ccx, val, &[0])) as Disr
|
||||
}
|
||||
}
|
||||
Univariant(..) => 0,
|
||||
|
@ -1138,8 +1138,8 @@ fn const_struct_field(ccx: &CrateContext, val: ValueRef, ix: uint, sub_idx: Opti
|
|||
loop {
|
||||
loop {
|
||||
field = match sub_idx {
|
||||
Some(si) => const_get_elt(ccx, val, [real_ix, si as u32]),
|
||||
None => const_get_elt(ccx, val, [real_ix])
|
||||
Some(si) => const_get_elt(ccx, val, &[real_ix, si as u32]),
|
||||
None => const_get_elt(ccx, val, &[real_ix])
|
||||
};
|
||||
if !is_undef(field) {
|
||||
break;
|
||||
|
|
|
@ -337,7 +337,7 @@ pub fn at_box_body(bcx: Block, body_t: ty::t, boxptr: ValueRef) -> ValueRef {
|
|||
let ccx = bcx.ccx();
|
||||
let ty = Type::at_box(ccx, type_of(ccx, body_t));
|
||||
let boxptr = PointerCast(bcx, boxptr, ty.ptr_to());
|
||||
GEPi(bcx, boxptr, [0u, abi::box_field_body])
|
||||
GEPi(bcx, boxptr, &[0u, abi::box_field_body])
|
||||
}
|
||||
|
||||
fn require_alloc_fn(bcx: Block, info_ty: ty::t, it: LangItem) -> ast::DefId {
|
||||
|
@ -365,7 +365,7 @@ pub fn malloc_raw_dyn<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
// Allocate space:
|
||||
let r = callee::trans_lang_call(bcx,
|
||||
require_alloc_fn(bcx, info_ty, ExchangeMallocFnLangItem),
|
||||
[size, align],
|
||||
&[size, align],
|
||||
None);
|
||||
|
||||
Result::new(r.bcx, PointerCast(r.bcx, r.val, llty_ptr))
|
||||
|
@ -385,7 +385,7 @@ pub fn malloc_raw_dyn_proc<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, t: ty::t) -> Resu
|
|||
|
||||
// Allocate space and store the destructor pointer:
|
||||
let Result {bcx, val: llbox} = malloc_raw_dyn(bcx, ptr_llty, t, size, llalign);
|
||||
let dtor_ptr = GEPi(bcx, llbox, [0u, abi::box_field_drop_glue]);
|
||||
let dtor_ptr = GEPi(bcx, llbox, &[0u, abi::box_field_drop_glue]);
|
||||
let drop_glue_field_ty = type_of(ccx, ty::mk_nil_ptr(bcx.tcx()));
|
||||
let drop_glue = PointerCast(bcx, glue::get_drop_glue(ccx, ty::mk_uniq(bcx.tcx(), t)),
|
||||
drop_glue_field_ty);
|
||||
|
@ -517,7 +517,7 @@ pub fn get_res_dtor(ccx: &CrateContext,
|
|||
let class_ty = ty::lookup_item_type(tcx, parent_id).ty.subst(tcx, substs);
|
||||
let llty = type_of_dtor(ccx, class_ty);
|
||||
let dtor_ty = ty::mk_ctor_fn(ccx.tcx(), ast::DUMMY_NODE_ID,
|
||||
[glue::get_drop_glue_type(ccx, t)], ty::mk_nil(ccx.tcx()));
|
||||
&[glue::get_drop_glue_type(ccx, t)], ty::mk_nil(ccx.tcx()));
|
||||
get_extern_fn(ccx,
|
||||
&mut *ccx.externs().borrow_mut(),
|
||||
name.as_slice(),
|
||||
|
@ -694,8 +694,8 @@ pub fn iter_structural_ty<'a, 'blk, 'tcx>(cx: Block<'blk, 'tcx>,
|
|||
let (data_ptr, info) = if ty::type_is_sized(cx.tcx(), t) {
|
||||
(av, None)
|
||||
} else {
|
||||
let data = GEPi(cx, av, [0, abi::slice_elt_base]);
|
||||
let info = GEPi(cx, av, [0, abi::slice_elt_len]);
|
||||
let data = GEPi(cx, av, &[0, abi::slice_elt_base]);
|
||||
let info = GEPi(cx, av, &[0, abi::slice_elt_len]);
|
||||
(Load(cx, data), Some(Load(cx, info)))
|
||||
};
|
||||
|
||||
|
@ -713,8 +713,8 @@ pub fn iter_structural_ty<'a, 'blk, 'tcx>(cx: Block<'blk, 'tcx>,
|
|||
} else {
|
||||
let boxed_ty = ty::mk_open(cx.tcx(), field_ty);
|
||||
let scratch = datum::rvalue_scratch_datum(cx, boxed_ty, "__fat_ptr_iter");
|
||||
Store(cx, llfld_a, GEPi(cx, scratch.val, [0, abi::slice_elt_base]));
|
||||
Store(cx, info.unwrap(), GEPi(cx, scratch.val, [0, abi::slice_elt_len]));
|
||||
Store(cx, llfld_a, GEPi(cx, scratch.val, &[0, abi::slice_elt_base]));
|
||||
Store(cx, info.unwrap(), GEPi(cx, scratch.val, &[0, abi::slice_elt_len]));
|
||||
scratch.val
|
||||
};
|
||||
cx = f(cx, val, field_ty);
|
||||
|
@ -1110,7 +1110,7 @@ pub fn call_lifetime_start(cx: Block, ptr: ValueRef) {
|
|||
let llsize = C_u64(ccx, machine::llsize_of_alloc(ccx, val_ty(ptr).element_type()));
|
||||
let ptr = PointerCast(cx, ptr, Type::i8p(ccx));
|
||||
let lifetime_start = ccx.get_intrinsic(&"llvm.lifetime.start");
|
||||
Call(cx, lifetime_start, [llsize, ptr], None);
|
||||
Call(cx, lifetime_start, &[llsize, ptr], None);
|
||||
}
|
||||
|
||||
pub fn call_lifetime_end(cx: Block, ptr: ValueRef) {
|
||||
|
@ -1124,7 +1124,7 @@ pub fn call_lifetime_end(cx: Block, ptr: ValueRef) {
|
|||
let llsize = C_u64(ccx, machine::llsize_of_alloc(ccx, val_ty(ptr).element_type()));
|
||||
let ptr = PointerCast(cx, ptr, Type::i8p(ccx));
|
||||
let lifetime_end = ccx.get_intrinsic(&"llvm.lifetime.end");
|
||||
Call(cx, lifetime_end, [llsize, ptr], None);
|
||||
Call(cx, lifetime_end, &[llsize, ptr], None);
|
||||
}
|
||||
|
||||
pub fn call_memcpy(cx: Block, dst: ValueRef, src: ValueRef, n_bytes: ValueRef, align: u32) {
|
||||
|
@ -1141,7 +1141,7 @@ pub fn call_memcpy(cx: Block, dst: ValueRef, src: ValueRef, n_bytes: ValueRef, a
|
|||
let size = IntCast(cx, n_bytes, ccx.int_type());
|
||||
let align = C_i32(ccx, align as i32);
|
||||
let volatile = C_bool(ccx, false);
|
||||
Call(cx, memcpy, [dst_ptr, src_ptr, size, align, volatile], None);
|
||||
Call(cx, memcpy, &[dst_ptr, src_ptr, size, align, volatile], None);
|
||||
}
|
||||
|
||||
pub fn memcpy_ty(bcx: Block, dst: ValueRef, src: ValueRef, t: ty::t) {
|
||||
|
@ -1187,7 +1187,7 @@ fn memzero(b: &Builder, llptr: ValueRef, ty: ty::t) {
|
|||
let size = machine::llsize_of(ccx, llty);
|
||||
let align = C_i32(ccx, type_of::align_of(ccx, ty) as i32);
|
||||
let volatile = C_bool(ccx, false);
|
||||
b.call(llintrinsicfn, [llptr, llzeroval, size, align, volatile], None);
|
||||
b.call(llintrinsicfn, &[llptr, llzeroval, size, align, volatile], None);
|
||||
}
|
||||
|
||||
pub fn alloc_ty(bcx: Block, t: ty::t, name: &str) -> ValueRef {
|
||||
|
@ -1563,7 +1563,7 @@ fn create_datums_for_fn_args_under_call_abi(
|
|||
let llarg =
|
||||
get_param(bcx.fcx.llfn,
|
||||
bcx.fcx.arg_pos(i + j) as c_uint);
|
||||
let lldest = GEPi(bcx, llval, [0, j]);
|
||||
let lldest = GEPi(bcx, llval, &[0, j]);
|
||||
let datum = datum::Datum::new(
|
||||
llarg,
|
||||
tupled_arg_ty,
|
||||
|
@ -1654,7 +1654,7 @@ fn copy_unboxed_closure_args_to_allocas<'blk, 'tcx>(
|
|||
let tuple_element_datum =
|
||||
tuple_datum.get_element(bcx,
|
||||
tuple_element_type,
|
||||
|llval| GEPi(bcx, llval, [0, j]));
|
||||
|llval| GEPi(bcx, llval, &[0, j]));
|
||||
let tuple_element_datum = tuple_element_datum.to_expr_datum();
|
||||
let tuple_element_datum =
|
||||
unpack_datum!(bcx,
|
||||
|
@ -2551,7 +2551,7 @@ pub fn create_entry_wrapper(ccx: &CrateContext,
|
|||
fn create_entry_fn(ccx: &CrateContext,
|
||||
rust_main: ValueRef,
|
||||
use_start_lang_item: bool) {
|
||||
let llfty = Type::func([ccx.int_type(), Type::i8p(ccx).ptr_to()],
|
||||
let llfty = Type::func(&[ccx.int_type(), Type::i8p(ccx).ptr_to()],
|
||||
&ccx.int_type());
|
||||
|
||||
let llfn = decl_cdecl_fn(ccx, "main", llfty, ty::mk_nil(ccx.tcx()));
|
||||
|
@ -2908,7 +2908,7 @@ pub fn write_metadata(cx: &SharedCrateContext, krate: &ast::Crate) -> Vec<u8> {
|
|||
None => cx.sess().fatal("failed to compress metadata"),
|
||||
}.as_slice());
|
||||
let llmeta = C_bytes_in_context(cx.metadata_llcx(), compressed.as_slice());
|
||||
let llconst = C_struct_in_context(cx.metadata_llcx(), [llmeta], false);
|
||||
let llconst = C_struct_in_context(cx.metadata_llcx(), &[llmeta], false);
|
||||
let name = format!("rust_metadata_{}_{}",
|
||||
cx.link_meta().crate_name,
|
||||
cx.link_meta().crate_hash);
|
||||
|
|
|
@ -776,11 +776,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
self.count_insn("inlineasm");
|
||||
let asm = comment_text.as_slice().with_c_str(|c| {
|
||||
unsafe {
|
||||
llvm::LLVMConstInlineAsm(Type::func([], &Type::void(self.ccx)).to_ref(),
|
||||
llvm::LLVMConstInlineAsm(Type::func(&[], &Type::void(self.ccx)).to_ref(),
|
||||
c, noname(), False, False)
|
||||
}
|
||||
});
|
||||
self.call(asm, [], None);
|
||||
self.call(asm, &[], None);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -930,7 +930,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
llvm::LLVMGetNamedFunction(m, buf)
|
||||
});
|
||||
assert!((t as int != 0));
|
||||
let args: &[ValueRef] = [];
|
||||
let args: &[ValueRef] = &[];
|
||||
self.count_insn("trap");
|
||||
llvm::LLVMBuildCall(
|
||||
self.llbuilder, t, args.as_ptr(), args.len() as c_uint, noname());
|
||||
|
|
|
@ -721,9 +721,9 @@ pub fn trans_call_inner<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
// Closures are represented as (llfn, llclosure) pair:
|
||||
// load the requisite values out.
|
||||
let pair = d.to_llref();
|
||||
let llfn = GEPi(bcx, pair, [0u, abi::fn_field_code]);
|
||||
let llfn = GEPi(bcx, pair, &[0u, abi::fn_field_code]);
|
||||
let llfn = Load(bcx, llfn);
|
||||
let llenv = GEPi(bcx, pair, [0u, abi::fn_field_box]);
|
||||
let llenv = GEPi(bcx, pair, &[0u, abi::fn_field_box]);
|
||||
let llenv = Load(bcx, llenv);
|
||||
(llfn, Some(llenv), None)
|
||||
}
|
||||
|
|
|
@ -785,7 +785,7 @@ impl<'blk, 'tcx> CleanupHelperMethods<'blk, 'tcx> for FunctionContext<'blk, 'tcx
|
|||
// this represents but it's determined by the personality function and
|
||||
// this is what the EH proposal example uses.
|
||||
let llretty = Type::struct_(self.ccx,
|
||||
[Type::i8p(self.ccx), Type::i32(self.ccx)],
|
||||
&[Type::i8p(self.ccx), Type::i32(self.ccx)],
|
||||
false);
|
||||
|
||||
// The exception handling personality function.
|
||||
|
|
|
@ -207,7 +207,7 @@ pub fn store_environment<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
bv.to_string(ccx)).as_slice());
|
||||
}
|
||||
|
||||
let bound_data = GEPi(bcx, llbox, [0u, abi::box_field_body, i]);
|
||||
let bound_data = GEPi(bcx, llbox, &[0u, abi::box_field_body, i]);
|
||||
|
||||
match bv.action {
|
||||
ast::CaptureByValue => {
|
||||
|
@ -275,7 +275,7 @@ fn load_environment<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
// Populate the upvars from the environment
|
||||
let mut i = 0u;
|
||||
for freevar in freevars.iter() {
|
||||
let mut upvarptr = GEPi(bcx, llcdata, [0u, i]);
|
||||
let mut upvarptr = GEPi(bcx, llcdata, &[0u, i]);
|
||||
match store {
|
||||
ty::RegionTraitStore(..) => { upvarptr = Load(bcx, upvarptr); }
|
||||
ty::UniqTraitStore => {}
|
||||
|
@ -329,7 +329,7 @@ fn load_unboxed_closure_environment<'blk, 'tcx>(
|
|||
};
|
||||
|
||||
for (i, freevar) in freevars.iter().enumerate() {
|
||||
let mut upvar_ptr = GEPi(bcx, llenv, [0, i]);
|
||||
let mut upvar_ptr = GEPi(bcx, llenv, &[0, i]);
|
||||
if freevar_mode == ast::CaptureByRef {
|
||||
upvar_ptr = Load(bcx, upvar_ptr);
|
||||
}
|
||||
|
@ -347,9 +347,9 @@ fn load_unboxed_closure_environment<'blk, 'tcx>(
|
|||
}
|
||||
|
||||
fn fill_fn_pair(bcx: Block, pair: ValueRef, llfn: ValueRef, llenvptr: ValueRef) {
|
||||
Store(bcx, llfn, GEPi(bcx, pair, [0u, abi::fn_field_code]));
|
||||
Store(bcx, llfn, GEPi(bcx, pair, &[0u, abi::fn_field_code]));
|
||||
let llenvptr = PointerCast(bcx, llenvptr, Type::i8p(bcx.ccx()));
|
||||
Store(bcx, llenvptr, GEPi(bcx, pair, [0u, abi::fn_field_box]));
|
||||
Store(bcx, llenvptr, GEPi(bcx, pair, &[0u, abi::fn_field_box]));
|
||||
}
|
||||
|
||||
pub fn trans_expr_fn<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
||||
|
@ -407,7 +407,7 @@ pub fn trans_expr_fn<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
llfn,
|
||||
bcx.fcx.param_substs,
|
||||
id,
|
||||
[],
|
||||
&[],
|
||||
ty::ty_fn_ret(fty),
|
||||
ty::ty_fn_abi(fty),
|
||||
true,
|
||||
|
@ -504,7 +504,7 @@ pub fn trans_unboxed_closure<'blk, 'tcx>(
|
|||
llfn,
|
||||
bcx.fcx.param_substs,
|
||||
id,
|
||||
[],
|
||||
&[],
|
||||
ty::ty_fn_ret(function_type),
|
||||
ty::ty_fn_abi(function_type),
|
||||
true,
|
||||
|
|
|
@ -581,7 +581,7 @@ pub fn C_floating(s: &str, t: Type) -> ValueRef {
|
|||
}
|
||||
|
||||
pub fn C_nil(ccx: &CrateContext) -> ValueRef {
|
||||
C_struct(ccx, [], false)
|
||||
C_struct(ccx, &[], false)
|
||||
}
|
||||
|
||||
pub fn C_bool(ccx: &CrateContext, val: bool) -> ValueRef {
|
||||
|
@ -676,7 +676,7 @@ pub fn C_str_slice(cx: &CrateContext, s: InternedString) -> ValueRef {
|
|||
let len = s.get().len();
|
||||
let cs = llvm::LLVMConstPointerCast(C_cstr(cx, s, false),
|
||||
Type::i8p(cx).to_ref());
|
||||
C_named_struct(cx.tn().find_type("str_slice").unwrap(), [cs, C_uint(cx, len)])
|
||||
C_named_struct(cx.tn().find_type("str_slice").unwrap(), &[cs, C_uint(cx, len)])
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -694,7 +694,7 @@ pub fn C_binary_slice(cx: &CrateContext, data: &[u8]) -> ValueRef {
|
|||
llvm::SetLinkage(g, llvm::InternalLinkage);
|
||||
|
||||
let cs = llvm::LLVMConstPointerCast(g, Type::i8p(cx).to_ref());
|
||||
C_struct(cx, [cs, C_uint(cx, len)], false)
|
||||
C_struct(cx, &[cs, C_uint(cx, len)], false)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -204,7 +204,7 @@ pub fn const_expr(cx: &CrateContext, e: &ast::Expr) -> (ValueRef, ty::t) {
|
|||
def,
|
||||
llconst,
|
||||
true);
|
||||
llconst = C_struct(cx, [wrapper, C_null(Type::i8p(cx))], false)
|
||||
llconst = C_struct(cx, &[wrapper, C_null(Type::i8p(cx))], false)
|
||||
}
|
||||
ty::AdjustAddEnv(store) => {
|
||||
cx.sess()
|
||||
|
@ -264,7 +264,7 @@ pub fn const_expr(cx: &CrateContext, e: &ast::Expr) -> (ValueRef, ty::t) {
|
|||
let llptr = const_ptrcast(cx, llconst, llunitty);
|
||||
assert_eq!(abi::slice_elt_base, 0);
|
||||
assert_eq!(abi::slice_elt_len, 1);
|
||||
llconst = C_struct(cx, [
|
||||
llconst = C_struct(cx, &[
|
||||
llptr,
|
||||
C_uint(cx, len)
|
||||
], false);
|
||||
|
@ -444,8 +444,8 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr) -> ValueRef {
|
|||
ty::ty_vec(_, Some(u)) => (bv, C_uint(cx, u)),
|
||||
ty::ty_open(ty) => match ty::get(ty).sty {
|
||||
ty::ty_vec(_, None) | ty::ty_str => {
|
||||
let e1 = const_get_elt(cx, bv, [0]);
|
||||
(const_deref_ptr(cx, e1), const_get_elt(cx, bv, [1]))
|
||||
let e1 = const_get_elt(cx, bv, &[0]);
|
||||
(const_deref_ptr(cx, e1), const_get_elt(cx, bv, &[1]))
|
||||
},
|
||||
_ => cx.sess().span_bug(base.span,
|
||||
format!("index-expr base must be a vector \
|
||||
|
@ -484,7 +484,7 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr) -> ValueRef {
|
|||
cx.sess().span_err(e.span,
|
||||
"const index-expr is out of bounds");
|
||||
}
|
||||
const_get_elt(cx, arr, [iv as c_uint])
|
||||
const_get_elt(cx, arr, &[iv as c_uint])
|
||||
}
|
||||
ast::ExprCast(ref base, _) => {
|
||||
let ety = ty::expr_ty(cx.tcx(), e);
|
||||
|
@ -646,7 +646,7 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr) -> ValueRef {
|
|||
let vinfo = ty::enum_variant_with_id(cx.tcx(),
|
||||
enum_did,
|
||||
variant_did);
|
||||
adt::trans_const(cx, &*repr, vinfo.disr_val, [])
|
||||
adt::trans_const(cx, &*repr, vinfo.disr_val, &[])
|
||||
}
|
||||
Some(def::DefStruct(_)) => {
|
||||
let ety = ty::expr_ty(cx.tcx(), e);
|
||||
|
|
|
@ -434,7 +434,7 @@ impl LocalCrateContext {
|
|||
let ccx = local_ccx.dummy_ccx(shared);
|
||||
|
||||
let mut str_slice_ty = Type::named_struct(&ccx, "str_slice");
|
||||
str_slice_ty.set_struct_body([Type::i8p(&ccx), ccx.int_type()], false);
|
||||
str_slice_ty.set_struct_body(&[Type::i8p(&ccx), ccx.int_type()], false);
|
||||
ccx.tn().associate_type("str_slice", &str_slice_ty);
|
||||
|
||||
ccx.tn().associate_type("tydesc", &Type::tydesc(&ccx, str_slice_ty));
|
||||
|
@ -719,7 +719,7 @@ fn declare_intrinsic(ccx: &CrateContext, key: & &'static str) -> Option<ValueRef
|
|||
($name:expr fn() -> $ret:expr) => (
|
||||
if *key == $name {
|
||||
let f = base::decl_cdecl_fn(
|
||||
ccx, $name, Type::func([], &$ret),
|
||||
ccx, $name, Type::func(&[], &$ret),
|
||||
ty::mk_nil(ccx.tcx()));
|
||||
ccx.intrinsics().borrow_mut().insert($name, f.clone());
|
||||
return Some(f);
|
||||
|
@ -728,14 +728,14 @@ fn declare_intrinsic(ccx: &CrateContext, key: & &'static str) -> Option<ValueRef
|
|||
($name:expr fn($($arg:expr),*) -> $ret:expr) => (
|
||||
if *key == $name {
|
||||
let f = base::decl_cdecl_fn(ccx, $name,
|
||||
Type::func([$($arg),*], &$ret), ty::mk_nil(ccx.tcx()));
|
||||
Type::func(&[$($arg),*], &$ret), ty::mk_nil(ccx.tcx()));
|
||||
ccx.intrinsics().borrow_mut().insert($name, f.clone());
|
||||
return Some(f);
|
||||
}
|
||||
)
|
||||
)
|
||||
macro_rules! mk_struct (
|
||||
($($field_ty:expr),*) => (Type::struct_(ccx, [$($field_ty),*], false))
|
||||
($($field_ty:expr),*) => (Type::struct_(ccx, &[$($field_ty),*], false))
|
||||
)
|
||||
|
||||
let i8p = Type::i8p(ccx);
|
||||
|
@ -864,7 +864,7 @@ fn declare_intrinsic(ccx: &CrateContext, key: & &'static str) -> Option<ValueRef
|
|||
ifn!($name fn($($arg),*) -> $ret);
|
||||
} else if *key == $name {
|
||||
let f = base::decl_cdecl_fn(ccx, stringify!($cname),
|
||||
Type::func([$($arg),*], &$ret),
|
||||
Type::func(&[$($arg),*], &$ret),
|
||||
ty::mk_nil(ccx.tcx()));
|
||||
ccx.intrinsics().borrow_mut().insert($name, f.clone());
|
||||
return Some(f);
|
||||
|
|
|
@ -189,7 +189,7 @@ pub fn trans_if<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
let else_bcx_in = bcx.fcx.new_id_block("else-block", elexpr.id);
|
||||
let else_bcx_out = expr::trans_into(else_bcx_in, &*elexpr, dest);
|
||||
next_bcx = bcx.fcx.join_blocks(if_id,
|
||||
[then_bcx_out, else_bcx_out]);
|
||||
&[then_bcx_out, else_bcx_out]);
|
||||
CondBr(bcx, cond_val, then_bcx_in.llbb, else_bcx_in.llbb);
|
||||
}
|
||||
|
||||
|
@ -324,7 +324,7 @@ pub fn trans_for<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
|
|||
None,
|
||||
arg_cleanup_scope)
|
||||
},
|
||||
callee::ArgVals([lliterator]),
|
||||
callee::ArgVals(&[lliterator]),
|
||||
Some(expr::SaveIn(lloption)));
|
||||
bcx
|
||||
}));
|
||||
|
|
|
@ -985,7 +985,7 @@ pub fn create_match_binding_metadata(bcx: Block,
|
|||
},
|
||||
TrByMove => IndirectVariable {
|
||||
alloca: binding.llmatch,
|
||||
address_operations: aops
|
||||
address_operations: &aops
|
||||
},
|
||||
TrByRef => DirectVariable {
|
||||
alloca: binding.llmatch
|
||||
|
@ -1368,7 +1368,7 @@ pub fn create_function_debug_context(cx: &CrateContext,
|
|||
param_substs: ¶m_substs,
|
||||
error_reporting_span: Span) -> DIArray {
|
||||
if cx.sess().opts.debuginfo == LimitedDebugInfo {
|
||||
return create_DIArray(DIB(cx), []);
|
||||
return create_DIArray(DIB(cx), &[]);
|
||||
}
|
||||
|
||||
let mut signature = Vec::with_capacity(fn_decl.inputs.len() + 1);
|
||||
|
@ -1409,7 +1409,7 @@ pub fn create_function_debug_context(cx: &CrateContext,
|
|||
let has_self_type = self_type.is_some();
|
||||
|
||||
if !generics.is_type_parameterized() && !has_self_type {
|
||||
return create_DIArray(DIB(cx), []);
|
||||
return create_DIArray(DIB(cx), &[]);
|
||||
}
|
||||
|
||||
name_to_append_suffix_to.push('<');
|
||||
|
@ -2645,7 +2645,7 @@ fn create_struct_stub(cx: &CrateContext,
|
|||
// LLVMDIBuilderCreateStructType() wants an empty array. A null
|
||||
// pointer will lead to hard to trace and debug LLVM assertions
|
||||
// later on in llvm/lib/IR/Value.cpp.
|
||||
let empty_array = create_DIArray(DIB(cx), []);
|
||||
let empty_array = create_DIArray(DIB(cx), &[]);
|
||||
|
||||
llvm::LLVMDIBuilderCreateStructType(
|
||||
DIB(cx),
|
||||
|
@ -2688,7 +2688,7 @@ fn fixed_vec_metadata(cx: &CrateContext,
|
|||
len as i64)
|
||||
};
|
||||
|
||||
let subscripts = create_DIArray(DIB(cx), [subrange]);
|
||||
let subscripts = create_DIArray(DIB(cx), &[subrange]);
|
||||
let metadata = unsafe {
|
||||
llvm::LLVMDIBuilderCreateArrayType(
|
||||
DIB(cx),
|
||||
|
@ -2749,7 +2749,7 @@ fn vec_slice_metadata(cx: &CrateContext,
|
|||
slice_llvm_type,
|
||||
slice_type_name.as_slice(),
|
||||
unique_type_id,
|
||||
member_descriptions,
|
||||
&member_descriptions,
|
||||
UNKNOWN_SCOPE_METADATA,
|
||||
file_metadata,
|
||||
span);
|
||||
|
@ -2835,7 +2835,7 @@ fn trait_pointer_metadata(cx: &CrateContext,
|
|||
trait_llvm_type,
|
||||
trait_type_name.as_slice(),
|
||||
unique_type_id,
|
||||
[],
|
||||
&[],
|
||||
containing_scope,
|
||||
UNKNOWN_FILE_METADATA,
|
||||
codemap::DUMMY_SP)
|
||||
|
|
|
@ -166,11 +166,11 @@ pub fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
}
|
||||
|
||||
pub fn get_len(bcx: Block, fat_ptr: ValueRef) -> ValueRef {
|
||||
GEPi(bcx, fat_ptr, [0u, abi::slice_elt_len])
|
||||
GEPi(bcx, fat_ptr, &[0u, abi::slice_elt_len])
|
||||
}
|
||||
|
||||
pub fn get_dataptr(bcx: Block, fat_ptr: ValueRef) -> ValueRef {
|
||||
GEPi(bcx, fat_ptr, [0u, abi::slice_elt_base])
|
||||
GEPi(bcx, fat_ptr, &[0u, abi::slice_elt_base])
|
||||
}
|
||||
|
||||
fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
||||
|
@ -356,7 +356,7 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
val,
|
||||
type_of::type_of(bcx.ccx(), unsized_ty).ptr_to()),
|
||||
&ty::UnsizeLength(..) =>
|
||||
|bcx, val| GEPi(bcx, val, [0u, 0u]),
|
||||
|bcx, val| GEPi(bcx, val, &[0u, 0u]),
|
||||
&ty::UnsizeVtable(..) =>
|
||||
|_bcx, val| PointerCast(bcx, val, Type::i8p(bcx.ccx()))
|
||||
};
|
||||
|
@ -814,7 +814,7 @@ fn trans_index<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
let expect = ccx.get_intrinsic(&("llvm.expect.i1"));
|
||||
let expected = Call(bcx,
|
||||
expect,
|
||||
[bounds_check, C_bool(ccx, false)],
|
||||
&[bounds_check, C_bool(ccx, false)],
|
||||
None);
|
||||
bcx = with_cond(bcx, expected, |bcx| {
|
||||
controlflow::trans_fail_bounds_check(bcx,
|
||||
|
@ -822,7 +822,7 @@ fn trans_index<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
ix_val,
|
||||
len)
|
||||
});
|
||||
let elt = InBoundsGEP(bcx, base, [ix_val]);
|
||||
let elt = InBoundsGEP(bcx, base, &[ix_val]);
|
||||
let elt = PointerCast(bcx, elt, vt.llunit_ty.ptr_to());
|
||||
Datum::new(elt, vt.unit_ty, LvalueExpr)
|
||||
}
|
||||
|
@ -1758,8 +1758,8 @@ fn trans_lazy_binop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
}
|
||||
|
||||
Br(past_rhs, join.llbb);
|
||||
let phi = Phi(join, Type::i1(bcx.ccx()), [lhs, rhs],
|
||||
[past_lhs.llbb, past_rhs.llbb]);
|
||||
let phi = Phi(join, Type::i1(bcx.ccx()), &[lhs, rhs],
|
||||
&[past_lhs.llbb, past_rhs.llbb]);
|
||||
|
||||
return immediate_rvalue_bcx(join, phi, binop_ty).to_expr_datumblock();
|
||||
}
|
||||
|
|
|
@ -610,7 +610,7 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: &CrateContext,
|
|||
|
||||
let llfn = base::decl_internal_rust_fn(ccx, t, ps.as_slice());
|
||||
base::set_llvm_fn_attrs(ccx, attrs, llfn);
|
||||
base::trans_fn(ccx, decl, body, llfn, param_substs, id, []);
|
||||
base::trans_fn(ccx, decl, body, llfn, param_substs, id, &[]);
|
||||
llfn
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ pub fn trans_exchange_free_dyn<'blk, 'tcx>(cx: Block<'blk, 'tcx>, v: ValueRef,
|
|||
let ccx = cx.ccx();
|
||||
callee::trans_lang_call(cx,
|
||||
langcall(cx, None, "", ExchangeFreeFnLangItem),
|
||||
[PointerCast(cx, v, Type::i8p(ccx)), size, align],
|
||||
&[PointerCast(cx, v, Type::i8p(ccx)), size, align],
|
||||
Some(expr::Ignore)).bcx
|
||||
}
|
||||
|
||||
|
@ -124,7 +124,7 @@ pub fn drop_ty<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
None => debuginfo::clear_source_location(bcx.fcx)
|
||||
};
|
||||
|
||||
Call(bcx, glue, [ptr], None);
|
||||
Call(bcx, glue, &[ptr], None);
|
||||
}
|
||||
bcx
|
||||
}
|
||||
|
@ -195,7 +195,7 @@ fn trans_struct_drop_flag<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
|
|||
let struct_data = if ty::type_is_sized(bcx.tcx(), t) {
|
||||
v0
|
||||
} else {
|
||||
let llval = GEPi(bcx, v0, [0, abi::slice_elt_base]);
|
||||
let llval = GEPi(bcx, v0, &[0, abi::slice_elt_base]);
|
||||
Load(bcx, llval)
|
||||
};
|
||||
let drop_flag = unpack_datum!(bcx, adt::trans_drop_flag_ptr(bcx, &*repr, struct_data));
|
||||
|
@ -236,8 +236,8 @@ fn trans_struct_drop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
let (struct_data, info) = if ty::type_is_sized(bcx.tcx(), t) {
|
||||
(v0, None)
|
||||
} else {
|
||||
let data = GEPi(bcx, v0, [0, abi::slice_elt_base]);
|
||||
let info = GEPi(bcx, v0, [0, abi::slice_elt_len]);
|
||||
let data = GEPi(bcx, v0, &[0, abi::slice_elt_base]);
|
||||
let info = GEPi(bcx, v0, &[0, abi::slice_elt_len]);
|
||||
(Load(bcx, data), Some(Load(bcx, info)))
|
||||
};
|
||||
|
||||
|
@ -254,14 +254,14 @@ fn trans_struct_drop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
// The dtor expects a fat pointer, so make one, even if we have to fake it.
|
||||
let boxed_ty = ty::mk_open(bcx.tcx(), t);
|
||||
let scratch = datum::rvalue_scratch_datum(bcx, boxed_ty, "__fat_ptr_drop_self");
|
||||
Store(bcx, value, GEPi(bcx, scratch.val, [0, abi::slice_elt_base]));
|
||||
Store(bcx, value, GEPi(bcx, scratch.val, &[0, abi::slice_elt_base]));
|
||||
Store(bcx,
|
||||
// If we just had a thin pointer, make a fat pointer by sticking
|
||||
// null where we put the unsizing info. This works because t
|
||||
// is a sized type, so we will only unpack the fat pointer, never
|
||||
// use the fake info.
|
||||
info.unwrap_or(C_null(Type::i8p(bcx.ccx()))),
|
||||
GEPi(bcx, scratch.val, [0, abi::slice_elt_len]));
|
||||
GEPi(bcx, scratch.val, &[0, abi::slice_elt_len]));
|
||||
PointerCast(variant_cx, scratch.val, params[0])
|
||||
} else {
|
||||
PointerCast(variant_cx, value, params[0])
|
||||
|
@ -279,8 +279,8 @@ fn trans_struct_drop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
} else {
|
||||
let boxed_ty = ty::mk_open(bcx.tcx(), *ty);
|
||||
let scratch = datum::rvalue_scratch_datum(bcx, boxed_ty, "__fat_ptr_drop_field");
|
||||
Store(bcx, llfld_a, GEPi(bcx, scratch.val, [0, abi::slice_elt_base]));
|
||||
Store(bcx, info.unwrap(), GEPi(bcx, scratch.val, [0, abi::slice_elt_len]));
|
||||
Store(bcx, llfld_a, GEPi(bcx, scratch.val, &[0, abi::slice_elt_base]));
|
||||
Store(bcx, info.unwrap(), GEPi(bcx, scratch.val, &[0, abi::slice_elt_len]));
|
||||
scratch.val
|
||||
};
|
||||
variant_cx.fcx.schedule_drop_mem(cleanup::CustomScope(field_scope),
|
||||
|
@ -288,7 +288,7 @@ fn trans_struct_drop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
}
|
||||
|
||||
let dtor_ty = ty::mk_ctor_fn(variant_cx.tcx(), ast::DUMMY_NODE_ID,
|
||||
[get_drop_glue_type(bcx.ccx(), t)], ty::mk_nil(bcx.tcx()));
|
||||
&[get_drop_glue_type(bcx.ccx(), t)], ty::mk_nil(bcx.tcx()));
|
||||
let (_, variant_cx) = invoke(variant_cx, dtor_addr, args, dtor_ty, None, false);
|
||||
|
||||
variant_cx.fcx.pop_and_trans_custom_cleanup_scope(variant_cx, field_scope);
|
||||
|
@ -335,8 +335,8 @@ fn size_and_align_of_dst(bcx: Block, t :ty::t, info: ValueRef) -> (ValueRef, Val
|
|||
// info points to the vtable and the second entry in the vtable is the
|
||||
// dynamic size of the object.
|
||||
let info = PointerCast(bcx, info, Type::int(bcx.ccx()).ptr_to());
|
||||
let size_ptr = GEPi(bcx, info, [1u]);
|
||||
let align_ptr = GEPi(bcx, info, [2u]);
|
||||
let size_ptr = GEPi(bcx, info, &[1u]);
|
||||
let align_ptr = GEPi(bcx, info, &[2u]);
|
||||
(Load(bcx, size_ptr), Load(bcx, align_ptr))
|
||||
}
|
||||
ty::ty_vec(unit_ty, None) => {
|
||||
|
@ -366,26 +366,26 @@ fn make_drop_glue<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, v0: ValueRef, t: ty::t)
|
|||
tvec::make_drop_glue_unboxed(bcx, v0, unit_ty, true)
|
||||
}
|
||||
ty::ty_trait(..) => {
|
||||
let lluniquevalue = GEPi(bcx, v0, [0, abi::trt_field_box]);
|
||||
let lluniquevalue = GEPi(bcx, v0, &[0, abi::trt_field_box]);
|
||||
// Only drop the value when it is non-null
|
||||
let concrete_ptr = Load(bcx, lluniquevalue);
|
||||
with_cond(bcx, IsNotNull(bcx, concrete_ptr), |bcx| {
|
||||
let dtor_ptr = Load(bcx, GEPi(bcx, v0, [0, abi::trt_field_vtable]));
|
||||
let dtor_ptr = Load(bcx, GEPi(bcx, v0, &[0, abi::trt_field_vtable]));
|
||||
let dtor = Load(bcx, dtor_ptr);
|
||||
Call(bcx,
|
||||
dtor,
|
||||
[PointerCast(bcx, lluniquevalue, Type::i8p(bcx.ccx()))],
|
||||
&[PointerCast(bcx, lluniquevalue, Type::i8p(bcx.ccx()))],
|
||||
None);
|
||||
bcx
|
||||
})
|
||||
}
|
||||
ty::ty_struct(..) if !ty::type_is_sized(bcx.tcx(), content_ty) => {
|
||||
let llval = GEPi(bcx, v0, [0, abi::slice_elt_base]);
|
||||
let llval = GEPi(bcx, v0, &[0, abi::slice_elt_base]);
|
||||
let llbox = Load(bcx, llval);
|
||||
let not_null = IsNotNull(bcx, llbox);
|
||||
with_cond(bcx, not_null, |bcx| {
|
||||
let bcx = drop_ty(bcx, v0, content_ty, None);
|
||||
let info = GEPi(bcx, v0, [0, abi::slice_elt_len]);
|
||||
let info = GEPi(bcx, v0, &[0, abi::slice_elt_len]);
|
||||
let info = Load(bcx, info);
|
||||
let (llsize, llalign) = size_and_align_of_dst(bcx, content_ty, info);
|
||||
trans_exchange_free_dyn(bcx, llbox, llsize, llalign)
|
||||
|
@ -437,14 +437,14 @@ fn make_drop_glue<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, v0: ValueRef, t: ty::t)
|
|||
t,
|
||||
|bb, vv, tt| drop_ty(bb, vv, tt, None)),
|
||||
ty::ty_closure(ref f) if f.store == ty::UniqTraitStore => {
|
||||
let box_cell_v = GEPi(bcx, v0, [0u, abi::fn_field_box]);
|
||||
let box_cell_v = GEPi(bcx, v0, &[0u, abi::fn_field_box]);
|
||||
let env = Load(bcx, box_cell_v);
|
||||
let env_ptr_ty = Type::at_box(bcx.ccx(), Type::i8(bcx.ccx())).ptr_to();
|
||||
let env = PointerCast(bcx, env, env_ptr_ty);
|
||||
with_cond(bcx, IsNotNull(bcx, env), |bcx| {
|
||||
let dtor_ptr = GEPi(bcx, env, [0u, abi::box_field_drop_glue]);
|
||||
let dtor_ptr = GEPi(bcx, env, &[0u, abi::box_field_drop_glue]);
|
||||
let dtor = Load(bcx, dtor_ptr);
|
||||
Call(bcx, dtor, [PointerCast(bcx, box_cell_v, Type::i8p(bcx.ccx()))], None);
|
||||
Call(bcx, dtor, &[PointerCast(bcx, box_cell_v, Type::i8p(bcx.ccx()))], None);
|
||||
bcx
|
||||
})
|
||||
}
|
||||
|
@ -453,12 +453,12 @@ fn make_drop_glue<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, v0: ValueRef, t: ty::t)
|
|||
// above), because this happens for a trait field in an unsized
|
||||
// struct. If anything is null, it is the whole struct and we won't
|
||||
// get here.
|
||||
let lluniquevalue = GEPi(bcx, v0, [0, abi::trt_field_box]);
|
||||
let dtor_ptr = Load(bcx, GEPi(bcx, v0, [0, abi::trt_field_vtable]));
|
||||
let lluniquevalue = GEPi(bcx, v0, &[0, abi::trt_field_box]);
|
||||
let dtor_ptr = Load(bcx, GEPi(bcx, v0, &[0, abi::trt_field_vtable]));
|
||||
let dtor = Load(bcx, dtor_ptr);
|
||||
Call(bcx,
|
||||
dtor,
|
||||
[PointerCast(bcx, Load(bcx, lluniquevalue), Type::i8p(bcx.ccx()))],
|
||||
&[PointerCast(bcx, Load(bcx, lluniquevalue), Type::i8p(bcx.ccx()))],
|
||||
None);
|
||||
bcx
|
||||
}
|
||||
|
@ -578,10 +578,10 @@ pub fn emit_tydescs(ccx: &CrateContext) {
|
|||
ccx.stats().n_real_glues.set(ccx.stats().n_real_glues.get() + 1);
|
||||
|
||||
let tydesc = C_named_struct(ccx.tydesc_type(),
|
||||
[ti.size, // size
|
||||
ti.align, // align
|
||||
drop_glue, // drop_glue
|
||||
ti.name]); // name
|
||||
&[ti.size, // size
|
||||
ti.align, // align
|
||||
drop_glue, // drop_glue
|
||||
ti.name]); // name
|
||||
|
||||
unsafe {
|
||||
let gvar = ti.tydesc;
|
||||
|
|
|
@ -166,7 +166,7 @@ fn instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId)
|
|||
llfn,
|
||||
¶m_substs::empty(),
|
||||
mth.id,
|
||||
[]);
|
||||
&[]);
|
||||
// Use InternalLinkage so LLVM can optimize more
|
||||
// aggressively.
|
||||
SetLinkage(llfn, InternalLinkage);
|
||||
|
|
|
@ -207,7 +207,7 @@ pub fn trans_intrinsic_call<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, node: ast::N
|
|||
// These are the only intrinsic functions that diverge.
|
||||
if name.get() == "abort" {
|
||||
let llfn = ccx.get_intrinsic(&("llvm.trap"));
|
||||
Call(bcx, llfn, [], None);
|
||||
Call(bcx, llfn, &[], None);
|
||||
Unreachable(bcx);
|
||||
return Result::new(bcx, C_undef(Type::nil(ccx).ptr_to()));
|
||||
} else if name.get() == "unreachable" {
|
||||
|
@ -242,7 +242,7 @@ pub fn trans_intrinsic_call<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, node: ast::N
|
|||
}
|
||||
(_, "breakpoint") => {
|
||||
let llfn = ccx.get_intrinsic(&("llvm.debugtrap"));
|
||||
Call(bcx, llfn, [], None)
|
||||
Call(bcx, llfn, &[], None)
|
||||
}
|
||||
(_, "size_of") => {
|
||||
let tp_ty = *substs.types.get(FnSpace, 0);
|
||||
|
@ -291,7 +291,7 @@ pub fn trans_intrinsic_call<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, node: ast::N
|
|||
&ccx.link_meta().crate_hash);
|
||||
// NB: This needs to be kept in lockstep with the TypeId struct in
|
||||
// the intrinsic module
|
||||
C_named_struct(llret_ty, [C_u64(ccx, hash)])
|
||||
C_named_struct(llret_ty, &[C_u64(ccx, hash)])
|
||||
}
|
||||
(_, "init") => {
|
||||
let tp_ty = *substs.types.get(FnSpace, 0);
|
||||
|
@ -317,7 +317,7 @@ pub fn trans_intrinsic_call<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, node: ast::N
|
|||
(_, "offset") => {
|
||||
let ptr = llargs[0];
|
||||
let offset = llargs[1];
|
||||
InBoundsGEP(bcx, ptr, [offset])
|
||||
InBoundsGEP(bcx, ptr, &[offset])
|
||||
}
|
||||
|
||||
(_, "copy_nonoverlapping_memory") => {
|
||||
|
@ -578,8 +578,8 @@ fn copy_intrinsic(bcx: Block, allow_overlap: bool, volatile: bool,
|
|||
let src_ptr = PointerCast(bcx, src, Type::i8p(ccx));
|
||||
let llfn = ccx.get_intrinsic(&name);
|
||||
|
||||
Call(bcx, llfn, [dst_ptr, src_ptr, Mul(bcx, size, count), align,
|
||||
C_bool(ccx, volatile)], None)
|
||||
Call(bcx, llfn, &[dst_ptr, src_ptr, Mul(bcx, size, count), align,
|
||||
C_bool(ccx, volatile)], None)
|
||||
}
|
||||
|
||||
fn memset_intrinsic(bcx: Block, volatile: bool, tp_ty: ty::t,
|
||||
|
@ -597,14 +597,14 @@ fn memset_intrinsic(bcx: Block, volatile: bool, tp_ty: ty::t,
|
|||
let dst_ptr = PointerCast(bcx, dst, Type::i8p(ccx));
|
||||
let llfn = ccx.get_intrinsic(&name);
|
||||
|
||||
Call(bcx, llfn, [dst_ptr, val, Mul(bcx, size, count), align,
|
||||
C_bool(ccx, volatile)], None)
|
||||
Call(bcx, llfn, &[dst_ptr, val, Mul(bcx, size, count), align,
|
||||
C_bool(ccx, volatile)], None)
|
||||
}
|
||||
|
||||
fn count_zeros_intrinsic(bcx: Block, name: &'static str, val: ValueRef) -> ValueRef {
|
||||
let y = C_bool(bcx.ccx(), false);
|
||||
let llfn = bcx.ccx().get_intrinsic(&name);
|
||||
Call(bcx, llfn, [val, y], None)
|
||||
Call(bcx, llfn, &[val, y], None)
|
||||
}
|
||||
|
||||
fn with_overflow_intrinsic(bcx: Block, name: &'static str, t: ty::t,
|
||||
|
@ -612,7 +612,7 @@ fn with_overflow_intrinsic(bcx: Block, name: &'static str, t: ty::t,
|
|||
let llfn = bcx.ccx().get_intrinsic(&name);
|
||||
|
||||
// Convert `i1` to a `bool`, and write it to the out parameter
|
||||
let val = Call(bcx, llfn, [a, b], None);
|
||||
let val = Call(bcx, llfn, &[a, b], None);
|
||||
let result = ExtractValue(bcx, val, 0);
|
||||
let overflow = ZExt(bcx, ExtractValue(bcx, val, 1), Type::bool(bcx.ccx()));
|
||||
let ret = C_undef(type_of::type_of(bcx.ccx(), t));
|
||||
|
|
|
@ -89,7 +89,7 @@ pub fn trans_impl(ccx: &CrateContext,
|
|||
llfn,
|
||||
¶m_substs::empty(),
|
||||
method.id,
|
||||
[]);
|
||||
&[]);
|
||||
update_linkage(ccx,
|
||||
llfn,
|
||||
Some(method.id),
|
||||
|
@ -479,7 +479,7 @@ pub fn trans_trait_callee_from_llval<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
|
||||
// Load the data pointer from the object.
|
||||
debug!("(translating trait callee) loading second index from pair");
|
||||
let llboxptr = GEPi(bcx, llpair, [0u, abi::trt_field_box]);
|
||||
let llboxptr = GEPi(bcx, llpair, &[0u, abi::trt_field_box]);
|
||||
let llbox = Load(bcx, llboxptr);
|
||||
let llself = PointerCast(bcx, llbox, Type::i8p(ccx));
|
||||
|
||||
|
@ -501,9 +501,9 @@ pub fn trans_trait_callee_from_llval<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
let llvtable = Load(bcx,
|
||||
PointerCast(bcx,
|
||||
GEPi(bcx, llpair,
|
||||
[0u, abi::trt_field_vtable]),
|
||||
&[0u, abi::trt_field_vtable]),
|
||||
Type::vtable(ccx).ptr_to().ptr_to()));
|
||||
let mptr = Load(bcx, GEPi(bcx, llvtable, [0u, n_method + VTABLE_OFFSET]));
|
||||
let mptr = Load(bcx, GEPi(bcx, llvtable, &[0u, n_method + VTABLE_OFFSET]));
|
||||
let mptr = PointerCast(bcx, mptr, llcallee_ty.ptr_to());
|
||||
|
||||
return Callee {
|
||||
|
@ -764,13 +764,13 @@ pub fn trans_trait_cast<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
let llbox_ty = type_of(bcx.ccx(), datum_ty);
|
||||
|
||||
// Store the pointer into the first half of pair.
|
||||
let llboxdest = GEPi(bcx, lldest, [0u, abi::trt_field_box]);
|
||||
let llboxdest = GEPi(bcx, lldest, &[0u, abi::trt_field_box]);
|
||||
let llboxdest = PointerCast(bcx, llboxdest, llbox_ty.ptr_to());
|
||||
bcx = datum.store_to(bcx, llboxdest);
|
||||
|
||||
// Store the vtable into the second half of pair.
|
||||
let vtable = get_vtable(bcx, datum_ty, trait_ref);
|
||||
let llvtabledest = GEPi(bcx, lldest, [0u, abi::trt_field_vtable]);
|
||||
let llvtabledest = GEPi(bcx, lldest, &[0u, abi::trt_field_vtable]);
|
||||
let llvtabledest = PointerCast(bcx, llvtabledest, val_ty(vtable).ptr_to());
|
||||
Store(bcx, vtable, llvtabledest);
|
||||
|
||||
|
|
|
@ -179,10 +179,10 @@ pub fn monomorphic_fn(ccx: &CrateContext,
|
|||
if needs_body {
|
||||
if abi != abi::Rust {
|
||||
foreign::trans_rust_fn_with_foreign_abi(
|
||||
ccx, &**decl, &**body, [], d, &psubsts, fn_id.node,
|
||||
ccx, &**decl, &**body, &[], d, &psubsts, fn_id.node,
|
||||
Some(hash.as_slice()));
|
||||
} else {
|
||||
trans_fn(ccx, &**decl, &**body, d, &psubsts, fn_id.node, []);
|
||||
trans_fn(ccx, &**decl, &**body, d, &psubsts, fn_id.node, &[]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -226,7 +226,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
|
|||
d,
|
||||
&psubsts,
|
||||
mth.id,
|
||||
[]);
|
||||
&[]);
|
||||
}
|
||||
d
|
||||
}
|
||||
|
@ -242,7 +242,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
|
|||
let needs_body = setup_lldecl(d, mth.attrs.as_slice());
|
||||
if needs_body {
|
||||
trans_fn(ccx, mth.pe_fn_decl(), mth.pe_body(), d,
|
||||
&psubsts, mth.id, []);
|
||||
&psubsts, mth.id, &[]);
|
||||
}
|
||||
d
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ pub fn pointer_add_byte(bcx: Block, ptr: ValueRef, bytes: ValueRef) -> ValueRef
|
|||
let _icx = push_ctxt("tvec::pointer_add_byte");
|
||||
let old_ty = val_ty(ptr);
|
||||
let bptr = PointerCast(bcx, ptr, Type::i8p(bcx.ccx()));
|
||||
return PointerCast(bcx, InBoundsGEP(bcx, bptr, [bytes]), old_ty);
|
||||
return PointerCast(bcx, InBoundsGEP(bcx, bptr, &[bytes]), old_ty);
|
||||
}
|
||||
|
||||
pub fn make_drop_glue_unboxed<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
||||
|
@ -128,7 +128,7 @@ pub fn trans_fixed_vstore<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
SaveIn(lldest) => {
|
||||
// lldest will have type *[T x N], but we want the type *T,
|
||||
// so use GEP to convert:
|
||||
let lldest = GEPi(bcx, lldest, [0, 0]);
|
||||
let lldest = GEPi(bcx, lldest, &[0, 0]);
|
||||
write_content(bcx, &vt, expr, expr, SaveIn(lldest))
|
||||
}
|
||||
};
|
||||
|
@ -231,8 +231,8 @@ pub fn trans_lit_str<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
let llbytes = C_uint(bcx.ccx(), bytes);
|
||||
let llcstr = C_cstr(bcx.ccx(), str_lit, false);
|
||||
let llcstr = llvm::LLVMConstPointerCast(llcstr, Type::i8p(bcx.ccx()).to_ref());
|
||||
Store(bcx, llcstr, GEPi(bcx, lldest, [0u, abi::slice_elt_base]));
|
||||
Store(bcx, llbytes, GEPi(bcx, lldest, [0u, abi::slice_elt_len]));
|
||||
Store(bcx, llcstr, GEPi(bcx, lldest, &[0u, abi::slice_elt_base]));
|
||||
Store(bcx, llbytes, GEPi(bcx, lldest, &[0u, abi::slice_elt_len]));
|
||||
bcx
|
||||
}
|
||||
}
|
||||
|
@ -290,7 +290,7 @@ pub fn write_content<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
SaveIn(lldest) => {
|
||||
let temp_scope = fcx.push_custom_cleanup_scope();
|
||||
for (i, element) in elements.iter().enumerate() {
|
||||
let lleltptr = GEPi(bcx, lldest, [i]);
|
||||
let lleltptr = GEPi(bcx, lldest, &[i]);
|
||||
debug!("writing index {} with lleltptr={}",
|
||||
i, bcx.val_to_string(lleltptr));
|
||||
bcx = expr::trans_into(bcx, &**element,
|
||||
|
@ -397,8 +397,8 @@ pub fn get_fixed_base_and_len(bcx: Block,
|
|||
fn get_slice_base_and_len(bcx: Block,
|
||||
llval: ValueRef)
|
||||
-> (ValueRef, ValueRef) {
|
||||
let base = Load(bcx, GEPi(bcx, llval, [0u, abi::slice_elt_base]));
|
||||
let len = Load(bcx, GEPi(bcx, llval, [0u, abi::slice_elt_len]));
|
||||
let base = Load(bcx, GEPi(bcx, llval, &[0u, abi::slice_elt_base]));
|
||||
let len = Load(bcx, GEPi(bcx, llval, &[0u, abi::slice_elt_len]));
|
||||
(base, len)
|
||||
}
|
||||
|
||||
|
@ -427,7 +427,7 @@ pub fn get_base_and_len(bcx: Block,
|
|||
ty::ty_uniq(ty) | ty::ty_rptr(_, ty::mt{ty, ..}) => match ty::get(ty).sty {
|
||||
ty::ty_vec(_, None) | ty::ty_str => get_slice_base_and_len(bcx, llval),
|
||||
ty::ty_vec(_, Some(n)) => {
|
||||
let base = GEPi(bcx, Load(bcx, llval), [0u, 0u]);
|
||||
let base = GEPi(bcx, Load(bcx, llval), &[0u, 0u]);
|
||||
(base, C_uint(ccx, n))
|
||||
}
|
||||
_ => ccx.sess().bug("unexpected type in get_base_and_len"),
|
||||
|
@ -477,7 +477,7 @@ pub fn iter_vec_loop<'a, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
let lleltptr = if vt.llunit_alloc_size == 0 {
|
||||
data_ptr
|
||||
} else {
|
||||
InBoundsGEP(body_bcx, data_ptr, [i])
|
||||
InBoundsGEP(body_bcx, data_ptr, &[i])
|
||||
};
|
||||
let body_bcx = f(body_bcx, lleltptr, vt.unit_ty);
|
||||
|
||||
|
@ -521,7 +521,7 @@ pub fn iter_vec_raw<'a, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
let header_bcx = fcx.new_temp_block("iter_vec_loop_header");
|
||||
Br(bcx, header_bcx.llbb);
|
||||
let data_ptr =
|
||||
Phi(header_bcx, val_ty(data_ptr), [data_ptr], [bcx.llbb]);
|
||||
Phi(header_bcx, val_ty(data_ptr), &[data_ptr], &[bcx.llbb]);
|
||||
let not_yet_at_end =
|
||||
ICmp(header_bcx, llvm::IntULT, data_ptr, data_end_ptr);
|
||||
let body_bcx = fcx.new_temp_block("iter_vec_loop_body");
|
||||
|
@ -529,7 +529,7 @@ pub fn iter_vec_raw<'a, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
CondBr(header_bcx, not_yet_at_end, body_bcx.llbb, next_bcx.llbb);
|
||||
let body_bcx = f(body_bcx, data_ptr, vt.unit_ty);
|
||||
AddIncomingToPhi(data_ptr, InBoundsGEP(body_bcx, data_ptr,
|
||||
[C_int(bcx.ccx(), 1i)]),
|
||||
&[C_int(bcx.ccx(), 1i)]),
|
||||
body_bcx.llbb);
|
||||
Br(body_bcx, header_bcx.llbb);
|
||||
next_bcx
|
||||
|
|
|
@ -162,7 +162,7 @@ impl Type {
|
|||
}
|
||||
|
||||
pub fn empty_struct(ccx: &CrateContext) -> Type {
|
||||
Type::struct_(ccx, [], false)
|
||||
Type::struct_(ccx, &[], false)
|
||||
}
|
||||
|
||||
pub fn vtable(ccx: &CrateContext) -> Type {
|
||||
|
@ -182,7 +182,7 @@ impl Type {
|
|||
}
|
||||
|
||||
pub fn glue_fn(ccx: &CrateContext, t: Type) -> Type {
|
||||
Type::func([t], &Type::void(ccx))
|
||||
Type::func(&[t], &Type::void(ccx))
|
||||
}
|
||||
|
||||
pub fn tydesc(ccx: &CrateContext, str_slice_ty: Type) -> Type {
|
||||
|
@ -199,7 +199,7 @@ impl Type {
|
|||
int_ty, // align
|
||||
glue_fn_ty, // drop
|
||||
str_slice_ty]; // name
|
||||
tydesc.set_struct_body(elems, false);
|
||||
tydesc.set_struct_body(&elems, false);
|
||||
|
||||
tydesc
|
||||
}
|
||||
|
@ -214,7 +214,7 @@ impl Type {
|
|||
|
||||
pub fn vec(ccx: &CrateContext, ty: &Type) -> Type {
|
||||
Type::struct_(ccx,
|
||||
[Type::array(ty, 0), Type::int(ccx)],
|
||||
&[Type::array(ty, 0), Type::int(ccx)],
|
||||
false)
|
||||
}
|
||||
|
||||
|
@ -224,7 +224,7 @@ impl Type {
|
|||
|
||||
// The box pointed to by @T.
|
||||
pub fn at_box(ccx: &CrateContext, ty: Type) -> Type {
|
||||
Type::struct_(ccx, [
|
||||
Type::struct_(ccx, &[
|
||||
ccx.int_type(), Type::glue_fn(ccx, Type::i8p(ccx)).ptr_to(),
|
||||
Type::i8p(ccx), Type::i8p(ccx), ty
|
||||
], false)
|
||||
|
@ -235,7 +235,7 @@ impl Type {
|
|||
}
|
||||
|
||||
pub fn opaque_trait(ccx: &CrateContext) -> Type {
|
||||
Type::struct_(ccx, [Type::opaque_trait_data(ccx).ptr_to(), Type::vtable_ptr(ccx)], false)
|
||||
Type::struct_(ccx, &[Type::opaque_trait_data(ccx).ptr_to(), Type::vtable_ptr(ccx)], false)
|
||||
}
|
||||
|
||||
pub fn opaque_trait_data(ccx: &CrateContext) -> Type {
|
||||
|
|
|
@ -195,12 +195,12 @@ pub fn sizing_type_of(cx: &CrateContext, t: ty::t) -> Type {
|
|||
if ty::type_is_sized(cx.tcx(), ty) {
|
||||
Type::i8p(cx)
|
||||
} else {
|
||||
Type::struct_(cx, [Type::i8p(cx), Type::i8p(cx)], false)
|
||||
Type::struct_(cx, &[Type::i8p(cx), Type::i8p(cx)], false)
|
||||
}
|
||||
}
|
||||
|
||||
ty::ty_bare_fn(..) => Type::i8p(cx),
|
||||
ty::ty_closure(..) => Type::struct_(cx, [Type::i8p(cx), Type::i8p(cx)], false),
|
||||
ty::ty_closure(..) => Type::struct_(cx, &[Type::i8p(cx), Type::i8p(cx)], false),
|
||||
|
||||
ty::ty_vec(ty, Some(size)) => {
|
||||
let llty = sizing_type_of(cx, ty);
|
||||
|
@ -231,7 +231,7 @@ pub fn sizing_type_of(cx: &CrateContext, t: ty::t) -> Type {
|
|||
}
|
||||
|
||||
ty::ty_open(_) => {
|
||||
Type::struct_(cx, [Type::i8p(cx), Type::i8p(cx)], false)
|
||||
Type::struct_(cx, &[Type::i8p(cx), Type::i8p(cx)], false)
|
||||
}
|
||||
|
||||
ty::ty_infer(..) | ty::ty_param(..) | ty::ty_err(..) => {
|
||||
|
@ -337,7 +337,7 @@ pub fn type_of(cx: &CrateContext, t: ty::t) -> Type {
|
|||
ty::ty_trait(..) => Type::opaque_trait(cx),
|
||||
_ if !ty::type_is_sized(cx.tcx(), ty) => {
|
||||
let p_ty = type_of(cx, ty).ptr_to();
|
||||
Type::struct_(cx, [p_ty, type_of_unsize_info(cx, ty)], false)
|
||||
Type::struct_(cx, &[p_ty, type_of_unsize_info(cx, ty)], false)
|
||||
}
|
||||
_ => type_of(cx, ty).ptr_to(),
|
||||
}
|
||||
|
@ -364,7 +364,7 @@ pub fn type_of(cx: &CrateContext, t: ty::t) -> Type {
|
|||
}
|
||||
ty::ty_closure(_) => {
|
||||
let fn_ty = type_of_fn_from_ty(cx, t).ptr_to();
|
||||
Type::struct_(cx, [fn_ty, Type::i8p(cx)], false)
|
||||
Type::struct_(cx, &[fn_ty, Type::i8p(cx)], false)
|
||||
}
|
||||
ty::ty_tup(ref tys) if tys.is_empty() => Type::nil(cx),
|
||||
ty::ty_tup(..) => {
|
||||
|
@ -391,15 +391,15 @@ pub fn type_of(cx: &CrateContext, t: ty::t) -> Type {
|
|||
ty::ty_open(t) => match ty::get(t).sty {
|
||||
ty::ty_struct(..) => {
|
||||
let p_ty = type_of(cx, t).ptr_to();
|
||||
Type::struct_(cx, [p_ty, type_of_unsize_info(cx, t)], false)
|
||||
Type::struct_(cx, &[p_ty, type_of_unsize_info(cx, t)], false)
|
||||
}
|
||||
ty::ty_vec(ty, None) => {
|
||||
let p_ty = type_of(cx, ty).ptr_to();
|
||||
Type::struct_(cx, [p_ty, type_of_unsize_info(cx, t)], false)
|
||||
Type::struct_(cx, &[p_ty, type_of_unsize_info(cx, t)], false)
|
||||
}
|
||||
ty::ty_str => {
|
||||
let p_ty = Type::i8p(cx);
|
||||
Type::struct_(cx, [p_ty, type_of_unsize_info(cx, t)], false)
|
||||
Type::struct_(cx, &[p_ty, type_of_unsize_info(cx, t)], false)
|
||||
}
|
||||
ty::ty_trait(..) => Type::opaque_trait(cx),
|
||||
_ => cx.sess().bug(format!("ty_open with sized type: {}",
|
||||
|
@ -472,5 +472,5 @@ pub fn llvm_type_name(cx: &CrateContext,
|
|||
|
||||
pub fn type_of_dtor(ccx: &CrateContext, self_ty: ty::t) -> Type {
|
||||
let self_ty = type_of(ccx, self_ty).ptr_to();
|
||||
Type::func([self_ty], &Type::void(ccx))
|
||||
Type::func(&[self_ty], &Type::void(ccx))
|
||||
}
|
||||
|
|
|
@ -2656,7 +2656,7 @@ pub fn type_contents(cx: &ctxt, ty: t) -> TypeContents {
|
|||
bounds: ExistentialBounds)
|
||||
-> TypeContents {
|
||||
// These are the type contents of the (opaque) interior
|
||||
kind_bounds_to_contents(cx, bounds.builtin_bounds, [])
|
||||
kind_bounds_to_contents(cx, bounds.builtin_bounds, &[])
|
||||
}
|
||||
|
||||
fn kind_bounds_to_contents(cx: &ctxt,
|
||||
|
@ -4850,7 +4850,7 @@ pub fn required_region_bounds(tcx: &ctxt,
|
|||
|
||||
all_bounds.push_all(region_bounds);
|
||||
|
||||
push_region_bounds([],
|
||||
push_region_bounds(&[],
|
||||
builtin_bounds,
|
||||
&mut all_bounds);
|
||||
|
||||
|
|
|
@ -1442,7 +1442,7 @@ pub fn compute_opt_region_bound(tcx: &ty::ctxt,
|
|||
let derived_region_bounds =
|
||||
ty::required_region_bounds(
|
||||
tcx,
|
||||
[],
|
||||
&[],
|
||||
builtin_bounds,
|
||||
trait_bounds);
|
||||
|
||||
|
|
|
@ -1064,7 +1064,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
|
|||
|
||||
// First try to borrow to a slice
|
||||
let entry = self.search_for_some_kind_of_autorefd_method(
|
||||
|r, m| AutoPtr(r, m, None), autoderefs, [MutImmutable, MutMutable],
|
||||
|r, m| AutoPtr(r, m, None), autoderefs, &[MutImmutable, MutMutable],
|
||||
|m,r| ty::mk_slice(tcx, r,
|
||||
ty::mt {ty:ty, mutbl:m}));
|
||||
|
||||
|
@ -1075,7 +1075,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
|
|||
// Then try to borrow to a slice *and* borrow a pointer.
|
||||
self.search_for_some_kind_of_autorefd_method(
|
||||
|r, m| AutoPtr(r, ast::MutImmutable, Some( box AutoPtr(r, m, None))),
|
||||
autoderefs, [MutImmutable, MutMutable],
|
||||
autoderefs, &[MutImmutable, MutMutable],
|
||||
|m, r| {
|
||||
let slice_ty = ty::mk_slice(tcx, r,
|
||||
ty::mt {ty:ty, mutbl:m});
|
||||
|
@ -1096,7 +1096,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
|
|||
// First try to borrow to an unsized vec.
|
||||
let entry = self.search_for_some_kind_of_autorefd_method(
|
||||
|_r, _m| AutoUnsize(ty::UnsizeLength(len)),
|
||||
autoderefs, [MutImmutable, MutMutable],
|
||||
autoderefs, &[MutImmutable, MutMutable],
|
||||
|_m, _r| ty::mk_vec(tcx, ty, None));
|
||||
|
||||
if entry.is_some() {
|
||||
|
@ -1106,7 +1106,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
|
|||
// Then try to borrow to a slice.
|
||||
let entry = self.search_for_some_kind_of_autorefd_method(
|
||||
|r, m| AutoPtr(r, m, Some(box AutoUnsize(ty::UnsizeLength(len)))),
|
||||
autoderefs, [MutImmutable, MutMutable],
|
||||
autoderefs, &[MutImmutable, MutMutable],
|
||||
|m, r| ty::mk_slice(tcx, r, ty::mt {ty:ty, mutbl:m}));
|
||||
|
||||
if entry.is_some() {
|
||||
|
@ -1118,7 +1118,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
|
|||
|r, m| AutoPtr(r, m,
|
||||
Some(box AutoPtr(r, m,
|
||||
Some(box AutoUnsize(ty::UnsizeLength(len)))))),
|
||||
autoderefs, [MutImmutable, MutMutable],
|
||||
autoderefs, &[MutImmutable, MutMutable],
|
||||
|m, r| {
|
||||
let slice_ty = ty::mk_slice(tcx, r, ty::mt {ty:ty, mutbl:m});
|
||||
ty::mk_rptr(tcx, r, ty::mt {ty:slice_ty, mutbl:MutImmutable})
|
||||
|
@ -1130,7 +1130,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
|
|||
debug!("auto_slice_str");
|
||||
|
||||
let entry = self.search_for_some_kind_of_autorefd_method(
|
||||
|r, m| AutoPtr(r, m, None), autoderefs, [MutImmutable],
|
||||
|r, m| AutoPtr(r, m, None), autoderefs, &[MutImmutable],
|
||||
|_m, r| ty::mk_str_slice(tcx, r, MutImmutable));
|
||||
|
||||
if entry.is_some() {
|
||||
|
@ -1139,7 +1139,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
|
|||
|
||||
self.search_for_some_kind_of_autorefd_method(
|
||||
|r, m| AutoPtr(r, ast::MutImmutable, Some( box AutoPtr(r, m, None))),
|
||||
autoderefs, [MutImmutable],
|
||||
autoderefs, &[MutImmutable],
|
||||
|m, r| {
|
||||
let slice_ty = ty::mk_str_slice(tcx, r, m);
|
||||
ty::mk_rptr(tcx, r, ty::mt {ty:slice_ty, mutbl:m})
|
||||
|
@ -1158,7 +1158,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
|
|||
let tcx = self.tcx();
|
||||
self.search_for_some_kind_of_autorefd_method(
|
||||
|r, m| AutoPtr(r, m, None),
|
||||
autoderefs, [MutImmutable, MutMutable],
|
||||
autoderefs, &[MutImmutable, MutMutable],
|
||||
|m, r| {
|
||||
let principal = ty::TraitRef::new(trt_did,
|
||||
trt_substs.clone());
|
||||
|
@ -1220,7 +1220,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
|
|||
ty_unboxed_closure(..) | ty_tup(..) | ty_open(..) |
|
||||
ty_str | ty_vec(..) | ty_trait(..) | ty_closure(..) => {
|
||||
self.search_for_some_kind_of_autorefd_method(
|
||||
|r, m| AutoPtr(r, m, None), autoderefs, [MutImmutable, MutMutable],
|
||||
|r, m| AutoPtr(r, m, None), autoderefs, &[MutImmutable, MutMutable],
|
||||
|m,r| ty::mk_rptr(tcx, r, ty::mt {ty:self_ty, mutbl:m}))
|
||||
}
|
||||
|
||||
|
|
|
@ -412,9 +412,9 @@ impl<'a, 'tcx> Wf<'a, 'tcx> {
|
|||
// region bounds required from all of the trait types:
|
||||
let required_region_bounds =
|
||||
ty::required_region_bounds(self.tcx,
|
||||
[],
|
||||
&[],
|
||||
bounds.builtin_bounds,
|
||||
[]);
|
||||
&[]);
|
||||
for &r_d in required_region_bounds.iter() {
|
||||
// Each of these is an instance of the `'c <= 'b`
|
||||
// constraint above
|
||||
|
|
|
@ -152,9 +152,9 @@ impl<'a, 'tcx, 'v> visit::Visitor<'v> for CoherenceCheckVisitor<'a, 'tcx> {
|
|||
ItemImpl(_, ref opt_trait, _, _) => {
|
||||
match opt_trait.clone() {
|
||||
Some(opt_trait) => {
|
||||
self.cc.check_implementation(item, [opt_trait]);
|
||||
self.cc.check_implementation(item, &[opt_trait]);
|
||||
}
|
||||
None => self.cc.check_implementation(item, [])
|
||||
None => self.cc.check_implementation(item, &[])
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
|
|
|
@ -376,7 +376,7 @@ impl<'a, 'tcx> Env<'a, 'tcx> {
|
|||
|
||||
#[test]
|
||||
fn contravariant_region_ptr_ok() {
|
||||
test_env("contravariant_region_ptr", EMPTY_SOURCE_STR, errors([]), |env| {
|
||||
test_env("contravariant_region_ptr", EMPTY_SOURCE_STR, errors(&[]), |env| {
|
||||
env.create_simple_region_hierarchy();
|
||||
let t_rptr1 = env.t_rptr_scope(1);
|
||||
let t_rptr10 = env.t_rptr_scope(10);
|
||||
|
@ -390,7 +390,7 @@ fn contravariant_region_ptr_ok() {
|
|||
fn contravariant_region_ptr_err() {
|
||||
test_env("contravariant_region_ptr",
|
||||
EMPTY_SOURCE_STR,
|
||||
errors(["lifetime mismatch"]),
|
||||
errors(&["lifetime mismatch"]),
|
||||
|env| {
|
||||
env.create_simple_region_hierarchy();
|
||||
let t_rptr1 = env.t_rptr_scope(1);
|
||||
|
@ -405,114 +405,114 @@ fn contravariant_region_ptr_err() {
|
|||
|
||||
#[test]
|
||||
fn lub_bound_bound() {
|
||||
test_env("contravariant_region_ptr", EMPTY_SOURCE_STR, errors([]), |env| {
|
||||
test_env("contravariant_region_ptr", EMPTY_SOURCE_STR, errors(&[]), |env| {
|
||||
let t_rptr_bound1 = env.t_rptr_late_bound(22, 1);
|
||||
let t_rptr_bound2 = env.t_rptr_late_bound(22, 2);
|
||||
env.check_lub(env.t_fn(22, [t_rptr_bound1], env.t_int()),
|
||||
env.t_fn(22, [t_rptr_bound2], env.t_int()),
|
||||
env.t_fn(22, [t_rptr_bound1], env.t_int()));
|
||||
env.check_lub(env.t_fn(22, &[t_rptr_bound1], env.t_int()),
|
||||
env.t_fn(22, &[t_rptr_bound2], env.t_int()),
|
||||
env.t_fn(22, &[t_rptr_bound1], env.t_int()));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lub_bound_free() {
|
||||
test_env("contravariant_region_ptr", EMPTY_SOURCE_STR, errors([]), |env| {
|
||||
test_env("contravariant_region_ptr", EMPTY_SOURCE_STR, errors(&[]), |env| {
|
||||
let t_rptr_bound1 = env.t_rptr_late_bound(22, 1);
|
||||
let t_rptr_free1 = env.t_rptr_free(0, 1);
|
||||
env.check_lub(env.t_fn(22, [t_rptr_bound1], env.t_int()),
|
||||
env.t_fn(22, [t_rptr_free1], env.t_int()),
|
||||
env.t_fn(22, [t_rptr_free1], env.t_int()));
|
||||
env.check_lub(env.t_fn(22, &[t_rptr_bound1], env.t_int()),
|
||||
env.t_fn(22, &[t_rptr_free1], env.t_int()),
|
||||
env.t_fn(22, &[t_rptr_free1], env.t_int()));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lub_bound_static() {
|
||||
test_env("contravariant_region_ptr", EMPTY_SOURCE_STR, errors([]), |env| {
|
||||
test_env("contravariant_region_ptr", EMPTY_SOURCE_STR, errors(&[]), |env| {
|
||||
let t_rptr_bound1 = env.t_rptr_late_bound(22, 1);
|
||||
let t_rptr_static = env.t_rptr_static();
|
||||
env.check_lub(env.t_fn(22, [t_rptr_bound1], env.t_int()),
|
||||
env.t_fn(22, [t_rptr_static], env.t_int()),
|
||||
env.t_fn(22, [t_rptr_static], env.t_int()));
|
||||
env.check_lub(env.t_fn(22, &[t_rptr_bound1], env.t_int()),
|
||||
env.t_fn(22, &[t_rptr_static], env.t_int()),
|
||||
env.t_fn(22, &[t_rptr_static], env.t_int()));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lub_bound_bound_inverse_order() {
|
||||
test_env("contravariant_region_ptr", EMPTY_SOURCE_STR, errors([]), |env| {
|
||||
test_env("contravariant_region_ptr", EMPTY_SOURCE_STR, errors(&[]), |env| {
|
||||
let t_rptr_bound1 = env.t_rptr_late_bound(22, 1);
|
||||
let t_rptr_bound2 = env.t_rptr_late_bound(22, 2);
|
||||
env.check_lub(env.t_fn(22, [t_rptr_bound1, t_rptr_bound2], t_rptr_bound1),
|
||||
env.t_fn(22, [t_rptr_bound2, t_rptr_bound1], t_rptr_bound1),
|
||||
env.t_fn(22, [t_rptr_bound1, t_rptr_bound1], t_rptr_bound1));
|
||||
env.check_lub(env.t_fn(22, &[t_rptr_bound1, t_rptr_bound2], t_rptr_bound1),
|
||||
env.t_fn(22, &[t_rptr_bound2, t_rptr_bound1], t_rptr_bound1),
|
||||
env.t_fn(22, &[t_rptr_bound1, t_rptr_bound1], t_rptr_bound1));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lub_free_free() {
|
||||
test_env("contravariant_region_ptr", EMPTY_SOURCE_STR, errors([]), |env| {
|
||||
test_env("contravariant_region_ptr", EMPTY_SOURCE_STR, errors(&[]), |env| {
|
||||
let t_rptr_free1 = env.t_rptr_free(0, 1);
|
||||
let t_rptr_free2 = env.t_rptr_free(0, 2);
|
||||
let t_rptr_static = env.t_rptr_static();
|
||||
env.check_lub(env.t_fn(22, [t_rptr_free1], env.t_int()),
|
||||
env.t_fn(22, [t_rptr_free2], env.t_int()),
|
||||
env.t_fn(22, [t_rptr_static], env.t_int()));
|
||||
env.check_lub(env.t_fn(22, &[t_rptr_free1], env.t_int()),
|
||||
env.t_fn(22, &[t_rptr_free2], env.t_int()),
|
||||
env.t_fn(22, &[t_rptr_static], env.t_int()));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lub_returning_scope() {
|
||||
test_env("contravariant_region_ptr", EMPTY_SOURCE_STR,
|
||||
errors(["cannot infer an appropriate lifetime"]), |env| {
|
||||
errors(&["cannot infer an appropriate lifetime"]), |env| {
|
||||
let t_rptr_scope10 = env.t_rptr_scope(10);
|
||||
let t_rptr_scope11 = env.t_rptr_scope(11);
|
||||
|
||||
// this should generate an error when regions are resolved
|
||||
env.make_lub_ty(env.t_fn(22, [], t_rptr_scope10),
|
||||
env.t_fn(22, [], t_rptr_scope11));
|
||||
env.make_lub_ty(env.t_fn(22, &[], t_rptr_scope10),
|
||||
env.t_fn(22, &[], t_rptr_scope11));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn glb_free_free_with_common_scope() {
|
||||
test_env("contravariant_region_ptr", EMPTY_SOURCE_STR, errors([]), |env| {
|
||||
test_env("contravariant_region_ptr", EMPTY_SOURCE_STR, errors(&[]), |env| {
|
||||
let t_rptr_free1 = env.t_rptr_free(0, 1);
|
||||
let t_rptr_free2 = env.t_rptr_free(0, 2);
|
||||
let t_rptr_scope = env.t_rptr_scope(0);
|
||||
env.check_glb(env.t_fn(22, [t_rptr_free1], env.t_int()),
|
||||
env.t_fn(22, [t_rptr_free2], env.t_int()),
|
||||
env.t_fn(22, [t_rptr_scope], env.t_int()));
|
||||
env.check_glb(env.t_fn(22, &[t_rptr_free1], env.t_int()),
|
||||
env.t_fn(22, &[t_rptr_free2], env.t_int()),
|
||||
env.t_fn(22, &[t_rptr_scope], env.t_int()));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn glb_bound_bound() {
|
||||
test_env("contravariant_region_ptr", EMPTY_SOURCE_STR, errors([]), |env| {
|
||||
test_env("contravariant_region_ptr", EMPTY_SOURCE_STR, errors(&[]), |env| {
|
||||
let t_rptr_bound1 = env.t_rptr_late_bound(22, 1);
|
||||
let t_rptr_bound2 = env.t_rptr_late_bound(22, 2);
|
||||
env.check_glb(env.t_fn(22, [t_rptr_bound1], env.t_int()),
|
||||
env.t_fn(22, [t_rptr_bound2], env.t_int()),
|
||||
env.t_fn(22, [t_rptr_bound1], env.t_int()));
|
||||
env.check_glb(env.t_fn(22, &[t_rptr_bound1], env.t_int()),
|
||||
env.t_fn(22, &[t_rptr_bound2], env.t_int()),
|
||||
env.t_fn(22, &[t_rptr_bound1], env.t_int()));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn glb_bound_free() {
|
||||
test_env("contravariant_region_ptr", EMPTY_SOURCE_STR, errors([]), |env| {
|
||||
test_env("contravariant_region_ptr", EMPTY_SOURCE_STR, errors(&[]), |env| {
|
||||
let t_rptr_bound1 = env.t_rptr_late_bound(22, 1);
|
||||
let t_rptr_free1 = env.t_rptr_free(0, 1);
|
||||
env.check_glb(env.t_fn(22, [t_rptr_bound1], env.t_int()),
|
||||
env.t_fn(22, [t_rptr_free1], env.t_int()),
|
||||
env.t_fn(22, [t_rptr_bound1], env.t_int()));
|
||||
env.check_glb(env.t_fn(22, &[t_rptr_bound1], env.t_int()),
|
||||
env.t_fn(22, &[t_rptr_free1], env.t_int()),
|
||||
env.t_fn(22, &[t_rptr_bound1], env.t_int()));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn glb_bound_static() {
|
||||
test_env("contravariant_region_ptr", EMPTY_SOURCE_STR, errors([]), |env| {
|
||||
test_env("contravariant_region_ptr", EMPTY_SOURCE_STR, errors(&[]), |env| {
|
||||
let t_rptr_bound1 = env.t_rptr_late_bound(22, 1);
|
||||
let t_rptr_static = env.t_rptr_static();
|
||||
env.check_glb(env.t_fn(22, [t_rptr_bound1], env.t_int()),
|
||||
env.t_fn(22, [t_rptr_static], env.t_int()),
|
||||
env.t_fn(22, [t_rptr_bound1], env.t_int()));
|
||||
env.check_glb(env.t_fn(22, &[t_rptr_bound1], env.t_int()),
|
||||
env.t_fn(22, &[t_rptr_static], env.t_int()),
|
||||
env.t_fn(22, &[t_rptr_bound1], env.t_int()));
|
||||
})
|
||||
}
|
||||
|
|
|
@ -141,12 +141,12 @@ impl<'a> Archive<'a> {
|
|||
|
||||
/// Removes a file from this archive
|
||||
pub fn remove_file(&mut self, file: &str) {
|
||||
run_ar(self.handler, &self.maybe_ar_prog, "d", None, [&self.dst, &Path::new(file)]);
|
||||
run_ar(self.handler, &self.maybe_ar_prog, "d", None, &[&self.dst, &Path::new(file)]);
|
||||
}
|
||||
|
||||
/// Lists all files in an archive
|
||||
pub fn files(&self) -> Vec<String> {
|
||||
let output = run_ar(self.handler, &self.maybe_ar_prog, "t", None, [&self.dst]);
|
||||
let output = run_ar(self.handler, &self.maybe_ar_prog, "t", None, &[&self.dst]);
|
||||
let output = str::from_utf8(output.output.as_slice()).unwrap();
|
||||
// use lines_any because windows delimits output with `\r\n` instead of
|
||||
// just `\n`
|
||||
|
@ -288,7 +288,7 @@ impl<'a> ArchiveBuilder<'a> {
|
|||
// of filename collisions.
|
||||
let archive = os::make_absolute(archive);
|
||||
run_ar(self.archive.handler, &self.archive.maybe_ar_prog,
|
||||
"x", Some(loc.path()), [&archive]);
|
||||
"x", Some(loc.path()), &[&archive]);
|
||||
|
||||
// Next, we must rename all of the inputs to "guaranteed unique names".
|
||||
// We move each file into `self.work_dir` under its new unique name.
|
||||
|
|
|
@ -140,7 +140,7 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_rpaths_to_flags() {
|
||||
let flags = rpaths_to_flags([
|
||||
let flags = rpaths_to_flags(&[
|
||||
"path1".to_string(),
|
||||
"path2".to_string()
|
||||
]);
|
||||
|
@ -151,12 +151,12 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_minimize1() {
|
||||
let res = minimize_rpaths([
|
||||
let res = minimize_rpaths(&[
|
||||
"rpath1".to_string(),
|
||||
"rpath2".to_string(),
|
||||
"rpath1".to_string()
|
||||
]);
|
||||
assert!(res.as_slice() == [
|
||||
assert!(res.as_slice() == &[
|
||||
"rpath1".to_string(),
|
||||
"rpath2".to_string()
|
||||
]);
|
||||
|
@ -164,7 +164,7 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_minimize2() {
|
||||
let res = minimize_rpaths([
|
||||
let res = minimize_rpaths(&[
|
||||
"1a".to_string(),
|
||||
"2".to_string(),
|
||||
"2".to_string(),
|
||||
|
@ -176,7 +176,7 @@ mod test {
|
|||
"4a".to_string(),
|
||||
"3".to_string()
|
||||
]);
|
||||
assert!(res.as_slice() == [
|
||||
assert!(res.as_slice() == &[
|
||||
"1a".to_string(),
|
||||
"2".to_string(),
|
||||
"4a".to_string(),
|
||||
|
|
|
@ -139,7 +139,7 @@ impl FixedBuffer for FixedBuffer64 {
|
|||
self.buffer[mut self.buffer_idx..size],
|
||||
input[..buffer_remaining]);
|
||||
self.buffer_idx = 0;
|
||||
func(self.buffer);
|
||||
func(&self.buffer);
|
||||
i += buffer_remaining;
|
||||
} else {
|
||||
copy_memory(
|
||||
|
@ -657,7 +657,7 @@ mod bench {
|
|||
let mut sh = Sha256::new();
|
||||
let bytes = [1u8, ..10];
|
||||
b.iter(|| {
|
||||
sh.input(bytes);
|
||||
sh.input(&bytes);
|
||||
});
|
||||
b.bytes = bytes.len() as u64;
|
||||
}
|
||||
|
@ -667,7 +667,7 @@ mod bench {
|
|||
let mut sh = Sha256::new();
|
||||
let bytes = [1u8, ..1024];
|
||||
b.iter(|| {
|
||||
sh.input(bytes);
|
||||
sh.input(&bytes);
|
||||
});
|
||||
b.bytes = bytes.len() as u64;
|
||||
}
|
||||
|
@ -677,7 +677,7 @@ mod bench {
|
|||
let mut sh = Sha256::new();
|
||||
let bytes = [1u8, ..65536];
|
||||
b.iter(|| {
|
||||
sh.input(bytes);
|
||||
sh.input(&bytes);
|
||||
});
|
||||
b.bytes = bytes.len() as u64;
|
||||
}
|
||||
|
|
|
@ -432,7 +432,7 @@ unsafe fn with_c_str<T>(v: &[u8], checked: bool,
|
|||
f: |*const libc::c_char| -> T) -> T {
|
||||
let c_str = if v.len() < BUF_LEN {
|
||||
let mut buf: [u8, .. BUF_LEN] = mem::uninitialized();
|
||||
slice::bytes::copy_memory(buf, v);
|
||||
slice::bytes::copy_memory(&mut buf, v);
|
||||
buf[v.len()] = 0;
|
||||
|
||||
let buf = buf.as_mut_ptr();
|
||||
|
@ -554,7 +554,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_vec_to_c_str() {
|
||||
let b: &[u8] = [];
|
||||
let b: &[u8] = &[];
|
||||
let c_str = b.to_c_str();
|
||||
unsafe {
|
||||
assert_eq!(*c_str.as_ptr().offset(0), 0);
|
||||
|
@ -646,7 +646,7 @@ mod tests {
|
|||
let c_str = "hello".to_c_str();
|
||||
assert_eq!(c_str.as_bytes_no_nul(), b"hello");
|
||||
let c_str = "".to_c_str();
|
||||
let exp: &[u8] = [];
|
||||
let exp: &[u8] = &[];
|
||||
assert_eq!(c_str.as_bytes_no_nul(), exp);
|
||||
let c_str = b"foo\xFF".to_c_str();
|
||||
assert_eq!(c_str.as_bytes_no_nul(), b"foo\xFF");
|
||||
|
|
|
@ -74,7 +74,7 @@ pub fn abort(args: &fmt::Arguments) -> ! {
|
|||
|
||||
// Convert the arguments into a stack-allocated string
|
||||
let mut msg = [0u8, ..512];
|
||||
let mut w = BufWriter { buf: msg, pos: 0 };
|
||||
let mut w = BufWriter { buf: &mut msg, pos: 0 };
|
||||
let _ = write!(&mut w, "{}", args);
|
||||
let msg = str::from_utf8(w.buf[mut ..w.pos]).unwrap_or("aborted");
|
||||
let msg = if msg.is_empty() {"aborted"} else {msg};
|
||||
|
|
|
@ -361,8 +361,8 @@ fn escape_str(writer: &mut io::Writer, v: &str) -> Result<(), io::IoError> {
|
|||
|
||||
fn escape_char(writer: &mut io::Writer, v: char) -> Result<(), io::IoError> {
|
||||
let mut buf = [0, .. 4];
|
||||
v.encode_utf8(buf);
|
||||
escape_bytes(writer, buf)
|
||||
v.encode_utf8(&mut buf);
|
||||
escape_bytes(writer, &mut buf)
|
||||
}
|
||||
|
||||
fn spaces(wr: &mut io::Writer, mut n: uint) -> Result<(), io::IoError> {
|
||||
|
@ -370,7 +370,7 @@ fn spaces(wr: &mut io::Writer, mut n: uint) -> Result<(), io::IoError> {
|
|||
static BUF: [u8, ..LEN] = [b' ', ..LEN];
|
||||
|
||||
while n >= LEN {
|
||||
try!(wr.write(BUF));
|
||||
try!(wr.write(&BUF));
|
||||
n -= LEN;
|
||||
}
|
||||
|
||||
|
@ -2584,27 +2584,27 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_write_object() {
|
||||
assert_eq!(mk_object([]).to_string().into_string(), "{}".to_string());
|
||||
assert_eq!(mk_object([]).to_pretty_str().into_string(), "{}".to_string());
|
||||
assert_eq!(mk_object(&[]).to_string().into_string(), "{}".to_string());
|
||||
assert_eq!(mk_object(&[]).to_pretty_str().into_string(), "{}".to_string());
|
||||
|
||||
assert_eq!(
|
||||
mk_object([
|
||||
mk_object(&[
|
||||
("a".to_string(), Boolean(true))
|
||||
]).to_string().into_string(),
|
||||
"{\"a\":true}".to_string()
|
||||
);
|
||||
assert_eq!(
|
||||
mk_object([("a".to_string(), Boolean(true))]).to_pretty_str(),
|
||||
mk_object(&[("a".to_string(), Boolean(true))]).to_pretty_str(),
|
||||
"\
|
||||
{\n \
|
||||
\"a\": true\n\
|
||||
}".to_string()
|
||||
);
|
||||
|
||||
let complex_obj = mk_object([
|
||||
let complex_obj = mk_object(&[
|
||||
("b".to_string(), List(vec![
|
||||
mk_object([("c".to_string(), String("\x0c\r".to_string()))]),
|
||||
mk_object([("d".to_string(), String("".to_string()))])
|
||||
mk_object(&[("c".to_string(), String("\x0c\r".to_string()))]),
|
||||
mk_object(&[("d".to_string(), String("".to_string()))])
|
||||
]))
|
||||
]);
|
||||
|
||||
|
@ -2632,11 +2632,11 @@ mod tests {
|
|||
}".to_string()
|
||||
);
|
||||
|
||||
let a = mk_object([
|
||||
let a = mk_object(&[
|
||||
("a".to_string(), Boolean(true)),
|
||||
("b".to_string(), List(vec![
|
||||
mk_object([("c".to_string(), String("\x0c\r".to_string()))]),
|
||||
mk_object([("d".to_string(), String("".to_string()))])
|
||||
mk_object(&[("c".to_string(), String("\x0c\r".to_string()))]),
|
||||
mk_object(&[("d".to_string(), String("".to_string()))])
|
||||
]))
|
||||
]);
|
||||
|
||||
|
@ -2941,22 +2941,22 @@ mod tests {
|
|||
assert_eq!(from_str("{\"a\":1 1"), Err(SyntaxError(InvalidSyntax, 1, 8)));
|
||||
assert_eq!(from_str("{\"a\":1,"), Err(SyntaxError(EOFWhileParsingObject, 1, 8)));
|
||||
|
||||
assert_eq!(from_str("{}").unwrap(), mk_object([]));
|
||||
assert_eq!(from_str("{}").unwrap(), mk_object(&[]));
|
||||
assert_eq!(from_str("{\"a\": 3}").unwrap(),
|
||||
mk_object([("a".to_string(), U64(3))]));
|
||||
mk_object(&[("a".to_string(), U64(3))]));
|
||||
|
||||
assert_eq!(from_str(
|
||||
"{ \"a\": null, \"b\" : true }").unwrap(),
|
||||
mk_object([
|
||||
mk_object(&[
|
||||
("a".to_string(), Null),
|
||||
("b".to_string(), Boolean(true))]));
|
||||
assert_eq!(from_str("\n{ \"a\": null, \"b\" : true }\n").unwrap(),
|
||||
mk_object([
|
||||
mk_object(&[
|
||||
("a".to_string(), Null),
|
||||
("b".to_string(), Boolean(true))]));
|
||||
assert_eq!(from_str(
|
||||
"{\"a\" : 1.0 ,\"b\": [ true ]}").unwrap(),
|
||||
mk_object([
|
||||
mk_object(&[
|
||||
("a".to_string(), F64(1.0)),
|
||||
("b".to_string(), List(vec![Boolean(true)]))
|
||||
]));
|
||||
|
@ -2969,13 +2969,13 @@ mod tests {
|
|||
{ \"c\": {\"d\": null} } \
|
||||
]\
|
||||
}").unwrap(),
|
||||
mk_object([
|
||||
mk_object(&[
|
||||
("a".to_string(), F64(1.0)),
|
||||
("b".to_string(), List(vec![
|
||||
Boolean(true),
|
||||
String("foo\nbar".to_string()),
|
||||
mk_object([
|
||||
("c".to_string(), mk_object([("d".to_string(), Null)]))
|
||||
mk_object(&[
|
||||
("c".to_string(), mk_object(&[("d".to_string(), Null)]))
|
||||
])
|
||||
]))
|
||||
]));
|
||||
|
@ -3639,20 +3639,20 @@ mod tests {
|
|||
stack.bump_index();
|
||||
|
||||
assert!(stack.len() == 1);
|
||||
assert!(stack.is_equal_to([Index(1)]));
|
||||
assert!(stack.starts_with([Index(1)]));
|
||||
assert!(stack.ends_with([Index(1)]));
|
||||
assert!(stack.is_equal_to(&[Index(1)]));
|
||||
assert!(stack.starts_with(&[Index(1)]));
|
||||
assert!(stack.ends_with(&[Index(1)]));
|
||||
assert!(stack.last_is_index());
|
||||
assert!(stack.get(0) == Index(1));
|
||||
|
||||
stack.push_key("foo".to_string());
|
||||
|
||||
assert!(stack.len() == 2);
|
||||
assert!(stack.is_equal_to([Index(1), Key("foo")]));
|
||||
assert!(stack.starts_with([Index(1), Key("foo")]));
|
||||
assert!(stack.starts_with([Index(1)]));
|
||||
assert!(stack.ends_with([Index(1), Key("foo")]));
|
||||
assert!(stack.ends_with([Key("foo")]));
|
||||
assert!(stack.is_equal_to(&[Index(1), Key("foo")]));
|
||||
assert!(stack.starts_with(&[Index(1), Key("foo")]));
|
||||
assert!(stack.starts_with(&[Index(1)]));
|
||||
assert!(stack.ends_with(&[Index(1), Key("foo")]));
|
||||
assert!(stack.ends_with(&[Key("foo")]));
|
||||
assert!(!stack.last_is_index());
|
||||
assert!(stack.get(0) == Index(1));
|
||||
assert!(stack.get(1) == Key("foo"));
|
||||
|
@ -3660,13 +3660,13 @@ mod tests {
|
|||
stack.push_key("bar".to_string());
|
||||
|
||||
assert!(stack.len() == 3);
|
||||
assert!(stack.is_equal_to([Index(1), Key("foo"), Key("bar")]));
|
||||
assert!(stack.starts_with([Index(1)]));
|
||||
assert!(stack.starts_with([Index(1), Key("foo")]));
|
||||
assert!(stack.starts_with([Index(1), Key("foo"), Key("bar")]));
|
||||
assert!(stack.ends_with([Key("bar")]));
|
||||
assert!(stack.ends_with([Key("foo"), Key("bar")]));
|
||||
assert!(stack.ends_with([Index(1), Key("foo"), Key("bar")]));
|
||||
assert!(stack.is_equal_to(&[Index(1), Key("foo"), Key("bar")]));
|
||||
assert!(stack.starts_with(&[Index(1)]));
|
||||
assert!(stack.starts_with(&[Index(1), Key("foo")]));
|
||||
assert!(stack.starts_with(&[Index(1), Key("foo"), Key("bar")]));
|
||||
assert!(stack.ends_with(&[Key("bar")]));
|
||||
assert!(stack.ends_with(&[Key("foo"), Key("bar")]));
|
||||
assert!(stack.ends_with(&[Index(1), Key("foo"), Key("bar")]));
|
||||
assert!(!stack.last_is_index());
|
||||
assert!(stack.get(0) == Index(1));
|
||||
assert!(stack.get(1) == Key("foo"));
|
||||
|
@ -3675,11 +3675,11 @@ mod tests {
|
|||
stack.pop();
|
||||
|
||||
assert!(stack.len() == 2);
|
||||
assert!(stack.is_equal_to([Index(1), Key("foo")]));
|
||||
assert!(stack.starts_with([Index(1), Key("foo")]));
|
||||
assert!(stack.starts_with([Index(1)]));
|
||||
assert!(stack.ends_with([Index(1), Key("foo")]));
|
||||
assert!(stack.ends_with([Key("foo")]));
|
||||
assert!(stack.is_equal_to(&[Index(1), Key("foo")]));
|
||||
assert!(stack.starts_with(&[Index(1), Key("foo")]));
|
||||
assert!(stack.starts_with(&[Index(1)]));
|
||||
assert!(stack.ends_with(&[Index(1), Key("foo")]));
|
||||
assert!(stack.ends_with(&[Key("foo")]));
|
||||
assert!(!stack.last_is_index());
|
||||
assert!(stack.get(0) == Index(1));
|
||||
assert!(stack.get(1) == Key("foo"));
|
||||
|
|
|
@ -38,7 +38,7 @@ use vec::Vec;
|
|||
/// let mut reader = BufferedReader::new(file);
|
||||
///
|
||||
/// let mut buf = [0, ..100];
|
||||
/// match reader.read(buf) {
|
||||
/// match reader.read(&mut buf) {
|
||||
/// Ok(nread) => println!("Read {} bytes", nread),
|
||||
/// Err(e) => println!("error reading: {}", e)
|
||||
/// }
|
||||
|
@ -300,7 +300,7 @@ impl<W: Reader> Reader for InternalBufferedWriter<W> {
|
|||
/// stream.flush();
|
||||
///
|
||||
/// let mut buf = [0, ..100];
|
||||
/// match stream.read(buf) {
|
||||
/// match stream.read(&mut buf) {
|
||||
/// Ok(nread) => println!("Read {} bytes", nread),
|
||||
/// Err(e) => println!("error reading: {}", e)
|
||||
/// }
|
||||
|
@ -414,35 +414,35 @@ mod test {
|
|||
let mut reader = BufferedReader::with_capacity(2, inner);
|
||||
|
||||
let mut buf = [0, 0, 0];
|
||||
let nread = reader.read(buf);
|
||||
let nread = reader.read(&mut buf);
|
||||
assert_eq!(Ok(3), nread);
|
||||
let b: &[_] = &[5, 6, 7];
|
||||
assert_eq!(buf.as_slice(), b);
|
||||
|
||||
let mut buf = [0, 0];
|
||||
let nread = reader.read(buf);
|
||||
let nread = reader.read(&mut buf);
|
||||
assert_eq!(Ok(2), nread);
|
||||
let b: &[_] = &[0, 1];
|
||||
assert_eq!(buf.as_slice(), b);
|
||||
|
||||
let mut buf = [0];
|
||||
let nread = reader.read(buf);
|
||||
let nread = reader.read(&mut buf);
|
||||
assert_eq!(Ok(1), nread);
|
||||
let b: &[_] = &[2];
|
||||
assert_eq!(buf.as_slice(), b);
|
||||
|
||||
let mut buf = [0, 0, 0];
|
||||
let nread = reader.read(buf);
|
||||
let nread = reader.read(&mut buf);
|
||||
assert_eq!(Ok(1), nread);
|
||||
let b: &[_] = &[3, 0, 0];
|
||||
assert_eq!(buf.as_slice(), b);
|
||||
|
||||
let nread = reader.read(buf);
|
||||
let nread = reader.read(&mut buf);
|
||||
assert_eq!(Ok(1), nread);
|
||||
let b: &[_] = &[4, 0, 0];
|
||||
assert_eq!(buf.as_slice(), b);
|
||||
|
||||
assert!(reader.read(buf).is_err());
|
||||
assert!(reader.read(&mut buf).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -450,36 +450,36 @@ mod test {
|
|||
let inner = MemWriter::new();
|
||||
let mut writer = BufferedWriter::with_capacity(2, inner);
|
||||
|
||||
writer.write([0, 1]).unwrap();
|
||||
writer.write(&[0, 1]).unwrap();
|
||||
let b: &[_] = &[];
|
||||
assert_eq!(writer.get_ref().get_ref(), b);
|
||||
|
||||
writer.write([2]).unwrap();
|
||||
writer.write(&[2]).unwrap();
|
||||
let b: &[_] = &[0, 1];
|
||||
assert_eq!(writer.get_ref().get_ref(), b);
|
||||
|
||||
writer.write([3]).unwrap();
|
||||
writer.write(&[3]).unwrap();
|
||||
assert_eq!(writer.get_ref().get_ref(), b);
|
||||
|
||||
writer.flush().unwrap();
|
||||
let a: &[_] = &[0, 1, 2, 3];
|
||||
assert_eq!(a, writer.get_ref().get_ref());
|
||||
|
||||
writer.write([4]).unwrap();
|
||||
writer.write([5]).unwrap();
|
||||
writer.write(&[4]).unwrap();
|
||||
writer.write(&[5]).unwrap();
|
||||
assert_eq!(a, writer.get_ref().get_ref());
|
||||
|
||||
writer.write([6]).unwrap();
|
||||
writer.write(&[6]).unwrap();
|
||||
let a: &[_] = &[0, 1, 2, 3, 4, 5];
|
||||
assert_eq!(a,
|
||||
writer.get_ref().get_ref());
|
||||
|
||||
writer.write([7, 8]).unwrap();
|
||||
writer.write(&[7, 8]).unwrap();
|
||||
let a: &[_] = &[0, 1, 2, 3, 4, 5, 6];
|
||||
assert_eq!(a,
|
||||
writer.get_ref().get_ref());
|
||||
|
||||
writer.write([9, 10, 11]).unwrap();
|
||||
writer.write(&[9, 10, 11]).unwrap();
|
||||
let a: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
|
||||
assert_eq!(a,
|
||||
writer.get_ref().get_ref());
|
||||
|
@ -492,7 +492,7 @@ mod test {
|
|||
#[test]
|
||||
fn test_buffered_writer_inner_flushes() {
|
||||
let mut w = BufferedWriter::with_capacity(3, MemWriter::new());
|
||||
w.write([0, 1]).unwrap();
|
||||
w.write(&[0, 1]).unwrap();
|
||||
let a: &[_] = &[];
|
||||
assert_eq!(a, w.get_ref().get_ref());
|
||||
let w = w.unwrap();
|
||||
|
@ -518,8 +518,8 @@ mod test {
|
|||
|
||||
let mut stream = BufferedStream::new(S);
|
||||
let mut buf = [];
|
||||
assert!(stream.read(buf).is_err());
|
||||
stream.write(buf).unwrap();
|
||||
assert!(stream.read(&mut buf).is_err());
|
||||
stream.write(&buf).unwrap();
|
||||
stream.flush().unwrap();
|
||||
}
|
||||
|
||||
|
@ -537,21 +537,21 @@ mod test {
|
|||
#[test]
|
||||
fn test_line_buffer() {
|
||||
let mut writer = LineBufferedWriter::new(MemWriter::new());
|
||||
writer.write([0]).unwrap();
|
||||
writer.write(&[0]).unwrap();
|
||||
let b: &[_] = &[];
|
||||
assert_eq!(writer.get_ref().get_ref(), b);
|
||||
writer.write([1]).unwrap();
|
||||
writer.write(&[1]).unwrap();
|
||||
assert_eq!(writer.get_ref().get_ref(), b);
|
||||
writer.flush().unwrap();
|
||||
let b: &[_] = &[0, 1];
|
||||
assert_eq!(writer.get_ref().get_ref(), b);
|
||||
writer.write([0, b'\n', 1, b'\n', 2]).unwrap();
|
||||
writer.write(&[0, b'\n', 1, b'\n', 2]).unwrap();
|
||||
let b: &[_] = &[0, 1, 0, b'\n', 1, b'\n'];
|
||||
assert_eq!(writer.get_ref().get_ref(), b);
|
||||
writer.flush().unwrap();
|
||||
let b: &[_] = &[0, 1, 0, b'\n', 1, b'\n', 2];
|
||||
assert_eq!(writer.get_ref().get_ref(), b);
|
||||
writer.write([3, b'\n']).unwrap();
|
||||
writer.write(&[3, b'\n']).unwrap();
|
||||
let b: &[_] = &[0, 1, 0, b'\n', 1, b'\n', 2, 3, b'\n'];
|
||||
assert_eq!(writer.get_ref().get_ref(), b);
|
||||
}
|
||||
|
@ -582,26 +582,26 @@ mod test {
|
|||
let inner = ShortReader{lengths: vec![0, 1, 2, 0, 1, 0]};
|
||||
let mut reader = BufferedReader::new(inner);
|
||||
let mut buf = [0, 0];
|
||||
assert_eq!(reader.read(buf), Ok(0));
|
||||
assert_eq!(reader.read(buf), Ok(1));
|
||||
assert_eq!(reader.read(buf), Ok(2));
|
||||
assert_eq!(reader.read(buf), Ok(0));
|
||||
assert_eq!(reader.read(buf), Ok(1));
|
||||
assert_eq!(reader.read(buf), Ok(0));
|
||||
assert!(reader.read(buf).is_err());
|
||||
assert_eq!(reader.read(&mut buf), Ok(0));
|
||||
assert_eq!(reader.read(&mut buf), Ok(1));
|
||||
assert_eq!(reader.read(&mut buf), Ok(2));
|
||||
assert_eq!(reader.read(&mut buf), Ok(0));
|
||||
assert_eq!(reader.read(&mut buf), Ok(1));
|
||||
assert_eq!(reader.read(&mut buf), Ok(0));
|
||||
assert!(reader.read(&mut buf).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn read_char_buffered() {
|
||||
let buf = [195u8, 159u8];
|
||||
let mut reader = BufferedReader::with_capacity(1, BufReader::new(buf));
|
||||
let mut reader = BufferedReader::with_capacity(1, BufReader::new(&buf));
|
||||
assert_eq!(reader.read_char(), Ok('ß'));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_chars() {
|
||||
let buf = [195u8, 159u8, b'a'];
|
||||
let mut reader = BufferedReader::with_capacity(1, BufReader::new(buf));
|
||||
let mut reader = BufferedReader::with_capacity(1, BufReader::new(&buf));
|
||||
let mut it = reader.chars();
|
||||
assert_eq!(it.next(), Some(Ok('ß')));
|
||||
assert_eq!(it.next(), Some(Ok('a')));
|
||||
|
|
|
@ -30,7 +30,7 @@ use vec::Vec;
|
|||
/// let mut reader = ChanReader::new(rx);
|
||||
///
|
||||
/// let mut buf = [0u8, ..100];
|
||||
/// match reader.read(buf) {
|
||||
/// match reader.read(&mut buf) {
|
||||
/// Ok(nread) => println!("Read {} bytes", nread),
|
||||
/// Err(e) => println!("read error: {}", e),
|
||||
/// }
|
||||
|
@ -172,17 +172,17 @@ mod test {
|
|||
let mut reader = ChanReader::new(rx);
|
||||
let mut buf = [0u8, ..3];
|
||||
|
||||
assert_eq!(Ok(0), reader.read([]));
|
||||
assert_eq!(Ok(0), reader.read(&mut []));
|
||||
|
||||
assert_eq!(Ok(3), reader.read(buf));
|
||||
assert_eq!(Ok(3), reader.read(&mut buf));
|
||||
let a: &[u8] = &[1,2,3];
|
||||
assert_eq!(a, buf.as_slice());
|
||||
|
||||
assert_eq!(Ok(3), reader.read(buf));
|
||||
assert_eq!(Ok(3), reader.read(&mut buf));
|
||||
let a: &[u8] = &[4,5,6];
|
||||
assert_eq!(a, buf.as_slice());
|
||||
|
||||
assert_eq!(Ok(2), reader.read(buf));
|
||||
assert_eq!(Ok(2), reader.read(&mut buf));
|
||||
let a: &[u8] = &[7,8,6];
|
||||
assert_eq!(a, buf.as_slice());
|
||||
|
||||
|
|
|
@ -82,9 +82,9 @@ pub fn u64_to_le_bytes<T>(n: u64, size: uint, f: |v: &[u8]| -> T) -> T {
|
|||
assert!(size <= 8u);
|
||||
match size {
|
||||
1u => f(&[n as u8]),
|
||||
2u => f(unsafe { transmute::<_, [u8, ..2]>((n as u16).to_le()) }),
|
||||
4u => f(unsafe { transmute::<_, [u8, ..4]>((n as u32).to_le()) }),
|
||||
8u => f(unsafe { transmute::<_, [u8, ..8]>(n.to_le()) }),
|
||||
2u => f(unsafe { & transmute::<_, [u8, ..2]>((n as u16).to_le()) }),
|
||||
4u => f(unsafe { & transmute::<_, [u8, ..4]>((n as u32).to_le()) }),
|
||||
8u => f(unsafe { & transmute::<_, [u8, ..8]>(n.to_le()) }),
|
||||
_ => {
|
||||
|
||||
let mut bytes = vec!();
|
||||
|
@ -121,9 +121,9 @@ pub fn u64_to_be_bytes<T>(n: u64, size: uint, f: |v: &[u8]| -> T) -> T {
|
|||
assert!(size <= 8u);
|
||||
match size {
|
||||
1u => f(&[n as u8]),
|
||||
2u => f(unsafe { transmute::<_, [u8, ..2]>((n as u16).to_be()) }),
|
||||
4u => f(unsafe { transmute::<_, [u8, ..4]>((n as u32).to_be()) }),
|
||||
8u => f(unsafe { transmute::<_, [u8, ..8]>(n.to_be()) }),
|
||||
2u => f(unsafe { & transmute::<_, [u8, ..2]>((n as u16).to_be()) }),
|
||||
4u => f(unsafe { & transmute::<_, [u8, ..4]>((n as u32).to_be()) }),
|
||||
8u => f(unsafe { & transmute::<_, [u8, ..8]>(n.to_be()) }),
|
||||
_ => {
|
||||
let mut bytes = vec!();
|
||||
let mut i = size;
|
||||
|
@ -474,26 +474,26 @@ mod test {
|
|||
let buf = [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09];
|
||||
|
||||
// Aligned access
|
||||
assert_eq!(u64_from_be_bytes(buf, 0, 0), 0);
|
||||
assert_eq!(u64_from_be_bytes(buf, 0, 1), 0x01);
|
||||
assert_eq!(u64_from_be_bytes(buf, 0, 2), 0x0102);
|
||||
assert_eq!(u64_from_be_bytes(buf, 0, 3), 0x010203);
|
||||
assert_eq!(u64_from_be_bytes(buf, 0, 4), 0x01020304);
|
||||
assert_eq!(u64_from_be_bytes(buf, 0, 5), 0x0102030405);
|
||||
assert_eq!(u64_from_be_bytes(buf, 0, 6), 0x010203040506);
|
||||
assert_eq!(u64_from_be_bytes(buf, 0, 7), 0x01020304050607);
|
||||
assert_eq!(u64_from_be_bytes(buf, 0, 8), 0x0102030405060708);
|
||||
assert_eq!(u64_from_be_bytes(&buf, 0, 0), 0);
|
||||
assert_eq!(u64_from_be_bytes(&buf, 0, 1), 0x01);
|
||||
assert_eq!(u64_from_be_bytes(&buf, 0, 2), 0x0102);
|
||||
assert_eq!(u64_from_be_bytes(&buf, 0, 3), 0x010203);
|
||||
assert_eq!(u64_from_be_bytes(&buf, 0, 4), 0x01020304);
|
||||
assert_eq!(u64_from_be_bytes(&buf, 0, 5), 0x0102030405);
|
||||
assert_eq!(u64_from_be_bytes(&buf, 0, 6), 0x010203040506);
|
||||
assert_eq!(u64_from_be_bytes(&buf, 0, 7), 0x01020304050607);
|
||||
assert_eq!(u64_from_be_bytes(&buf, 0, 8), 0x0102030405060708);
|
||||
|
||||
// Unaligned access
|
||||
assert_eq!(u64_from_be_bytes(buf, 1, 0), 0);
|
||||
assert_eq!(u64_from_be_bytes(buf, 1, 1), 0x02);
|
||||
assert_eq!(u64_from_be_bytes(buf, 1, 2), 0x0203);
|
||||
assert_eq!(u64_from_be_bytes(buf, 1, 3), 0x020304);
|
||||
assert_eq!(u64_from_be_bytes(buf, 1, 4), 0x02030405);
|
||||
assert_eq!(u64_from_be_bytes(buf, 1, 5), 0x0203040506);
|
||||
assert_eq!(u64_from_be_bytes(buf, 1, 6), 0x020304050607);
|
||||
assert_eq!(u64_from_be_bytes(buf, 1, 7), 0x02030405060708);
|
||||
assert_eq!(u64_from_be_bytes(buf, 1, 8), 0x0203040506070809);
|
||||
assert_eq!(u64_from_be_bytes(&buf, 1, 0), 0);
|
||||
assert_eq!(u64_from_be_bytes(&buf, 1, 1), 0x02);
|
||||
assert_eq!(u64_from_be_bytes(&buf, 1, 2), 0x0203);
|
||||
assert_eq!(u64_from_be_bytes(&buf, 1, 3), 0x020304);
|
||||
assert_eq!(u64_from_be_bytes(&buf, 1, 4), 0x02030405);
|
||||
assert_eq!(u64_from_be_bytes(&buf, 1, 5), 0x0203040506);
|
||||
assert_eq!(u64_from_be_bytes(&buf, 1, 6), 0x020304050607);
|
||||
assert_eq!(u64_from_be_bytes(&buf, 1, 7), 0x02030405060708);
|
||||
assert_eq!(u64_from_be_bytes(&buf, 1, 8), 0x0203040506070809);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -384,7 +384,7 @@ pub fn copy(from: &Path, to: &Path) -> IoResult<()> {
|
|||
let mut buf = [0, ..io::DEFAULT_BUF_SIZE];
|
||||
|
||||
loop {
|
||||
let amt = match reader.read(buf) {
|
||||
let amt = match reader.read(&mut buf) {
|
||||
Ok(n) => n,
|
||||
Err(ref e) if e.kind == io::EndOfFile => { break }
|
||||
Err(e) => return update_err(Err(e), from, to)
|
||||
|
@ -881,7 +881,7 @@ mod test {
|
|||
{
|
||||
let mut read_stream = File::open_mode(filename, Open, Read);
|
||||
let mut read_buf = [0, .. 1028];
|
||||
let read_str = match check!(read_stream.read(read_buf)) {
|
||||
let read_str = match check!(read_stream.read(&mut read_buf)) {
|
||||
-1|0 => panic!("shouldn't happen"),
|
||||
n => str::from_utf8(read_buf[..n]).unwrap().to_string()
|
||||
};
|
||||
|
@ -939,7 +939,7 @@ mod test {
|
|||
}
|
||||
}
|
||||
check!(unlink(filename));
|
||||
let read_str = str::from_utf8(read_mem).unwrap();
|
||||
let read_str = str::from_utf8(&read_mem).unwrap();
|
||||
assert_eq!(read_str, message);
|
||||
}
|
||||
|
||||
|
@ -960,11 +960,11 @@ mod test {
|
|||
let mut read_stream = File::open_mode(filename, Open, Read);
|
||||
check!(read_stream.seek(set_cursor as i64, SeekSet));
|
||||
tell_pos_pre_read = check!(read_stream.tell());
|
||||
check!(read_stream.read(read_mem));
|
||||
check!(read_stream.read(&mut read_mem));
|
||||
tell_pos_post_read = check!(read_stream.tell());
|
||||
}
|
||||
check!(unlink(filename));
|
||||
let read_str = str::from_utf8(read_mem).unwrap();
|
||||
let read_str = str::from_utf8(&read_mem).unwrap();
|
||||
assert_eq!(read_str, message.slice(4, 8));
|
||||
assert_eq!(tell_pos_pre_read, set_cursor);
|
||||
assert_eq!(tell_pos_post_read, message.len() as u64);
|
||||
|
@ -987,10 +987,10 @@ mod test {
|
|||
}
|
||||
{
|
||||
let mut read_stream = File::open_mode(filename, Open, Read);
|
||||
check!(read_stream.read(read_mem));
|
||||
check!(read_stream.read(&mut read_mem));
|
||||
}
|
||||
check!(unlink(filename));
|
||||
let read_str = str::from_utf8(read_mem).unwrap();
|
||||
let read_str = str::from_utf8(&read_mem).unwrap();
|
||||
assert!(read_str.as_slice() == final_msg.as_slice());
|
||||
}
|
||||
|
||||
|
@ -1012,16 +1012,16 @@ mod test {
|
|||
let mut read_stream = File::open_mode(filename, Open, Read);
|
||||
|
||||
check!(read_stream.seek(-4, SeekEnd));
|
||||
check!(read_stream.read(read_mem));
|
||||
assert_eq!(str::from_utf8(read_mem).unwrap(), chunk_three);
|
||||
check!(read_stream.read(&mut read_mem));
|
||||
assert_eq!(str::from_utf8(&read_mem).unwrap(), chunk_three);
|
||||
|
||||
check!(read_stream.seek(-9, SeekCur));
|
||||
check!(read_stream.read(read_mem));
|
||||
assert_eq!(str::from_utf8(read_mem).unwrap(), chunk_two);
|
||||
check!(read_stream.read(&mut read_mem));
|
||||
assert_eq!(str::from_utf8(&read_mem).unwrap(), chunk_two);
|
||||
|
||||
check!(read_stream.seek(0, SeekSet));
|
||||
check!(read_stream.read(read_mem));
|
||||
assert_eq!(str::from_utf8(read_mem).unwrap(), chunk_one);
|
||||
check!(read_stream.read(&mut read_mem));
|
||||
assert_eq!(str::from_utf8(&read_mem).unwrap(), chunk_one);
|
||||
}
|
||||
check!(unlink(filename));
|
||||
}
|
||||
|
@ -1107,8 +1107,8 @@ mod test {
|
|||
for f in files.iter() {
|
||||
{
|
||||
let n = f.filestem_str();
|
||||
check!(File::open(f).read(mem));
|
||||
let read_str = str::from_utf8(mem).unwrap();
|
||||
check!(File::open(f).read(&mut mem));
|
||||
let read_str = str::from_utf8(&mem).unwrap();
|
||||
let expected = match n {
|
||||
None|Some("") => panic!("really shouldn't happen.."),
|
||||
Some(n) => format!("{}{}", prefix, n),
|
||||
|
@ -1532,13 +1532,13 @@ mod test {
|
|||
use rand::{StdRng, Rng};
|
||||
|
||||
let mut bytes = [0, ..1024];
|
||||
StdRng::new().ok().unwrap().fill_bytes(bytes);
|
||||
StdRng::new().ok().unwrap().fill_bytes(&mut bytes);
|
||||
|
||||
let tmpdir = tmpdir();
|
||||
|
||||
check!(File::create(&tmpdir.join("test")).write(bytes));
|
||||
check!(File::create(&tmpdir.join("test")).write(&bytes));
|
||||
let actual = check!(File::open(&tmpdir.join("test")).read_to_end());
|
||||
assert!(actual.as_slice() == bytes);
|
||||
assert!(actual.as_slice() == &bytes);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -50,7 +50,7 @@ fn combine(seek: SeekStyle, cur: uint, end: uint, offset: i64) -> IoResult<u64>
|
|||
/// use std::io::MemWriter;
|
||||
///
|
||||
/// let mut w = MemWriter::new();
|
||||
/// w.write([0, 1, 2]);
|
||||
/// w.write(&[0, 1, 2]);
|
||||
///
|
||||
/// assert_eq!(w.unwrap(), vec!(0, 1, 2));
|
||||
/// ```
|
||||
|
@ -200,8 +200,8 @@ impl Buffer for MemReader {
|
|||
///
|
||||
/// let mut buf = [0, ..4];
|
||||
/// {
|
||||
/// let mut w = BufWriter::new(buf);
|
||||
/// w.write([0, 1, 2]);
|
||||
/// let mut w = BufWriter::new(&mut buf);
|
||||
/// w.write(&[0, 1, 2]);
|
||||
/// }
|
||||
/// assert!(buf == [0, 1, 2, 0]);
|
||||
/// ```
|
||||
|
@ -262,7 +262,7 @@ impl<'a> Seek for BufWriter<'a> {
|
|||
/// use std::io::BufReader;
|
||||
///
|
||||
/// let mut buf = [0, 1, 2, 3];
|
||||
/// let mut r = BufReader::new(buf);
|
||||
/// let mut r = BufReader::new(&mut buf);
|
||||
///
|
||||
/// assert_eq!(r.read_to_end().unwrap(), vec!(0, 1, 2, 3));
|
||||
/// ```
|
||||
|
@ -346,9 +346,9 @@ mod test {
|
|||
#[test]
|
||||
fn test_mem_writer() {
|
||||
let mut writer = MemWriter::new();
|
||||
writer.write([0]).unwrap();
|
||||
writer.write([1, 2, 3]).unwrap();
|
||||
writer.write([4, 5, 6, 7]).unwrap();
|
||||
writer.write(&[0]).unwrap();
|
||||
writer.write(&[1, 2, 3]).unwrap();
|
||||
writer.write(&[4, 5, 6, 7]).unwrap();
|
||||
let b: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7];
|
||||
assert_eq!(writer.get_ref(), b);
|
||||
}
|
||||
|
@ -357,14 +357,14 @@ mod test {
|
|||
fn test_buf_writer() {
|
||||
let mut buf = [0 as u8, ..8];
|
||||
{
|
||||
let mut writer = BufWriter::new(buf);
|
||||
let mut writer = BufWriter::new(&mut buf);
|
||||
assert_eq!(writer.tell(), Ok(0));
|
||||
writer.write([0]).unwrap();
|
||||
writer.write(&[0]).unwrap();
|
||||
assert_eq!(writer.tell(), Ok(1));
|
||||
writer.write([1, 2, 3]).unwrap();
|
||||
writer.write([4, 5, 6, 7]).unwrap();
|
||||
writer.write(&[1, 2, 3]).unwrap();
|
||||
writer.write(&[4, 5, 6, 7]).unwrap();
|
||||
assert_eq!(writer.tell(), Ok(8));
|
||||
writer.write([]).unwrap();
|
||||
writer.write(&[]).unwrap();
|
||||
assert_eq!(writer.tell(), Ok(8));
|
||||
}
|
||||
let b: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7];
|
||||
|
@ -375,24 +375,24 @@ mod test {
|
|||
fn test_buf_writer_seek() {
|
||||
let mut buf = [0 as u8, ..8];
|
||||
{
|
||||
let mut writer = BufWriter::new(buf);
|
||||
let mut writer = BufWriter::new(&mut buf);
|
||||
assert_eq!(writer.tell(), Ok(0));
|
||||
writer.write([1]).unwrap();
|
||||
writer.write(&[1]).unwrap();
|
||||
assert_eq!(writer.tell(), Ok(1));
|
||||
|
||||
writer.seek(2, SeekSet).unwrap();
|
||||
assert_eq!(writer.tell(), Ok(2));
|
||||
writer.write([2]).unwrap();
|
||||
writer.write(&[2]).unwrap();
|
||||
assert_eq!(writer.tell(), Ok(3));
|
||||
|
||||
writer.seek(-2, SeekCur).unwrap();
|
||||
assert_eq!(writer.tell(), Ok(1));
|
||||
writer.write([3]).unwrap();
|
||||
writer.write(&[3]).unwrap();
|
||||
assert_eq!(writer.tell(), Ok(2));
|
||||
|
||||
writer.seek(-1, SeekEnd).unwrap();
|
||||
assert_eq!(writer.tell(), Ok(7));
|
||||
writer.write([4]).unwrap();
|
||||
writer.write(&[4]).unwrap();
|
||||
assert_eq!(writer.tell(), Ok(8));
|
||||
|
||||
}
|
||||
|
@ -403,10 +403,10 @@ mod test {
|
|||
#[test]
|
||||
fn test_buf_writer_error() {
|
||||
let mut buf = [0 as u8, ..2];
|
||||
let mut writer = BufWriter::new(buf);
|
||||
writer.write([0]).unwrap();
|
||||
let mut writer = BufWriter::new(&mut buf);
|
||||
writer.write(&[0]).unwrap();
|
||||
|
||||
match writer.write([0, 0]) {
|
||||
match writer.write(&[0, 0]) {
|
||||
Ok(..) => panic!(),
|
||||
Err(e) => assert_eq!(e.kind, io::OtherIoError),
|
||||
}
|
||||
|
@ -416,26 +416,26 @@ mod test {
|
|||
fn test_mem_reader() {
|
||||
let mut reader = MemReader::new(vec!(0, 1, 2, 3, 4, 5, 6, 7));
|
||||
let mut buf = [];
|
||||
assert_eq!(reader.read(buf), Ok(0));
|
||||
assert_eq!(reader.read(&mut buf), Ok(0));
|
||||
assert_eq!(reader.tell(), Ok(0));
|
||||
let mut buf = [0];
|
||||
assert_eq!(reader.read(buf), Ok(1));
|
||||
assert_eq!(reader.read(&mut buf), Ok(1));
|
||||
assert_eq!(reader.tell(), Ok(1));
|
||||
let b: &[_] = &[0];
|
||||
assert_eq!(buf.as_slice(), b);
|
||||
let mut buf = [0, ..4];
|
||||
assert_eq!(reader.read(buf), Ok(4));
|
||||
assert_eq!(reader.read(&mut buf), Ok(4));
|
||||
assert_eq!(reader.tell(), Ok(5));
|
||||
let b: &[_] = &[1, 2, 3, 4];
|
||||
assert_eq!(buf.as_slice(), b);
|
||||
assert_eq!(reader.read(buf), Ok(3));
|
||||
assert_eq!(reader.read(&mut buf), Ok(3));
|
||||
let b: &[_] = &[5, 6, 7];
|
||||
assert_eq!(buf[0..3], b);
|
||||
assert!(reader.read(buf).is_err());
|
||||
assert!(reader.read(&mut buf).is_err());
|
||||
let mut reader = MemReader::new(vec!(0, 1, 2, 3, 4, 5, 6, 7));
|
||||
assert_eq!(reader.read_until(3).unwrap(), vec!(0, 1, 2, 3));
|
||||
assert_eq!(reader.read_until(3).unwrap(), vec!(4, 5, 6, 7));
|
||||
assert!(reader.read(buf).is_err());
|
||||
assert!(reader.read(&mut buf).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -443,26 +443,26 @@ mod test {
|
|||
let in_buf = vec![0, 1, 2, 3, 4, 5, 6, 7];
|
||||
let mut reader = BufReader::new(in_buf.as_slice());
|
||||
let mut buf = [];
|
||||
assert_eq!(reader.read(buf), Ok(0));
|
||||
assert_eq!(reader.read(&mut buf), Ok(0));
|
||||
assert_eq!(reader.tell(), Ok(0));
|
||||
let mut buf = [0];
|
||||
assert_eq!(reader.read(buf), Ok(1));
|
||||
assert_eq!(reader.read(&mut buf), Ok(1));
|
||||
assert_eq!(reader.tell(), Ok(1));
|
||||
let b: &[_] = &[0];
|
||||
assert_eq!(buf.as_slice(), b);
|
||||
let mut buf = [0, ..4];
|
||||
assert_eq!(reader.read(buf), Ok(4));
|
||||
assert_eq!(reader.read(&mut buf), Ok(4));
|
||||
assert_eq!(reader.tell(), Ok(5));
|
||||
let b: &[_] = &[1, 2, 3, 4];
|
||||
assert_eq!(buf.as_slice(), b);
|
||||
assert_eq!(reader.read(buf), Ok(3));
|
||||
assert_eq!(reader.read(&mut buf), Ok(3));
|
||||
let b: &[_] = &[5, 6, 7];
|
||||
assert_eq!(buf[0..3], b);
|
||||
assert!(reader.read(buf).is_err());
|
||||
assert!(reader.read(&mut buf).is_err());
|
||||
let mut reader = BufReader::new(in_buf.as_slice());
|
||||
assert_eq!(reader.read_until(3).unwrap(), vec!(0, 1, 2, 3));
|
||||
assert_eq!(reader.read_until(3).unwrap(), vec!(4, 5, 6, 7));
|
||||
assert!(reader.read(buf).is_err());
|
||||
assert!(reader.read(&mut buf).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -506,7 +506,7 @@ mod test {
|
|||
#[test]
|
||||
fn test_read_whole_string_bad() {
|
||||
let buf = [0xff];
|
||||
let mut r = BufReader::new(buf);
|
||||
let mut r = BufReader::new(&buf);
|
||||
match r.read_to_string() {
|
||||
Ok(..) => panic!(),
|
||||
Err(..) => {}
|
||||
|
@ -516,7 +516,7 @@ mod test {
|
|||
#[test]
|
||||
fn seek_past_end() {
|
||||
let buf = [0xff];
|
||||
let mut r = BufReader::new(buf);
|
||||
let mut r = BufReader::new(&buf);
|
||||
r.seek(10, SeekSet).unwrap();
|
||||
assert!(r.read(&mut []).is_err());
|
||||
|
||||
|
@ -525,22 +525,22 @@ mod test {
|
|||
assert!(r.read(&mut []).is_err());
|
||||
|
||||
let mut buf = [0];
|
||||
let mut r = BufWriter::new(buf);
|
||||
let mut r = BufWriter::new(&mut buf);
|
||||
r.seek(10, SeekSet).unwrap();
|
||||
assert!(r.write([3]).is_err());
|
||||
assert!(r.write(&[3]).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn seek_before_0() {
|
||||
let buf = [0xff];
|
||||
let mut r = BufReader::new(buf);
|
||||
let mut r = BufReader::new(&buf);
|
||||
assert!(r.seek(-1, SeekSet).is_err());
|
||||
|
||||
let mut r = MemReader::new(vec!(10));
|
||||
assert!(r.seek(-1, SeekSet).is_err());
|
||||
|
||||
let mut buf = [0];
|
||||
let mut r = BufWriter::new(buf);
|
||||
let mut r = BufWriter::new(&mut buf);
|
||||
assert!(r.seek(-1, SeekSet).is_err());
|
||||
}
|
||||
|
||||
|
@ -548,15 +548,15 @@ mod test {
|
|||
fn io_read_at_least() {
|
||||
let mut r = MemReader::new(vec![1, 2, 3, 4, 5, 6, 7, 8]);
|
||||
let mut buf = [0, ..3];
|
||||
assert!(r.read_at_least(buf.len(), buf).is_ok());
|
||||
assert!(r.read_at_least(buf.len(), &mut buf).is_ok());
|
||||
let b: &[_] = &[1, 2, 3];
|
||||
assert_eq!(buf.as_slice(), b);
|
||||
assert!(r.read_at_least(0, buf[mut ..0]).is_ok());
|
||||
assert_eq!(buf.as_slice(), b);
|
||||
assert!(r.read_at_least(buf.len(), buf).is_ok());
|
||||
assert!(r.read_at_least(buf.len(), &mut buf).is_ok());
|
||||
let b: &[_] = &[4, 5, 6];
|
||||
assert_eq!(buf.as_slice(), b);
|
||||
assert!(r.read_at_least(buf.len(), buf).is_err());
|
||||
assert!(r.read_at_least(buf.len(), &mut buf).is_err());
|
||||
let b: &[_] = &[7, 8, 6];
|
||||
assert_eq!(buf.as_slice(), b);
|
||||
}
|
||||
|
@ -625,7 +625,7 @@ mod test {
|
|||
let mut rdr = MemReader::new(buf);
|
||||
for _i in range(0u, 10) {
|
||||
let mut buf = [0 as u8, .. 10];
|
||||
rdr.read(buf).unwrap();
|
||||
rdr.read(&mut buf).unwrap();
|
||||
assert_eq!(buf.as_slice(), [5, .. 10].as_slice());
|
||||
}
|
||||
}
|
||||
|
@ -637,9 +637,9 @@ mod test {
|
|||
b.iter(|| {
|
||||
let mut buf = [0 as u8, ..100];
|
||||
{
|
||||
let mut wr = BufWriter::new(buf);
|
||||
let mut wr = BufWriter::new(&mut buf);
|
||||
for _i in range(0u, 10) {
|
||||
wr.write([5, .. 10]).unwrap();
|
||||
wr.write(&[5, .. 10]).unwrap();
|
||||
}
|
||||
}
|
||||
assert_eq!(buf.as_slice(), [5, .. 100].as_slice());
|
||||
|
@ -651,10 +651,10 @@ mod test {
|
|||
b.iter(|| {
|
||||
let buf = [5 as u8, ..100];
|
||||
{
|
||||
let mut rdr = BufReader::new(buf);
|
||||
let mut rdr = BufReader::new(&buf);
|
||||
for _i in range(0u, 10) {
|
||||
let mut buf = [0 as u8, .. 10];
|
||||
rdr.read(buf).unwrap();
|
||||
rdr.read(&mut buf).unwrap();
|
||||
assert_eq!(buf.as_slice(), [5, .. 10].as_slice());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -521,7 +521,7 @@ pub trait Reader {
|
|||
/// Reads a single byte. Returns `Err` on EOF.
|
||||
fn read_byte(&mut self) -> IoResult<u8> {
|
||||
let mut buf = [0];
|
||||
try!(self.read_at_least(1, buf));
|
||||
try!(self.read_at_least(1, &mut buf));
|
||||
Ok(buf[0])
|
||||
}
|
||||
|
||||
|
@ -1061,7 +1061,7 @@ pub trait Writer {
|
|||
/// that the `write` method is used specifically instead.
|
||||
#[inline]
|
||||
fn write_line(&mut self, s: &str) -> IoResult<()> {
|
||||
self.write_str(s).and_then(|()| self.write([b'\n']))
|
||||
self.write_str(s).and_then(|()| self.write(&[b'\n']))
|
||||
}
|
||||
|
||||
/// Write a single char, encoded as UTF-8.
|
||||
|
@ -1217,13 +1217,13 @@ pub trait Writer {
|
|||
/// Write a u8 (1 byte).
|
||||
#[inline]
|
||||
fn write_u8(&mut self, n: u8) -> IoResult<()> {
|
||||
self.write([n])
|
||||
self.write(&[n])
|
||||
}
|
||||
|
||||
/// Write an i8 (1 byte).
|
||||
#[inline]
|
||||
fn write_i8(&mut self, n: i8) -> IoResult<()> {
|
||||
self.write([n as u8])
|
||||
self.write(&[n as u8])
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1949,7 +1949,7 @@ mod tests {
|
|||
fn test_read_at_least() {
|
||||
let mut r = BadReader::new(MemReader::new(b"hello, world!".to_vec()),
|
||||
vec![GoodBehavior(uint::MAX)]);
|
||||
let mut buf = [0u8, ..5];
|
||||
let buf = &mut [0u8, ..5];
|
||||
assert!(r.read_at_least(1, buf).unwrap() >= 1);
|
||||
assert!(r.read_exact(5).unwrap().len() == 5); // read_exact uses read_at_least
|
||||
assert!(r.read_at_least(0, buf).is_ok());
|
||||
|
|
|
@ -53,7 +53,7 @@ impl UnixStream {
|
|||
///
|
||||
/// let server = Path::new("path/to/my/socket");
|
||||
/// let mut stream = UnixStream::connect(&server);
|
||||
/// stream.write([1, 2, 3]);
|
||||
/// stream.write(&[1, 2, 3]);
|
||||
/// ```
|
||||
pub fn connect<P: ToCStr>(path: &P) -> IoResult<UnixStream> {
|
||||
UnixStreamImp::connect(&path.to_c_str(), None)
|
||||
|
@ -169,7 +169,7 @@ impl UnixListener {
|
|||
/// let server = Path::new("/path/to/my/socket");
|
||||
/// let stream = UnixListener::bind(&server);
|
||||
/// for mut client in stream.listen().incoming() {
|
||||
/// client.write([1, 2, 3, 4]);
|
||||
/// client.write(&[1, 2, 3, 4]);
|
||||
/// }
|
||||
/// # }
|
||||
/// ```
|
||||
|
@ -307,10 +307,10 @@ mod tests {
|
|||
fn smoke() {
|
||||
smalltest(proc(mut server) {
|
||||
let mut buf = [0];
|
||||
server.read(buf).unwrap();
|
||||
server.read(&mut buf).unwrap();
|
||||
assert!(buf[0] == 99);
|
||||
}, proc(mut client) {
|
||||
client.write([99]).unwrap();
|
||||
client.write(&[99]).unwrap();
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -319,8 +319,8 @@ mod tests {
|
|||
fn read_eof() {
|
||||
smalltest(proc(mut server) {
|
||||
let mut buf = [0];
|
||||
assert!(server.read(buf).is_err());
|
||||
assert!(server.read(buf).is_err());
|
||||
assert!(server.read(&mut buf).is_err());
|
||||
assert!(server.read(&mut buf).is_err());
|
||||
}, proc(_client) {
|
||||
// drop the client
|
||||
})
|
||||
|
@ -331,7 +331,7 @@ mod tests {
|
|||
smalltest(proc(mut server) {
|
||||
let buf = [0];
|
||||
loop {
|
||||
match server.write(buf) {
|
||||
match server.write(&buf) {
|
||||
Ok(..) => {}
|
||||
Err(e) => {
|
||||
assert!(e.kind == BrokenPipe ||
|
||||
|
@ -361,7 +361,7 @@ mod tests {
|
|||
spawn(proc() {
|
||||
for _ in range(0u, times) {
|
||||
let mut stream = UnixStream::connect(&path2);
|
||||
match stream.write([100]) {
|
||||
match stream.write(&[100]) {
|
||||
Ok(..) => {}
|
||||
Err(e) => panic!("failed write: {}", e)
|
||||
}
|
||||
|
@ -371,7 +371,7 @@ mod tests {
|
|||
for _ in range(0, times) {
|
||||
let mut client = acceptor.accept();
|
||||
let mut buf = [0];
|
||||
match client.read(buf) {
|
||||
match client.read(&mut buf) {
|
||||
Ok(..) => {}
|
||||
Err(e) => panic!("failed read/accept: {}", e),
|
||||
}
|
||||
|
@ -396,10 +396,10 @@ mod tests {
|
|||
let mut s = UnixStream::connect(&addr);
|
||||
let mut buf = [0, 0];
|
||||
debug!("client reading");
|
||||
assert_eq!(s.read(buf), Ok(1));
|
||||
assert_eq!(s.read(&mut buf), Ok(1));
|
||||
assert_eq!(buf[0], 1);
|
||||
debug!("client writing");
|
||||
s.write([2]).unwrap();
|
||||
s.write(&[2]).unwrap();
|
||||
debug!("client dropping");
|
||||
});
|
||||
|
||||
|
@ -412,14 +412,14 @@ mod tests {
|
|||
let mut s2 = s2;
|
||||
rx1.recv();
|
||||
debug!("writer writing");
|
||||
s2.write([1]).unwrap();
|
||||
s2.write(&[1]).unwrap();
|
||||
debug!("writer done");
|
||||
tx2.send(());
|
||||
});
|
||||
tx1.send(());
|
||||
let mut buf = [0, 0];
|
||||
debug!("reader reading");
|
||||
assert_eq!(s1.read(buf), Ok(1));
|
||||
assert_eq!(s1.read(&mut buf), Ok(1));
|
||||
debug!("reader done");
|
||||
rx2.recv();
|
||||
}
|
||||
|
@ -433,9 +433,9 @@ mod tests {
|
|||
|
||||
spawn(proc() {
|
||||
let mut s = UnixStream::connect(&addr);
|
||||
s.write([1]).unwrap();
|
||||
s.write(&[1]).unwrap();
|
||||
rx.recv();
|
||||
s.write([2]).unwrap();
|
||||
s.write(&[2]).unwrap();
|
||||
rx.recv();
|
||||
});
|
||||
|
||||
|
@ -446,12 +446,12 @@ mod tests {
|
|||
spawn(proc() {
|
||||
let mut s2 = s2;
|
||||
let mut buf = [0, 0];
|
||||
s2.read(buf).unwrap();
|
||||
s2.read(&mut buf).unwrap();
|
||||
tx2.send(());
|
||||
done.send(());
|
||||
});
|
||||
let mut buf = [0, 0];
|
||||
s1.read(buf).unwrap();
|
||||
s1.read(&mut buf).unwrap();
|
||||
tx1.send(());
|
||||
|
||||
rx.recv();
|
||||
|
@ -464,7 +464,7 @@ mod tests {
|
|||
|
||||
spawn(proc() {
|
||||
let mut s = UnixStream::connect(&addr);
|
||||
let mut buf = [0, 1];
|
||||
let buf = &mut [0, 1];
|
||||
s.read(buf).unwrap();
|
||||
s.read(buf).unwrap();
|
||||
});
|
||||
|
@ -475,10 +475,10 @@ mod tests {
|
|||
let (tx, rx) = channel();
|
||||
spawn(proc() {
|
||||
let mut s2 = s2;
|
||||
s2.write([1]).unwrap();
|
||||
s2.write(&[1]).unwrap();
|
||||
tx.send(());
|
||||
});
|
||||
s1.write([2]).unwrap();
|
||||
s1.write(&[2]).unwrap();
|
||||
|
||||
rx.recv();
|
||||
}
|
||||
|
@ -588,18 +588,18 @@ mod tests {
|
|||
|
||||
// closing should prevent reads/writes
|
||||
s.close_write().unwrap();
|
||||
assert!(s.write([0]).is_err());
|
||||
assert!(s.write(&[0]).is_err());
|
||||
s.close_read().unwrap();
|
||||
assert!(s.read(b).is_err());
|
||||
assert!(s.read(&mut b).is_err());
|
||||
|
||||
// closing should affect previous handles
|
||||
assert!(s2.write([0]).is_err());
|
||||
assert!(s2.read(b).is_err());
|
||||
assert!(s2.write(&[0]).is_err());
|
||||
assert!(s2.read(&mut b).is_err());
|
||||
|
||||
// closing should affect new handles
|
||||
let mut s3 = s.clone();
|
||||
assert!(s3.write([0]).is_err());
|
||||
assert!(s3.read(b).is_err());
|
||||
assert!(s3.write(&[0]).is_err());
|
||||
assert!(s3.read(&mut b).is_err());
|
||||
|
||||
// make sure these don't die
|
||||
let _ = s2.close_read();
|
||||
|
@ -624,7 +624,7 @@ mod tests {
|
|||
let (tx, rx) = channel();
|
||||
spawn(proc() {
|
||||
let mut s2 = s2;
|
||||
assert!(s2.read([0]).is_err());
|
||||
assert!(s2.read(&mut [0]).is_err());
|
||||
tx.send(());
|
||||
});
|
||||
// this should wake up the child task
|
||||
|
@ -642,18 +642,18 @@ mod tests {
|
|||
spawn(proc() {
|
||||
let mut s = UnixStream::connect(&addr).unwrap();
|
||||
rx.recv();
|
||||
assert!(s.write([0]).is_ok());
|
||||
assert!(s.write(&[0]).is_ok());
|
||||
let _ = rx.recv_opt();
|
||||
});
|
||||
|
||||
let mut s = a.accept().unwrap();
|
||||
s.set_timeout(Some(20));
|
||||
assert_eq!(s.read([0]).err().unwrap().kind, TimedOut);
|
||||
assert_eq!(s.read([0]).err().unwrap().kind, TimedOut);
|
||||
assert_eq!(s.read(&mut [0]).err().unwrap().kind, TimedOut);
|
||||
assert_eq!(s.read(&mut [0]).err().unwrap().kind, TimedOut);
|
||||
|
||||
s.set_timeout(Some(20));
|
||||
for i in range(0u, 1001) {
|
||||
match s.write([0, .. 128 * 1024]) {
|
||||
match s.write(&[0, .. 128 * 1024]) {
|
||||
Ok(()) | Err(IoError { kind: ShortWrite(..), .. }) => {},
|
||||
Err(IoError { kind: TimedOut, .. }) => break,
|
||||
Err(e) => panic!("{}", e),
|
||||
|
@ -664,12 +664,12 @@ mod tests {
|
|||
// I'm not sure as to why, but apparently the write on windows always
|
||||
// succeeds after the previous timeout. Who knows?
|
||||
if !cfg!(windows) {
|
||||
assert_eq!(s.write([0]).err().unwrap().kind, TimedOut);
|
||||
assert_eq!(s.write(&[0]).err().unwrap().kind, TimedOut);
|
||||
}
|
||||
|
||||
tx.send(());
|
||||
s.set_timeout(None);
|
||||
assert_eq!(s.read([0, 0]), Ok(1));
|
||||
assert_eq!(s.read(&mut [0, 0]), Ok(1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -682,7 +682,7 @@ mod tests {
|
|||
rx.recv();
|
||||
let mut amt = 0;
|
||||
while amt < 100 * 128 * 1024 {
|
||||
match s.read([0, ..128 * 1024]) {
|
||||
match s.read(&mut [0, ..128 * 1024]) {
|
||||
Ok(n) => { amt += n; }
|
||||
Err(e) => panic!("{}", e),
|
||||
}
|
||||
|
@ -692,12 +692,12 @@ mod tests {
|
|||
|
||||
let mut s = a.accept().unwrap();
|
||||
s.set_read_timeout(Some(20));
|
||||
assert_eq!(s.read([0]).err().unwrap().kind, TimedOut);
|
||||
assert_eq!(s.read([0]).err().unwrap().kind, TimedOut);
|
||||
assert_eq!(s.read(&mut [0]).err().unwrap().kind, TimedOut);
|
||||
assert_eq!(s.read(&mut [0]).err().unwrap().kind, TimedOut);
|
||||
|
||||
tx.send(());
|
||||
for _ in range(0u, 100) {
|
||||
assert!(s.write([0, ..128 * 1024]).is_ok());
|
||||
assert!(s.write(&[0, ..128 * 1024]).is_ok());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -709,14 +709,14 @@ mod tests {
|
|||
spawn(proc() {
|
||||
let mut s = UnixStream::connect(&addr).unwrap();
|
||||
rx.recv();
|
||||
assert!(s.write([0]).is_ok());
|
||||
assert!(s.write(&[0]).is_ok());
|
||||
let _ = rx.recv_opt();
|
||||
});
|
||||
|
||||
let mut s = a.accept().unwrap();
|
||||
s.set_write_timeout(Some(20));
|
||||
for i in range(0u, 1001) {
|
||||
match s.write([0, .. 128 * 1024]) {
|
||||
match s.write(&[0, .. 128 * 1024]) {
|
||||
Ok(()) | Err(IoError { kind: ShortWrite(..), .. }) => {},
|
||||
Err(IoError { kind: TimedOut, .. }) => break,
|
||||
Err(e) => panic!("{}", e),
|
||||
|
@ -725,7 +725,7 @@ mod tests {
|
|||
}
|
||||
|
||||
tx.send(());
|
||||
assert!(s.read([0]).is_ok());
|
||||
assert!(s.read(&mut [0]).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -736,7 +736,7 @@ mod tests {
|
|||
spawn(proc() {
|
||||
let mut s = UnixStream::connect(&addr).unwrap();
|
||||
rx.recv();
|
||||
assert!(s.write([0]).is_ok());
|
||||
assert!(s.write(&[0]).is_ok());
|
||||
let _ = rx.recv_opt();
|
||||
});
|
||||
|
||||
|
@ -745,12 +745,12 @@ mod tests {
|
|||
let (tx2, rx2) = channel();
|
||||
spawn(proc() {
|
||||
let mut s2 = s2;
|
||||
assert!(s2.read([0]).is_ok());
|
||||
assert!(s2.read(&mut [0]).is_ok());
|
||||
tx2.send(());
|
||||
});
|
||||
|
||||
s.set_read_timeout(Some(20));
|
||||
assert_eq!(s.read([0]).err().unwrap().kind, TimedOut);
|
||||
assert_eq!(s.read(&mut [0]).err().unwrap().kind, TimedOut);
|
||||
tx.send(());
|
||||
|
||||
rx2.recv();
|
||||
|
|
|
@ -42,9 +42,9 @@ use sys::tcp::TcpAcceptor as TcpAcceptorImp;
|
|||
///
|
||||
/// let mut stream = TcpStream::connect("127.0.0.1:34254");
|
||||
///
|
||||
/// stream.write([1]);
|
||||
/// stream.write(&[1]);
|
||||
/// let mut buf = [0];
|
||||
/// stream.read(buf);
|
||||
/// stream.read(&mut buf);
|
||||
/// drop(stream); // close the connection
|
||||
/// ```
|
||||
pub struct TcpStream {
|
||||
|
@ -143,7 +143,7 @@ impl TcpStream {
|
|||
///
|
||||
/// // wait for some data, will get canceled after one second
|
||||
/// let mut buf = [0];
|
||||
/// stream.read(buf);
|
||||
/// stream.read(&mut buf);
|
||||
/// ```
|
||||
///
|
||||
/// Note that this method affects all cloned handles associated with this
|
||||
|
@ -487,12 +487,12 @@ mod test {
|
|||
|
||||
spawn(proc() {
|
||||
let mut stream = TcpStream::connect(("localhost", socket_addr.port));
|
||||
stream.write([144]).unwrap();
|
||||
stream.write(&[144]).unwrap();
|
||||
});
|
||||
|
||||
let mut stream = acceptor.accept();
|
||||
let mut buf = [0];
|
||||
stream.read(buf).unwrap();
|
||||
stream.read(&mut buf).unwrap();
|
||||
assert!(buf[0] == 144);
|
||||
}
|
||||
|
||||
|
@ -503,12 +503,12 @@ mod test {
|
|||
|
||||
spawn(proc() {
|
||||
let mut stream = TcpStream::connect(("localhost", addr.port));
|
||||
stream.write([64]).unwrap();
|
||||
stream.write(&[64]).unwrap();
|
||||
});
|
||||
|
||||
let mut stream = acceptor.accept();
|
||||
let mut buf = [0];
|
||||
stream.read(buf).unwrap();
|
||||
stream.read(&mut buf).unwrap();
|
||||
assert!(buf[0] == 64);
|
||||
}
|
||||
|
||||
|
@ -519,12 +519,12 @@ mod test {
|
|||
|
||||
spawn(proc() {
|
||||
let mut stream = TcpStream::connect(("127.0.0.1", addr.port));
|
||||
stream.write([44]).unwrap();
|
||||
stream.write(&[44]).unwrap();
|
||||
});
|
||||
|
||||
let mut stream = acceptor.accept();
|
||||
let mut buf = [0];
|
||||
stream.read(buf).unwrap();
|
||||
stream.read(&mut buf).unwrap();
|
||||
assert!(buf[0] == 44);
|
||||
}
|
||||
|
||||
|
@ -535,12 +535,12 @@ mod test {
|
|||
|
||||
spawn(proc() {
|
||||
let mut stream = TcpStream::connect(("::1", addr.port));
|
||||
stream.write([66]).unwrap();
|
||||
stream.write(&[66]).unwrap();
|
||||
});
|
||||
|
||||
let mut stream = acceptor.accept();
|
||||
let mut buf = [0];
|
||||
stream.read(buf).unwrap();
|
||||
stream.read(&mut buf).unwrap();
|
||||
assert!(buf[0] == 66);
|
||||
}
|
||||
|
||||
|
@ -551,12 +551,12 @@ mod test {
|
|||
|
||||
spawn(proc() {
|
||||
let mut stream = TcpStream::connect(addr);
|
||||
stream.write([99]).unwrap();
|
||||
stream.write(&[99]).unwrap();
|
||||
});
|
||||
|
||||
let mut stream = acceptor.accept();
|
||||
let mut buf = [0];
|
||||
stream.read(buf).unwrap();
|
||||
stream.read(&mut buf).unwrap();
|
||||
assert!(buf[0] == 99);
|
||||
}
|
||||
|
||||
|
@ -567,12 +567,12 @@ mod test {
|
|||
|
||||
spawn(proc() {
|
||||
let mut stream = TcpStream::connect(addr);
|
||||
stream.write([99]).unwrap();
|
||||
stream.write(&[99]).unwrap();
|
||||
});
|
||||
|
||||
let mut stream = acceptor.accept();
|
||||
let mut buf = [0];
|
||||
stream.read(buf).unwrap();
|
||||
stream.read(&mut buf).unwrap();
|
||||
assert!(buf[0] == 99);
|
||||
}
|
||||
|
||||
|
@ -588,7 +588,7 @@ mod test {
|
|||
|
||||
let mut stream = acceptor.accept();
|
||||
let mut buf = [0];
|
||||
let nread = stream.read(buf);
|
||||
let nread = stream.read(&mut buf);
|
||||
assert!(nread.is_err());
|
||||
}
|
||||
|
||||
|
@ -604,7 +604,7 @@ mod test {
|
|||
|
||||
let mut stream = acceptor.accept();
|
||||
let mut buf = [0];
|
||||
let nread = stream.read(buf);
|
||||
let nread = stream.read(&mut buf);
|
||||
assert!(nread.is_err());
|
||||
}
|
||||
|
||||
|
@ -620,10 +620,10 @@ mod test {
|
|||
|
||||
let mut stream = acceptor.accept();
|
||||
let mut buf = [0];
|
||||
let nread = stream.read(buf);
|
||||
let nread = stream.read(&mut buf);
|
||||
assert!(nread.is_err());
|
||||
|
||||
match stream.read(buf) {
|
||||
match stream.read(&mut buf) {
|
||||
Ok(..) => panic!(),
|
||||
Err(ref e) => {
|
||||
assert!(e.kind == NotConnected || e.kind == EndOfFile,
|
||||
|
@ -644,10 +644,10 @@ mod test {
|
|||
|
||||
let mut stream = acceptor.accept();
|
||||
let mut buf = [0];
|
||||
let nread = stream.read(buf);
|
||||
let nread = stream.read(&mut buf);
|
||||
assert!(nread.is_err());
|
||||
|
||||
match stream.read(buf) {
|
||||
match stream.read(&mut buf) {
|
||||
Ok(..) => panic!(),
|
||||
Err(ref e) => {
|
||||
assert!(e.kind == NotConnected || e.kind == EndOfFile,
|
||||
|
@ -670,7 +670,7 @@ mod test {
|
|||
let mut stream = acceptor.accept();
|
||||
rx.recv();
|
||||
let buf = [0];
|
||||
match stream.write(buf) {
|
||||
match stream.write(&buf) {
|
||||
Ok(..) => {}
|
||||
Err(e) => {
|
||||
assert!(e.kind == ConnectionReset ||
|
||||
|
@ -695,7 +695,7 @@ mod test {
|
|||
let mut stream = acceptor.accept();
|
||||
rx.recv();
|
||||
let buf = [0];
|
||||
match stream.write(buf) {
|
||||
match stream.write(&buf) {
|
||||
Ok(..) => {}
|
||||
Err(e) => {
|
||||
assert!(e.kind == ConnectionReset ||
|
||||
|
@ -715,13 +715,13 @@ mod test {
|
|||
spawn(proc() {
|
||||
for _ in range(0, max) {
|
||||
let mut stream = TcpStream::connect(addr);
|
||||
stream.write([99]).unwrap();
|
||||
stream.write(&[99]).unwrap();
|
||||
}
|
||||
});
|
||||
|
||||
for ref mut stream in acceptor.incoming().take(max) {
|
||||
let mut buf = [0];
|
||||
stream.read(buf).unwrap();
|
||||
stream.read(&mut buf).unwrap();
|
||||
assert_eq!(buf[0], 99);
|
||||
}
|
||||
}
|
||||
|
@ -735,13 +735,13 @@ mod test {
|
|||
spawn(proc() {
|
||||
for _ in range(0, max) {
|
||||
let mut stream = TcpStream::connect(addr);
|
||||
stream.write([99]).unwrap();
|
||||
stream.write(&[99]).unwrap();
|
||||
}
|
||||
});
|
||||
|
||||
for ref mut stream in acceptor.incoming().take(max) {
|
||||
let mut buf = [0];
|
||||
stream.read(buf).unwrap();
|
||||
stream.read(&mut buf).unwrap();
|
||||
assert_eq!(buf[0], 99);
|
||||
}
|
||||
}
|
||||
|
@ -759,7 +759,7 @@ mod test {
|
|||
spawn(proc() {
|
||||
let mut stream = stream;
|
||||
let mut buf = [0];
|
||||
stream.read(buf).unwrap();
|
||||
stream.read(&mut buf).unwrap();
|
||||
assert!(buf[0] == i as u8);
|
||||
debug!("read");
|
||||
});
|
||||
|
@ -777,7 +777,7 @@ mod test {
|
|||
// Connect again before writing
|
||||
connect(i + 1, addr);
|
||||
debug!("writing");
|
||||
stream.write([i as u8]).unwrap();
|
||||
stream.write(&[i as u8]).unwrap();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -795,7 +795,7 @@ mod test {
|
|||
spawn(proc() {
|
||||
let mut stream = stream;
|
||||
let mut buf = [0];
|
||||
stream.read(buf).unwrap();
|
||||
stream.read(&mut buf).unwrap();
|
||||
assert!(buf[0] == i as u8);
|
||||
debug!("read");
|
||||
});
|
||||
|
@ -813,7 +813,7 @@ mod test {
|
|||
// Connect again before writing
|
||||
connect(i + 1, addr);
|
||||
debug!("writing");
|
||||
stream.write([i as u8]).unwrap();
|
||||
stream.write(&[i as u8]).unwrap();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -831,7 +831,7 @@ mod test {
|
|||
spawn(proc() {
|
||||
let mut stream = stream;
|
||||
let mut buf = [0];
|
||||
stream.read(buf).unwrap();
|
||||
stream.read(&mut buf).unwrap();
|
||||
assert!(buf[0] == 99);
|
||||
debug!("read");
|
||||
});
|
||||
|
@ -849,7 +849,7 @@ mod test {
|
|||
// Connect again before writing
|
||||
connect(i + 1, addr);
|
||||
debug!("writing");
|
||||
stream.write([99]).unwrap();
|
||||
stream.write(&[99]).unwrap();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -867,7 +867,7 @@ mod test {
|
|||
spawn(proc() {
|
||||
let mut stream = stream;
|
||||
let mut buf = [0];
|
||||
stream.read(buf).unwrap();
|
||||
stream.read(&mut buf).unwrap();
|
||||
assert!(buf[0] == 99);
|
||||
debug!("read");
|
||||
});
|
||||
|
@ -885,7 +885,7 @@ mod test {
|
|||
// Connect again before writing
|
||||
connect(i + 1, addr);
|
||||
debug!("writing");
|
||||
stream.write([99]).unwrap();
|
||||
stream.write(&[99]).unwrap();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -941,17 +941,17 @@ mod test {
|
|||
let mut srv = TcpListener::bind(addr).listen().unwrap();
|
||||
tx.send(());
|
||||
let mut cl = srv.accept().unwrap();
|
||||
cl.write([10]).unwrap();
|
||||
cl.write(&[10]).unwrap();
|
||||
let mut b = [0];
|
||||
cl.read(b).unwrap();
|
||||
cl.read(&mut b).unwrap();
|
||||
tx.send(());
|
||||
});
|
||||
|
||||
rx.recv();
|
||||
let mut c = TcpStream::connect(addr).unwrap();
|
||||
let mut b = [0, ..10];
|
||||
assert_eq!(c.read(b), Ok(1));
|
||||
c.write([1]).unwrap();
|
||||
assert_eq!(c.read(&mut b), Ok(1));
|
||||
c.write(&[1]).unwrap();
|
||||
rx.recv();
|
||||
}
|
||||
|
||||
|
@ -1002,9 +1002,9 @@ mod test {
|
|||
spawn(proc() {
|
||||
let mut s = TcpStream::connect(addr);
|
||||
let mut buf = [0, 0];
|
||||
assert_eq!(s.read(buf), Ok(1));
|
||||
assert_eq!(s.read(&mut buf), Ok(1));
|
||||
assert_eq!(buf[0], 1);
|
||||
s.write([2]).unwrap();
|
||||
s.write(&[2]).unwrap();
|
||||
});
|
||||
|
||||
let mut s1 = acceptor.accept().unwrap();
|
||||
|
@ -1015,12 +1015,12 @@ mod test {
|
|||
spawn(proc() {
|
||||
let mut s2 = s2;
|
||||
rx1.recv();
|
||||
s2.write([1]).unwrap();
|
||||
s2.write(&[1]).unwrap();
|
||||
tx2.send(());
|
||||
});
|
||||
tx1.send(());
|
||||
let mut buf = [0, 0];
|
||||
assert_eq!(s1.read(buf), Ok(1));
|
||||
assert_eq!(s1.read(&mut buf), Ok(1));
|
||||
rx2.recv();
|
||||
}
|
||||
|
||||
|
@ -1033,9 +1033,9 @@ mod test {
|
|||
|
||||
spawn(proc() {
|
||||
let mut s = TcpStream::connect(addr);
|
||||
s.write([1]).unwrap();
|
||||
s.write(&[1]).unwrap();
|
||||
rx.recv();
|
||||
s.write([2]).unwrap();
|
||||
s.write(&[2]).unwrap();
|
||||
rx.recv();
|
||||
});
|
||||
|
||||
|
@ -1046,12 +1046,12 @@ mod test {
|
|||
spawn(proc() {
|
||||
let mut s2 = s2;
|
||||
let mut buf = [0, 0];
|
||||
s2.read(buf).unwrap();
|
||||
s2.read(&mut buf).unwrap();
|
||||
tx2.send(());
|
||||
done.send(());
|
||||
});
|
||||
let mut buf = [0, 0];
|
||||
s1.read(buf).unwrap();
|
||||
s1.read(&mut buf).unwrap();
|
||||
tx1.send(());
|
||||
|
||||
rx.recv();
|
||||
|
@ -1065,8 +1065,8 @@ mod test {
|
|||
spawn(proc() {
|
||||
let mut s = TcpStream::connect(addr);
|
||||
let mut buf = [0, 1];
|
||||
s.read(buf).unwrap();
|
||||
s.read(buf).unwrap();
|
||||
s.read(&mut buf).unwrap();
|
||||
s.read(&mut buf).unwrap();
|
||||
});
|
||||
|
||||
let mut s1 = acceptor.accept().unwrap();
|
||||
|
@ -1075,10 +1075,10 @@ mod test {
|
|||
let (done, rx) = channel();
|
||||
spawn(proc() {
|
||||
let mut s2 = s2;
|
||||
s2.write([1]).unwrap();
|
||||
s2.write(&[1]).unwrap();
|
||||
done.send(());
|
||||
});
|
||||
s1.write([2]).unwrap();
|
||||
s1.write(&[2]).unwrap();
|
||||
|
||||
rx.recv();
|
||||
}
|
||||
|
@ -1091,12 +1091,12 @@ mod test {
|
|||
let mut a = a;
|
||||
let mut c = a.accept().unwrap();
|
||||
assert_eq!(c.read_to_end(), Ok(vec!()));
|
||||
c.write([1]).unwrap();
|
||||
c.write(&[1]).unwrap();
|
||||
});
|
||||
|
||||
let mut s = TcpStream::connect(addr).unwrap();
|
||||
assert!(s.inner.close_write().is_ok());
|
||||
assert!(s.write([1]).is_err());
|
||||
assert!(s.write(&[1]).is_err());
|
||||
assert_eq!(s.read_to_end(), Ok(vec!(1)));
|
||||
}
|
||||
|
||||
|
@ -1161,18 +1161,18 @@ mod test {
|
|||
|
||||
// closing should prevent reads/writes
|
||||
s.close_write().unwrap();
|
||||
assert!(s.write([0]).is_err());
|
||||
assert!(s.write(&[0]).is_err());
|
||||
s.close_read().unwrap();
|
||||
assert!(s.read(b).is_err());
|
||||
assert!(s.read(&mut b).is_err());
|
||||
|
||||
// closing should affect previous handles
|
||||
assert!(s2.write([0]).is_err());
|
||||
assert!(s2.read(b).is_err());
|
||||
assert!(s2.write(&[0]).is_err());
|
||||
assert!(s2.read(&mut b).is_err());
|
||||
|
||||
// closing should affect new handles
|
||||
let mut s3 = s.clone();
|
||||
assert!(s3.write([0]).is_err());
|
||||
assert!(s3.read(b).is_err());
|
||||
assert!(s3.write(&[0]).is_err());
|
||||
assert!(s3.read(&mut b).is_err());
|
||||
|
||||
// make sure these don't die
|
||||
let _ = s2.close_read();
|
||||
|
@ -1197,7 +1197,7 @@ mod test {
|
|||
let (tx, rx) = channel();
|
||||
spawn(proc() {
|
||||
let mut s2 = s2;
|
||||
assert!(s2.read([0]).is_err());
|
||||
assert!(s2.read(&mut [0]).is_err());
|
||||
tx.send(());
|
||||
});
|
||||
// this should wake up the child task
|
||||
|
@ -1215,29 +1215,29 @@ mod test {
|
|||
spawn(proc() {
|
||||
let mut s = TcpStream::connect(addr).unwrap();
|
||||
rx.recv();
|
||||
assert!(s.write([0]).is_ok());
|
||||
assert!(s.write(&[0]).is_ok());
|
||||
let _ = rx.recv_opt();
|
||||
});
|
||||
|
||||
let mut s = a.accept().unwrap();
|
||||
s.set_timeout(Some(20));
|
||||
assert_eq!(s.read([0]).err().unwrap().kind, TimedOut);
|
||||
assert_eq!(s.read([0]).err().unwrap().kind, TimedOut);
|
||||
assert_eq!(s.read(&mut [0]).err().unwrap().kind, TimedOut);
|
||||
assert_eq!(s.read(&mut [0]).err().unwrap().kind, TimedOut);
|
||||
|
||||
s.set_timeout(Some(20));
|
||||
for i in range(0i, 1001) {
|
||||
match s.write([0, .. 128 * 1024]) {
|
||||
match s.write(&[0, .. 128 * 1024]) {
|
||||
Ok(()) | Err(IoError { kind: ShortWrite(..), .. }) => {},
|
||||
Err(IoError { kind: TimedOut, .. }) => break,
|
||||
Err(e) => panic!("{}", e),
|
||||
}
|
||||
if i == 1000 { panic!("should have filled up?!"); }
|
||||
}
|
||||
assert_eq!(s.write([0]).err().unwrap().kind, TimedOut);
|
||||
assert_eq!(s.write(&[0]).err().unwrap().kind, TimedOut);
|
||||
|
||||
tx.send(());
|
||||
s.set_timeout(None);
|
||||
assert_eq!(s.read([0, 0]), Ok(1));
|
||||
assert_eq!(s.read(&mut [0, 0]), Ok(1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1250,7 +1250,7 @@ mod test {
|
|||
rx.recv();
|
||||
let mut amt = 0;
|
||||
while amt < 100 * 128 * 1024 {
|
||||
match s.read([0, ..128 * 1024]) {
|
||||
match s.read(&mut [0, ..128 * 1024]) {
|
||||
Ok(n) => { amt += n; }
|
||||
Err(e) => panic!("{}", e),
|
||||
}
|
||||
|
@ -1260,12 +1260,12 @@ mod test {
|
|||
|
||||
let mut s = a.accept().unwrap();
|
||||
s.set_read_timeout(Some(20));
|
||||
assert_eq!(s.read([0]).err().unwrap().kind, TimedOut);
|
||||
assert_eq!(s.read([0]).err().unwrap().kind, TimedOut);
|
||||
assert_eq!(s.read(&mut [0]).err().unwrap().kind, TimedOut);
|
||||
assert_eq!(s.read(&mut [0]).err().unwrap().kind, TimedOut);
|
||||
|
||||
tx.send(());
|
||||
for _ in range(0i, 100) {
|
||||
assert!(s.write([0, ..128 * 1024]).is_ok());
|
||||
assert!(s.write(&[0, ..128 * 1024]).is_ok());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1277,24 +1277,24 @@ mod test {
|
|||
spawn(proc() {
|
||||
let mut s = TcpStream::connect(addr).unwrap();
|
||||
rx.recv();
|
||||
assert!(s.write([0]).is_ok());
|
||||
assert!(s.write(&[0]).is_ok());
|
||||
let _ = rx.recv_opt();
|
||||
});
|
||||
|
||||
let mut s = a.accept().unwrap();
|
||||
s.set_write_timeout(Some(20));
|
||||
for i in range(0i, 1001) {
|
||||
match s.write([0, .. 128 * 1024]) {
|
||||
match s.write(&[0, .. 128 * 1024]) {
|
||||
Ok(()) | Err(IoError { kind: ShortWrite(..), .. }) => {},
|
||||
Err(IoError { kind: TimedOut, .. }) => break,
|
||||
Err(e) => panic!("{}", e),
|
||||
}
|
||||
if i == 1000 { panic!("should have filled up?!"); }
|
||||
}
|
||||
assert_eq!(s.write([0]).err().unwrap().kind, TimedOut);
|
||||
assert_eq!(s.write(&[0]).err().unwrap().kind, TimedOut);
|
||||
|
||||
tx.send(());
|
||||
assert!(s.read([0]).is_ok());
|
||||
assert!(s.read(&mut [0]).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1305,7 +1305,7 @@ mod test {
|
|||
spawn(proc() {
|
||||
let mut s = TcpStream::connect(addr).unwrap();
|
||||
rx.recv();
|
||||
assert_eq!(s.write([0]), Ok(()));
|
||||
assert_eq!(s.write(&[0]), Ok(()));
|
||||
let _ = rx.recv_opt();
|
||||
});
|
||||
|
||||
|
@ -1314,12 +1314,12 @@ mod test {
|
|||
let (tx2, rx2) = channel();
|
||||
spawn(proc() {
|
||||
let mut s2 = s2;
|
||||
assert_eq!(s2.read([0]), Ok(1));
|
||||
assert_eq!(s2.read(&mut [0]), Ok(1));
|
||||
tx2.send(());
|
||||
});
|
||||
|
||||
s.set_read_timeout(Some(20));
|
||||
assert_eq!(s.read([0]).err().unwrap().kind, TimedOut);
|
||||
assert_eq!(s.read(&mut [0]).err().unwrap().kind, TimedOut);
|
||||
tx.send(());
|
||||
|
||||
rx2.recv();
|
||||
|
|
|
@ -44,7 +44,7 @@ use sys::udp::UdpSocket as UdpSocketImp;
|
|||
/// };
|
||||
///
|
||||
/// let mut buf = [0, ..10];
|
||||
/// match socket.recv_from(buf) {
|
||||
/// match socket.recv_from(&mut buf) {
|
||||
/// Ok((amt, src)) => {
|
||||
/// // Send a reply to the socket we received data from
|
||||
/// let buf = buf[mut ..amt];
|
||||
|
@ -266,7 +266,7 @@ mod test {
|
|||
match UdpSocket::bind(client_ip) {
|
||||
Ok(ref mut client) => {
|
||||
rx1.recv();
|
||||
client.send_to([99], server_ip).unwrap()
|
||||
client.send_to(&[99], server_ip).unwrap()
|
||||
}
|
||||
Err(..) => panic!()
|
||||
}
|
||||
|
@ -277,7 +277,7 @@ mod test {
|
|||
Ok(ref mut server) => {
|
||||
tx1.send(());
|
||||
let mut buf = [0];
|
||||
match server.recv_from(buf) {
|
||||
match server.recv_from(&mut buf) {
|
||||
Ok((nread, src)) => {
|
||||
assert_eq!(nread, 1);
|
||||
assert_eq!(buf[0], 99);
|
||||
|
@ -301,7 +301,7 @@ mod test {
|
|||
match UdpSocket::bind(client_ip) {
|
||||
Ok(ref mut client) => {
|
||||
rx.recv();
|
||||
client.send_to([99], server_ip).unwrap()
|
||||
client.send_to(&[99], server_ip).unwrap()
|
||||
}
|
||||
Err(..) => panic!()
|
||||
}
|
||||
|
@ -311,7 +311,7 @@ mod test {
|
|||
Ok(ref mut server) => {
|
||||
tx.send(());
|
||||
let mut buf = [0];
|
||||
match server.recv_from(buf) {
|
||||
match server.recv_from(&mut buf) {
|
||||
Ok((nread, src)) => {
|
||||
assert_eq!(nread, 1);
|
||||
assert_eq!(buf[0], 99);
|
||||
|
@ -345,8 +345,8 @@ mod test {
|
|||
}
|
||||
};
|
||||
rx1.recv();
|
||||
send_as(dummy_ip, [98]);
|
||||
send_as(client_ip, [99]);
|
||||
send_as(dummy_ip, &[98]);
|
||||
send_as(client_ip, &[99]);
|
||||
tx2.send(());
|
||||
});
|
||||
|
||||
|
@ -356,7 +356,7 @@ mod test {
|
|||
let mut stream = server.connect(client_ip);
|
||||
tx1.send(());
|
||||
let mut buf = [0];
|
||||
match stream.read(buf) {
|
||||
match stream.read(&mut buf) {
|
||||
Ok(nread) => {
|
||||
assert_eq!(nread, 1);
|
||||
assert_eq!(buf[0], 99);
|
||||
|
@ -383,7 +383,7 @@ mod test {
|
|||
let client = box client;
|
||||
let mut stream = client.connect(server_ip);
|
||||
rx1.recv();
|
||||
stream.write([99]).unwrap();
|
||||
stream.write(&[99]).unwrap();
|
||||
}
|
||||
Err(..) => panic!()
|
||||
}
|
||||
|
@ -396,7 +396,7 @@ mod test {
|
|||
let mut stream = server.connect(client_ip);
|
||||
tx1.send(());
|
||||
let mut buf = [0];
|
||||
match stream.read(buf) {
|
||||
match stream.read(&mut buf) {
|
||||
Ok(nread) => {
|
||||
assert_eq!(nread, 1);
|
||||
assert_eq!(buf[0], 99);
|
||||
|
@ -442,9 +442,9 @@ mod test {
|
|||
spawn(proc() {
|
||||
let mut sock2 = sock2;
|
||||
let mut buf = [0, 0];
|
||||
assert_eq!(sock2.recv_from(buf), Ok((1, addr1)));
|
||||
assert_eq!(sock2.recv_from(&mut buf), Ok((1, addr1)));
|
||||
assert_eq!(buf[0], 1);
|
||||
sock2.send_to([2], addr1).unwrap();
|
||||
sock2.send_to(&[2], addr1).unwrap();
|
||||
});
|
||||
|
||||
let sock3 = sock1.clone();
|
||||
|
@ -454,12 +454,12 @@ mod test {
|
|||
spawn(proc() {
|
||||
let mut sock3 = sock3;
|
||||
rx1.recv();
|
||||
sock3.send_to([1], addr2).unwrap();
|
||||
sock3.send_to(&[1], addr2).unwrap();
|
||||
tx2.send(());
|
||||
});
|
||||
tx1.send(());
|
||||
let mut buf = [0, 0];
|
||||
assert_eq!(sock1.recv_from(buf), Ok((1, addr2)));
|
||||
assert_eq!(sock1.recv_from(&mut buf), Ok((1, addr2)));
|
||||
rx2.recv();
|
||||
}
|
||||
|
||||
|
@ -474,9 +474,9 @@ mod test {
|
|||
|
||||
spawn(proc() {
|
||||
let mut sock2 = sock2;
|
||||
sock2.send_to([1], addr1).unwrap();
|
||||
sock2.send_to(&[1], addr1).unwrap();
|
||||
rx.recv();
|
||||
sock2.send_to([2], addr1).unwrap();
|
||||
sock2.send_to(&[2], addr1).unwrap();
|
||||
rx.recv();
|
||||
});
|
||||
|
||||
|
@ -486,12 +486,12 @@ mod test {
|
|||
spawn(proc() {
|
||||
let mut sock3 = sock3;
|
||||
let mut buf = [0, 0];
|
||||
sock3.recv_from(buf).unwrap();
|
||||
sock3.recv_from(&mut buf).unwrap();
|
||||
tx2.send(());
|
||||
done.send(());
|
||||
});
|
||||
let mut buf = [0, 0];
|
||||
sock1.recv_from(buf).unwrap();
|
||||
sock1.recv_from(&mut buf).unwrap();
|
||||
tx1.send(());
|
||||
|
||||
rx.recv();
|
||||
|
@ -512,7 +512,7 @@ mod test {
|
|||
let mut buf = [0, 1];
|
||||
|
||||
rx.recv();
|
||||
match sock2.recv_from(buf) {
|
||||
match sock2.recv_from(&mut buf) {
|
||||
Ok(..) => {}
|
||||
Err(e) => panic!("failed receive: {}", e),
|
||||
}
|
||||
|
@ -525,13 +525,13 @@ mod test {
|
|||
let tx2 = tx.clone();
|
||||
spawn(proc() {
|
||||
let mut sock3 = sock3;
|
||||
match sock3.send_to([1], addr2) {
|
||||
match sock3.send_to(&[1], addr2) {
|
||||
Ok(..) => { let _ = tx2.send_opt(()); }
|
||||
Err(..) => {}
|
||||
}
|
||||
done.send(());
|
||||
});
|
||||
match sock1.send_to([2], addr2) {
|
||||
match sock1.send_to(&[2], addr2) {
|
||||
Ok(..) => { let _ = tx.send_opt(()); }
|
||||
Err(..) => {}
|
||||
}
|
||||
|
@ -552,28 +552,28 @@ mod test {
|
|||
let (tx2, rx2) = channel();
|
||||
spawn(proc() {
|
||||
let mut a = UdpSocket::bind(addr2).unwrap();
|
||||
assert_eq!(a.recv_from([0]), Ok((1, addr1)));
|
||||
assert_eq!(a.send_to([0], addr1), Ok(()));
|
||||
assert_eq!(a.recv_from(&mut [0]), Ok((1, addr1)));
|
||||
assert_eq!(a.send_to(&[0], addr1), Ok(()));
|
||||
rx.recv();
|
||||
assert_eq!(a.send_to([0], addr1), Ok(()));
|
||||
assert_eq!(a.send_to(&[0], addr1), Ok(()));
|
||||
|
||||
tx2.send(());
|
||||
});
|
||||
|
||||
// Make sure that reads time out, but writes can continue
|
||||
a.set_read_timeout(Some(20));
|
||||
assert_eq!(a.recv_from([0]).err().unwrap().kind, TimedOut);
|
||||
assert_eq!(a.recv_from([0]).err().unwrap().kind, TimedOut);
|
||||
assert_eq!(a.send_to([0], addr2), Ok(()));
|
||||
assert_eq!(a.recv_from(&mut [0]).err().unwrap().kind, TimedOut);
|
||||
assert_eq!(a.recv_from(&mut [0]).err().unwrap().kind, TimedOut);
|
||||
assert_eq!(a.send_to(&[0], addr2), Ok(()));
|
||||
|
||||
// Cloned handles should be able to block
|
||||
let mut a2 = a.clone();
|
||||
assert_eq!(a2.recv_from([0]), Ok((1, addr2)));
|
||||
assert_eq!(a2.recv_from(&mut [0]), Ok((1, addr2)));
|
||||
|
||||
// Clearing the timeout should allow for receiving
|
||||
a.set_timeout(None);
|
||||
tx.send(());
|
||||
assert_eq!(a2.recv_from([0]), Ok((1, addr2)));
|
||||
assert_eq!(a2.recv_from(&mut [0]), Ok((1, addr2)));
|
||||
|
||||
// Make sure the child didn't die
|
||||
rx2.recv();
|
||||
|
@ -588,7 +588,7 @@ mod test {
|
|||
|
||||
a.set_write_timeout(Some(1000));
|
||||
for _ in range(0u, 100) {
|
||||
match a.send_to([0, ..4*1024], addr2) {
|
||||
match a.send_to(&[0, ..4*1024], addr2) {
|
||||
Ok(()) | Err(IoError { kind: ShortWrite(..), .. }) => {},
|
||||
Err(IoError { kind: TimedOut, .. }) => break,
|
||||
Err(e) => panic!("other error: {}", e),
|
||||
|
|
|
@ -125,12 +125,12 @@ mod test {
|
|||
let (tx, rx) = channel();
|
||||
spawn(proc() {
|
||||
let mut out = out;
|
||||
out.write([10]).unwrap();
|
||||
out.write(&[10]).unwrap();
|
||||
rx.recv(); // don't close the pipe until the other read has finished
|
||||
});
|
||||
|
||||
let mut buf = [0, ..10];
|
||||
input.read(buf).unwrap();
|
||||
input.read(&mut buf).unwrap();
|
||||
tx.send(());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ mod test {
|
|||
#[test]
|
||||
fn test_option_writer() {
|
||||
let mut writer: io::IoResult<MemWriter> = Ok(MemWriter::new());
|
||||
writer.write([0, 1, 2]).unwrap();
|
||||
writer.write(&[0, 1, 2]).unwrap();
|
||||
writer.flush().unwrap();
|
||||
assert_eq!(writer.unwrap().unwrap(), vec!(0, 1, 2));
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ mod test {
|
|||
let mut writer: io::IoResult<MemWriter> =
|
||||
Err(io::standard_error(io::EndOfFile));
|
||||
|
||||
match writer.write([0, 0, 0]) {
|
||||
match writer.write(&[0, 0, 0]) {
|
||||
Ok(..) => panic!(),
|
||||
Err(e) => assert_eq!(e.kind, io::EndOfFile),
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ mod test {
|
|||
let mut reader: io::IoResult<MemReader> =
|
||||
Ok(MemReader::new(vec!(0, 1, 2, 3)));
|
||||
let mut buf = [0, 0];
|
||||
reader.read(buf).unwrap();
|
||||
reader.read(&mut buf).unwrap();
|
||||
let b: &[_] = &[0, 1];
|
||||
assert_eq!(buf.as_slice(), b);
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ mod test {
|
|||
Err(io::standard_error(io::EndOfFile));
|
||||
let mut buf = [];
|
||||
|
||||
match reader.read(buf) {
|
||||
match reader.read(&mut buf) {
|
||||
Ok(..) => panic!(),
|
||||
Err(e) => assert_eq!(e.kind, io::EndOfFile),
|
||||
}
|
||||
|
|
|
@ -237,7 +237,7 @@ pub fn print(s: &str) {
|
|||
/// `\n` character is printed to the console after the string.
|
||||
pub fn println(s: &str) {
|
||||
with_task_stdout(|io| {
|
||||
io.write(s.as_bytes()).and_then(|()| io.write([b'\n']))
|
||||
io.write(s.as_bytes()).and_then(|()| io.write(&[b'\n']))
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -225,7 +225,7 @@ impl<R: Reader, W: Writer> Reader for TeeReader<R, W> {
|
|||
pub fn copy<R: Reader, W: Writer>(r: &mut R, w: &mut W) -> io::IoResult<()> {
|
||||
let mut buf = [0, ..super::DEFAULT_BUF_SIZE];
|
||||
loop {
|
||||
let len = match r.read(buf) {
|
||||
let len = match r.read(&mut buf) {
|
||||
Ok(len) => len,
|
||||
Err(ref e) if e.kind == io::EndOfFile => return Ok(()),
|
||||
Err(e) => return Err(e),
|
||||
|
@ -352,7 +352,7 @@ mod test {
|
|||
|
||||
let mut multi = MultiWriter::new(vec!(box TestWriter as Box<Writer>,
|
||||
box TestWriter as Box<Writer>));
|
||||
multi.write([1, 2, 3]).unwrap();
|
||||
multi.write(&[1, 2, 3]).unwrap();
|
||||
assert_eq!(2, unsafe { writes });
|
||||
assert_eq!(0, unsafe { flushes });
|
||||
multi.flush().unwrap();
|
||||
|
@ -413,25 +413,25 @@ mod test {
|
|||
fn test_iter_reader() {
|
||||
let mut r = IterReader::new(range(0u8, 8));
|
||||
let mut buf = [0, 0, 0];
|
||||
let len = r.read(buf).unwrap();
|
||||
let len = r.read(&mut buf).unwrap();
|
||||
assert_eq!(len, 3);
|
||||
assert!(buf == [0, 1, 2]);
|
||||
|
||||
let len = r.read(buf).unwrap();
|
||||
let len = r.read(&mut buf).unwrap();
|
||||
assert_eq!(len, 3);
|
||||
assert!(buf == [3, 4, 5]);
|
||||
|
||||
let len = r.read(buf).unwrap();
|
||||
let len = r.read(&mut buf).unwrap();
|
||||
assert_eq!(len, 2);
|
||||
assert!(buf == [6, 7, 5]);
|
||||
|
||||
assert_eq!(r.read(buf).unwrap_err().kind, io::EndOfFile);
|
||||
assert_eq!(r.read(&mut buf).unwrap_err().kind, io::EndOfFile);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn iter_reader_zero_length() {
|
||||
let mut r = IterReader::new(range(0u8, 8));
|
||||
let mut buf = [];
|
||||
assert_eq!(Ok(0), r.read(buf));
|
||||
assert_eq!(Ok(0), r.read(&mut buf));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ pub fn to_str_bytes<U>(n: $T, radix: uint, f: |v: &[u8]| -> U) -> U {
|
|||
// base 2 number, and then we need another for a possible '-' character.
|
||||
let mut buf = [0u8, ..65];
|
||||
let amt = {
|
||||
let mut wr = ::io::BufWriter::new(buf);
|
||||
let mut wr = ::io::BufWriter::new(&mut buf);
|
||||
(write!(&mut wr, "{}", ::fmt::radix(n, radix as u8))).unwrap();
|
||||
wr.tell().unwrap() as uint
|
||||
};
|
||||
|
|
|
@ -1936,7 +1936,7 @@ mod tests {
|
|||
fn memory_map_rw() {
|
||||
use result::{Ok, Err};
|
||||
|
||||
let chunk = match os::MemoryMap::new(16, [
|
||||
let chunk = match os::MemoryMap::new(16, &[
|
||||
os::MapReadable,
|
||||
os::MapWritable
|
||||
]) {
|
||||
|
@ -1983,7 +1983,7 @@ mod tests {
|
|||
"x".with_c_str(|x| assert!(write(fd, x as *const c_void, 1) == 1));
|
||||
fd
|
||||
};
|
||||
let chunk = match MemoryMap::new(size / 2, [
|
||||
let chunk = match MemoryMap::new(size / 2, &[
|
||||
MapReadable,
|
||||
MapWritable,
|
||||
MapFd(fd),
|
||||
|
@ -2012,16 +2012,16 @@ mod tests {
|
|||
parsed.iter().map(|s| Path::new(*s)).collect()
|
||||
}
|
||||
|
||||
assert!(check_parse("", [""]));
|
||||
assert!(check_parse(r#""""#, [""]));
|
||||
assert!(check_parse(";;", ["", "", ""]));
|
||||
assert!(check_parse(r"c:\", [r"c:\"]));
|
||||
assert!(check_parse(r"c:\;", [r"c:\", ""]));
|
||||
assert!(check_parse("", &mut [""]));
|
||||
assert!(check_parse(r#""""#, &mut [""]));
|
||||
assert!(check_parse(";;", &mut ["", "", ""]));
|
||||
assert!(check_parse(r"c:\", &mut [r"c:\"]));
|
||||
assert!(check_parse(r"c:\;", &mut [r"c:\", ""]));
|
||||
assert!(check_parse(r"c:\;c:\Program Files\",
|
||||
[r"c:\", r"c:\Program Files\"]));
|
||||
assert!(check_parse(r#"c:\;c:\"foo"\"#, [r"c:\", r"c:\foo\"]));
|
||||
&mut [r"c:\", r"c:\Program Files\"]));
|
||||
assert!(check_parse(r#"c:\;c:\"foo"\"#, &mut [r"c:\", r"c:\foo\"]));
|
||||
assert!(check_parse(r#"c:\;c:\"foo;bar"\;c:\baz"#,
|
||||
[r"c:\", r"c:\foo;bar\", r"c:\baz"]));
|
||||
&mut [r"c:\", r"c:\foo;bar\", r"c:\baz"]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2032,11 +2032,11 @@ mod tests {
|
|||
parsed.iter().map(|s| Path::new(*s)).collect()
|
||||
}
|
||||
|
||||
assert!(check_parse("", [""]));
|
||||
assert!(check_parse("::", ["", "", ""]));
|
||||
assert!(check_parse("/", ["/"]));
|
||||
assert!(check_parse("/:", ["/", ""]));
|
||||
assert!(check_parse("/:/usr/local", ["/", "/usr/local"]));
|
||||
assert!(check_parse("", &mut [""]));
|
||||
assert!(check_parse("::", &mut ["", "", ""]));
|
||||
assert!(check_parse("/", &mut ["/"]));
|
||||
assert!(check_parse("/:", &mut ["/", ""]));
|
||||
assert!(check_parse("/:/usr/local", &mut ["/", "/usr/local"]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2046,12 +2046,12 @@ mod tests {
|
|||
join_paths(input).unwrap().as_slice() == output.as_bytes()
|
||||
}
|
||||
|
||||
assert!(test_eq([], ""));
|
||||
assert!(test_eq(["/bin", "/usr/bin", "/usr/local/bin"],
|
||||
"/bin:/usr/bin:/usr/local/bin"));
|
||||
assert!(test_eq(["", "/bin", "", "", "/usr/bin", ""],
|
||||
":/bin:::/usr/bin:"));
|
||||
assert!(join_paths(["/te:st"]).is_err());
|
||||
assert!(test_eq(&[], ""));
|
||||
assert!(test_eq(&["/bin", "/usr/bin", "/usr/local/bin"],
|
||||
"/bin:/usr/bin:/usr/local/bin"));
|
||||
assert!(test_eq(&["", "/bin", "", "", "/usr/bin", ""],
|
||||
":/bin:::/usr/bin:"));
|
||||
assert!(join_paths(&["/te:st"]).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2068,7 +2068,7 @@ mod tests {
|
|||
r";c:\windows;;;c:\;"));
|
||||
assert!(test_eq([r"c:\te;st", r"c:\"],
|
||||
r#""c:\te;st";c:\"#));
|
||||
assert!(join_paths([r#"c:\te"st"#]).is_err());
|
||||
assert!(join_paths(&[r#"c:\te"st"#]).is_err());
|
||||
}
|
||||
|
||||
// More recursive_mkdir tests are in extra::tempfile
|
||||
|
|
|
@ -462,7 +462,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_paths() {
|
||||
let empty: &[u8] = [];
|
||||
let empty: &[u8] = &[];
|
||||
t!(v: Path::new(empty), b".");
|
||||
t!(v: Path::new(b"/"), b"/");
|
||||
t!(v: Path::new(b"a/b/c"), b"a/b/c");
|
||||
|
@ -731,14 +731,14 @@ mod tests {
|
|||
(s: $path:expr, $push:expr, $exp:expr) => (
|
||||
{
|
||||
let mut p = Path::new($path);
|
||||
p.push_many($push);
|
||||
p.push_many(&$push);
|
||||
assert!(p.as_str() == Some($exp));
|
||||
}
|
||||
);
|
||||
(v: $path:expr, $push:expr, $exp:expr) => (
|
||||
{
|
||||
let mut p = Path::new($path);
|
||||
p.push_many($push);
|
||||
p.push_many(&$push);
|
||||
assert!(p.as_vec() == $exp);
|
||||
}
|
||||
)
|
||||
|
@ -836,14 +836,14 @@ mod tests {
|
|||
(s: $path:expr, $join:expr, $exp:expr) => (
|
||||
{
|
||||
let path = Path::new($path);
|
||||
let res = path.join_many($join);
|
||||
let res = path.join_many(&$join);
|
||||
assert!(res.as_str() == Some($exp));
|
||||
}
|
||||
);
|
||||
(v: $path:expr, $join:expr, $exp:expr) => (
|
||||
{
|
||||
let path = Path::new($path);
|
||||
let res = path.join_many($join);
|
||||
let res = path.join_many(&$join);
|
||||
assert!(res.as_vec() == $exp);
|
||||
}
|
||||
)
|
||||
|
@ -859,7 +859,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_with_helpers() {
|
||||
let empty: &[u8] = [];
|
||||
let empty: &[u8] = &[];
|
||||
|
||||
t!(v: Path::new(b"a/b/c").with_filename(b"d"), b"a/b/d");
|
||||
t!(v: Path::new(b"a/b/c\xFF").with_filename(b"\x80"), b"a/b/\x80");
|
||||
|
@ -1173,7 +1173,7 @@ mod tests {
|
|||
{
|
||||
let path = Path::new($path);
|
||||
let comps = path.components().collect::<Vec<&[u8]>>();
|
||||
let exp: &[&str] = $exp;
|
||||
let exp: &[&str] = &$exp;
|
||||
let exps = exp.iter().map(|x| x.as_bytes()).collect::<Vec<&[u8]>>();
|
||||
assert!(comps == exps, "components: Expected {}, found {}",
|
||||
comps, exps);
|
||||
|
@ -1187,7 +1187,7 @@ mod tests {
|
|||
{
|
||||
let path = Path::new($arg);
|
||||
let comps = path.components().collect::<Vec<&[u8]>>();
|
||||
let exp: &[&[u8]] = [$($exp),*];
|
||||
let exp: &[&[u8]] = &[$($exp),*];
|
||||
assert_eq!(comps.as_slice(), exp);
|
||||
let comps = path.components().rev().collect::<Vec<&[u8]>>();
|
||||
let exp = exp.iter().rev().map(|&x|x).collect::<Vec<&[u8]>>();
|
||||
|
@ -1219,7 +1219,7 @@ mod tests {
|
|||
{
|
||||
let path = Path::new($arg);
|
||||
let comps = path.str_components().collect::<Vec<Option<&str>>>();
|
||||
let exp: &[Option<&str>] = $exp;
|
||||
let exp: &[Option<&str>] = &$exp;
|
||||
assert_eq!(comps.as_slice(), exp);
|
||||
let comps = path.str_components().rev().collect::<Vec<Option<&str>>>();
|
||||
let exp = exp.iter().rev().map(|&x|x).collect::<Vec<Option<&str>>>();
|
||||
|
|
|
@ -1195,7 +1195,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_paths() {
|
||||
let empty: &[u8] = [];
|
||||
let empty: &[u8] = &[];
|
||||
t!(v: Path::new(empty), b".");
|
||||
t!(v: Path::new(b"\\"), b"\\");
|
||||
t!(v: Path::new(b"a\\b\\c"), b"a\\b\\c");
|
||||
|
@ -1571,14 +1571,14 @@ mod tests {
|
|||
(s: $path:expr, $push:expr, $exp:expr) => (
|
||||
{
|
||||
let mut p = Path::new($path);
|
||||
p.push_many($push);
|
||||
p.push_many(&$push);
|
||||
assert_eq!(p.as_str(), Some($exp));
|
||||
}
|
||||
);
|
||||
(v: $path:expr, $push:expr, $exp:expr) => (
|
||||
{
|
||||
let mut p = Path::new($path);
|
||||
p.push_many($push);
|
||||
p.push_many(&$push);
|
||||
assert_eq!(p.as_vec(), $exp);
|
||||
}
|
||||
)
|
||||
|
@ -1712,14 +1712,14 @@ mod tests {
|
|||
(s: $path:expr, $join:expr, $exp:expr) => (
|
||||
{
|
||||
let path = Path::new($path);
|
||||
let res = path.join_many($join);
|
||||
let res = path.join_many(&$join);
|
||||
assert_eq!(res.as_str(), Some($exp));
|
||||
}
|
||||
);
|
||||
(v: $path:expr, $join:expr, $exp:expr) => (
|
||||
{
|
||||
let path = Path::new($path);
|
||||
let res = path.join_many($join);
|
||||
let res = path.join_many(&$join);
|
||||
assert_eq!(res.as_vec(), $exp);
|
||||
}
|
||||
)
|
||||
|
@ -2252,7 +2252,7 @@ mod tests {
|
|||
let path = Path::new($path);
|
||||
let comps = path.str_components().map(|x|x.unwrap())
|
||||
.collect::<Vec<&str>>();
|
||||
let exp: &[&str] = $exp;
|
||||
let exp: &[&str] = &$exp;
|
||||
assert_eq!(comps.as_slice(), exp);
|
||||
let comps = path.str_components().rev().map(|x|x.unwrap())
|
||||
.collect::<Vec<&str>>();
|
||||
|
@ -2309,7 +2309,7 @@ mod tests {
|
|||
{
|
||||
let path = Path::new($path);
|
||||
let comps = path.components().collect::<Vec<&[u8]>>();
|
||||
let exp: &[&[u8]] = $exp;
|
||||
let exp: &[&[u8]] = &$exp;
|
||||
assert_eq!(comps.as_slice(), exp);
|
||||
let comps = path.components().rev().collect::<Vec<&[u8]>>();
|
||||
let exp = exp.iter().rev().map(|&x|x).collect::<Vec<&[u8]>>();
|
||||
|
|
|
@ -522,7 +522,7 @@ mod test {
|
|||
#[test]
|
||||
fn test_choose() {
|
||||
let mut r = task_rng();
|
||||
assert_eq!(r.choose([1i, 1, 1]).map(|&x|x), Some(1));
|
||||
assert_eq!(r.choose(&[1i, 1, 1]).map(|&x|x), Some(1));
|
||||
|
||||
let v: &[int] = &[];
|
||||
assert_eq!(r.choose(v), None);
|
||||
|
@ -534,16 +534,16 @@ mod test {
|
|||
let empty: &mut [int] = &mut [];
|
||||
r.shuffle(empty);
|
||||
let mut one = [1i];
|
||||
r.shuffle(one);
|
||||
r.shuffle(&mut one);
|
||||
let b: &[_] = &[1];
|
||||
assert_eq!(one.as_slice(), b);
|
||||
|
||||
let mut two = [1i, 2];
|
||||
r.shuffle(two);
|
||||
r.shuffle(&mut two);
|
||||
assert!(two == [1, 2] || two == [2, 1]);
|
||||
|
||||
let mut x = [1i, 1, 1];
|
||||
r.shuffle(x);
|
||||
r.shuffle(&mut x);
|
||||
let b: &[_] = &[1, 1, 1];
|
||||
assert_eq!(x.as_slice(), b);
|
||||
}
|
||||
|
@ -553,7 +553,7 @@ mod test {
|
|||
let mut r = task_rng();
|
||||
r.gen::<int>();
|
||||
let mut v = [1i, 1, 1];
|
||||
r.shuffle(v);
|
||||
r.shuffle(&mut v);
|
||||
let b: &[_] = &[1, 1, 1];
|
||||
assert_eq!(v.as_slice(), b);
|
||||
assert_eq!(r.gen_range(0u, 1u), 0u);
|
||||
|
@ -673,7 +673,7 @@ mod bench {
|
|||
#[bench]
|
||||
fn rand_shuffle_100(b: &mut Bencher) {
|
||||
let mut rng = weak_rng();
|
||||
let x : &mut[uint] = [1,..100];
|
||||
let x : &mut[uint] = &mut [1,..100];
|
||||
b.iter(|| {
|
||||
rng.shuffle(x);
|
||||
})
|
||||
|
|
|
@ -343,7 +343,7 @@ mod test {
|
|||
r.next_u64();
|
||||
|
||||
let mut v = [0u8, .. 1000];
|
||||
r.fill_bytes(v);
|
||||
r.fill_bytes(&mut v);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -368,7 +368,7 @@ mod test {
|
|||
task::deschedule();
|
||||
r.next_u64();
|
||||
task::deschedule();
|
||||
r.fill_bytes(v);
|
||||
r.fill_bytes(&mut v);
|
||||
task::deschedule();
|
||||
}
|
||||
})
|
||||
|
|
|
@ -108,7 +108,7 @@ mod test {
|
|||
let mut w = [0u8, .. 8];
|
||||
|
||||
let mut rng = ReaderRng::new(MemReader::new(v.as_slice().to_vec()));
|
||||
rng.fill_bytes(w);
|
||||
rng.fill_bytes(&mut w);
|
||||
|
||||
assert!(v == w);
|
||||
}
|
||||
|
@ -118,6 +118,6 @@ mod test {
|
|||
fn test_reader_rng_insufficient_bytes() {
|
||||
let mut rng = ReaderRng::new(MemReader::new(vec!()));
|
||||
let mut v = [0u8, .. 3];
|
||||
rng.fill_bytes(v);
|
||||
rng.fill_bytes(&mut v);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -527,7 +527,7 @@ mod imp {
|
|||
Some(string) => try!(super::demangle(w, string)),
|
||||
None => try!(write!(w, "<unknown>")),
|
||||
}
|
||||
w.write(['\n' as u8])
|
||||
w.write(&['\n' as u8])
|
||||
}
|
||||
|
||||
/// Unwind library interface used for backtraces
|
||||
|
|
|
@ -359,7 +359,7 @@ pub fn read<T>(fd: sock_t,
|
|||
// With a timeout, first we wait for the socket to become
|
||||
// readable using select(), specifying the relevant timeout for
|
||||
// our previously set deadline.
|
||||
try!(await([fd], deadline, Readable));
|
||||
try!(await(&[fd], deadline, Readable));
|
||||
|
||||
// At this point, we're still within the timeout, and we've
|
||||
// determined that the socket is readable (as returned by
|
||||
|
@ -411,7 +411,7 @@ pub fn write<T>(fd: sock_t,
|
|||
while written < buf.len() && (write_everything || written == 0) {
|
||||
// As with read(), first wait for the socket to be ready for
|
||||
// the I/O operation.
|
||||
match await([fd], deadline, Writable) {
|
||||
match await(&[fd], deadline, Writable) {
|
||||
Err(ref e) if e.kind == io::EndOfFile && written > 0 => {
|
||||
assert!(deadline.is_some());
|
||||
return Err(short_write(written, "short write"))
|
||||
|
|
|
@ -376,7 +376,7 @@ mod tests {
|
|||
|
||||
writer.write(b"test").ok().unwrap();
|
||||
let mut buf = [0u8, ..4];
|
||||
match reader.read(buf) {
|
||||
match reader.read(&mut buf) {
|
||||
Ok(4) => {
|
||||
assert_eq!(buf[0], 't' as u8);
|
||||
assert_eq!(buf[1], 'e' as u8);
|
||||
|
@ -386,7 +386,7 @@ mod tests {
|
|||
r => panic!("invalid read: {}", r),
|
||||
}
|
||||
|
||||
assert!(writer.read(buf).is_err());
|
||||
assert!(reader.write(buf).is_err());
|
||||
assert!(writer.read(&mut buf).is_err());
|
||||
assert!(reader.write(&buf).is_err());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ pub fn new() -> (signal, signal) {
|
|||
}
|
||||
|
||||
pub fn signal(fd: libc::c_int) {
|
||||
FileDesc::new(fd, false).write([0]).ok().unwrap();
|
||||
FileDesc::new(fd, false).write(&[0]).ok().unwrap();
|
||||
}
|
||||
|
||||
pub fn close(fd: libc::c_int) {
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue