mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
librustc: Disallow multiple patterns from appearing in a "let" declaration.
You can still initialize multiple variables at once with "let (x, y) = (1, 2)".
This commit is contained in:
parent
16086ecff7
commit
8114d0e950
@ -2325,7 +2325,9 @@ An example of a for loop over the contents of a vector:
|
|||||||
~~~~
|
~~~~
|
||||||
# type foo = int;
|
# type foo = int;
|
||||||
# fn bar(f: foo) { }
|
# fn bar(f: foo) { }
|
||||||
# let a = 0, b = 0, c = 0;
|
# let a = 0;
|
||||||
|
# let b = 0;
|
||||||
|
# let c = 0;
|
||||||
|
|
||||||
let v: &[foo] = &[a, b, c];
|
let v: &[foo] = &[a, b, c];
|
||||||
|
|
||||||
@ -3000,7 +3002,7 @@ allocated within the stack's memory. The value is a part of the stack frame.
|
|||||||
|
|
||||||
Local variables are immutable unless declared with `let mut`. The
|
Local variables are immutable unless declared with `let mut`. The
|
||||||
`mut` keyword applies to all local variables declared within that
|
`mut` keyword applies to all local variables declared within that
|
||||||
declaration (so `let mut x, y` declares two mutable variables, `x` and
|
declaration (so `let mut (x, y) = ...` declares two mutable variables, `x` and
|
||||||
`y`).
|
`y`).
|
||||||
|
|
||||||
Function parameters are immutable unless declared with `mut`. The
|
Function parameters are immutable unless declared with `mut`. The
|
||||||
|
@ -159,8 +159,8 @@ pub struct Unique<T> {
|
|||||||
priv ptr: *mut T
|
priv ptr: *mut T
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<T: Owned> Unique<T> {
|
impl<T: Owned> Unique<T> {
|
||||||
fn new(value: T) -> Unique<T> {
|
pub fn new(value: T) -> Unique<T> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr = malloc(std::sys::size_of::<T>() as size_t) as *mut T;
|
let ptr = malloc(std::sys::size_of::<T>() as size_t) as *mut T;
|
||||||
assert!(!ptr::is_null(ptr));
|
assert!(!ptr::is_null(ptr));
|
||||||
@ -171,12 +171,12 @@ pub impl<T: Owned> Unique<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// the 'r lifetime results in the same semantics as `&*x` with ~T
|
// the 'r lifetime results in the same semantics as `&*x` with ~T
|
||||||
fn borrow<'r>(&'r self) -> &'r T {
|
pub fn borrow<'r>(&'r self) -> &'r T {
|
||||||
unsafe { cast::copy_lifetime(self, &*self.ptr) }
|
unsafe { cast::copy_lifetime(self, &*self.ptr) }
|
||||||
}
|
}
|
||||||
|
|
||||||
// the 'r lifetime results in the same semantics as `&mut *x` with ~T
|
// the 'r lifetime results in the same semantics as `&mut *x` with ~T
|
||||||
fn borrow_mut<'r>(&'r mut self) -> &'r mut T {
|
pub fn borrow_mut<'r>(&'r mut self) -> &'r mut T {
|
||||||
unsafe { cast::copy_mut_lifetime(self, &mut *self.ptr) }
|
unsafe { cast::copy_mut_lifetime(self, &mut *self.ptr) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,8 @@ doing nothing otherwise:
|
|||||||
~~~~
|
~~~~
|
||||||
# enum t { special_a(uint), special_b(uint) };
|
# enum t { special_a(uint), special_b(uint) };
|
||||||
# fn f() -> uint {
|
# fn f() -> uint {
|
||||||
# let input_1 = special_a(0), input_2 = special_a(0);
|
# let input_1 = special_a(0);
|
||||||
|
# let input_2 = special_a(0);
|
||||||
match input_1 {
|
match input_1 {
|
||||||
special_a(x) => { return x; }
|
special_a(x) => { return x; }
|
||||||
_ => {}
|
_ => {}
|
||||||
@ -38,7 +39,8 @@ the pattern in the above code:
|
|||||||
~~~~
|
~~~~
|
||||||
# enum t { special_a(uint), special_b(uint) };
|
# enum t { special_a(uint), special_b(uint) };
|
||||||
# fn f() -> uint {
|
# fn f() -> uint {
|
||||||
# let input_1 = special_a(0), input_2 = special_a(0);
|
# let input_1 = special_a(0);
|
||||||
|
# let input_2 = special_a(0);
|
||||||
macro_rules! early_return(
|
macro_rules! early_return(
|
||||||
($inp:expr $sp:ident) => ( // invoke it like `(input_5 special_e)`
|
($inp:expr $sp:ident) => ( // invoke it like `(input_5 special_e)`
|
||||||
match $inp {
|
match $inp {
|
||||||
@ -155,7 +157,8 @@ instead of `*` to mean "at least one".
|
|||||||
~~~~
|
~~~~
|
||||||
# enum t { special_a(uint),special_b(uint),special_c(uint),special_d(uint)};
|
# enum t { special_a(uint),special_b(uint),special_c(uint),special_d(uint)};
|
||||||
# fn f() -> uint {
|
# fn f() -> uint {
|
||||||
# let input_1 = special_a(0), input_2 = special_a(0);
|
# let input_1 = special_a(0);
|
||||||
|
# let input_2 = special_a(0);
|
||||||
macro_rules! early_return(
|
macro_rules! early_return(
|
||||||
($inp:expr, [ $($sp:ident)|+ ]) => (
|
($inp:expr, [ $($sp:ident)|+ ]) => (
|
||||||
match $inp {
|
match $inp {
|
||||||
|
@ -134,7 +134,7 @@ unsafe fn destroy_chunk(chunk: &Chunk) {
|
|||||||
while idx < fill {
|
while idx < fill {
|
||||||
let tydesc_data: *uint = transmute(ptr::offset(buf, idx));
|
let tydesc_data: *uint = transmute(ptr::offset(buf, idx));
|
||||||
let (tydesc, is_done) = un_bitpack_tydesc_ptr(*tydesc_data);
|
let (tydesc, is_done) = un_bitpack_tydesc_ptr(*tydesc_data);
|
||||||
let size = (*tydesc).size, align = (*tydesc).align;
|
let (size, align) = ((*tydesc).size, (*tydesc).align);
|
||||||
|
|
||||||
let after_tydesc = idx + sys::size_of::<*TypeDesc>();
|
let after_tydesc = idx + sys::size_of::<*TypeDesc>();
|
||||||
|
|
||||||
|
@ -194,8 +194,8 @@ impl FileInput {
|
|||||||
arguments. `"-"` represents `stdin`.
|
arguments. `"-"` represents `stdin`.
|
||||||
*/
|
*/
|
||||||
pub fn from_args() -> FileInput {
|
pub fn from_args() -> FileInput {
|
||||||
let args = os::args(),
|
let args = os::args();
|
||||||
pathed = pathify(args.tail(), true);
|
let pathed = pathify(args.tail(), true);
|
||||||
FileInput::from_vec(pathed)
|
FileInput::from_vec(pathed)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,8 +222,8 @@ impl FileInput {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let path_option = self.fi.files.shift(),
|
let path_option = self.fi.files.shift();
|
||||||
file = match path_option {
|
let file = match path_option {
|
||||||
None => io::stdin(),
|
None => io::stdin(),
|
||||||
Some(ref path) => io::file_reader(path).get()
|
Some(ref path) => io::file_reader(path).get()
|
||||||
};
|
};
|
||||||
@ -431,8 +431,8 @@ mod test {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_pathify() {
|
fn test_pathify() {
|
||||||
let strs = [~"some/path",
|
let strs = [~"some/path",
|
||||||
~"some/other/path"],
|
~"some/other/path"];
|
||||||
paths = ~[Some(Path("some/path")),
|
let paths = ~[Some(Path("some/path")),
|
||||||
Some(Path("some/other/path"))];
|
Some(Path("some/other/path"))];
|
||||||
|
|
||||||
assert_eq!(pathify(strs, true), copy paths);
|
assert_eq!(pathify(strs, true), copy paths);
|
||||||
@ -561,8 +561,10 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_no_trailing_newline() {
|
fn test_no_trailing_newline() {
|
||||||
let f1 = Some(Path("tmp/lib-fileinput-test-no-trailing-newline-1.tmp")),
|
let f1 =
|
||||||
f2 = Some(Path("tmp/lib-fileinput-test-no-trailing-newline-2.tmp"));
|
Some(Path("tmp/lib-fileinput-test-no-trailing-newline-1.tmp"));
|
||||||
|
let f2 =
|
||||||
|
Some(Path("tmp/lib-fileinput-test-no-trailing-newline-2.tmp"));
|
||||||
|
|
||||||
let wr = io::file_writer(f1.get_ref(), [io::Create, io::Truncate]).get();
|
let wr = io::file_writer(f1.get_ref(), [io::Create, io::Truncate]).get();
|
||||||
wr.write_str("1\n2");
|
wr.write_str("1\n2");
|
||||||
|
@ -58,9 +58,9 @@ pub fn md4(msg: &[u8]) -> Quad {
|
|||||||
let e = msg.len();
|
let e = msg.len();
|
||||||
let mut x = vec::from_elem(16u, 0u32);
|
let mut x = vec::from_elem(16u, 0u32);
|
||||||
while i < e {
|
while i < e {
|
||||||
let aa = a, bb = b, cc = c, dd = d;
|
let (aa, bb, cc, dd) = (a, b, c, d);
|
||||||
|
|
||||||
let mut j = 0u, base = i;
|
let mut (j, base) = (0u, i);
|
||||||
while j < 16u {
|
while j < 16u {
|
||||||
x[j] = (msg[base] as u32) + (msg[base + 1u] as u32 << 8u32) +
|
x[j] = (msg[base] as u32) + (msg[base + 1u] as u32 << 8u32) +
|
||||||
(msg[base + 2u] as u32 << 16u32) +
|
(msg[base + 2u] as u32 << 16u32) +
|
||||||
|
@ -416,7 +416,7 @@ fn get_authority(rawurl: &str) ->
|
|||||||
let mut port = None;
|
let mut port = None;
|
||||||
|
|
||||||
let mut colon_count = 0;
|
let mut colon_count = 0;
|
||||||
let mut pos = 0, begin = 2, end = len;
|
let mut (pos, begin, end) = (0, 2, len);
|
||||||
|
|
||||||
for str::each_chari(rawurl) |i,c| {
|
for str::each_chari(rawurl) |i,c| {
|
||||||
if i < 2 { loop; } // ignore the leading //
|
if i < 2 { loop; } // ignore the leading //
|
||||||
|
@ -125,7 +125,7 @@ impl Ord for BigUint {
|
|||||||
impl TotalOrd for BigUint {
|
impl TotalOrd for BigUint {
|
||||||
|
|
||||||
fn cmp(&self, other: &BigUint) -> Ordering {
|
fn cmp(&self, other: &BigUint) -> Ordering {
|
||||||
let s_len = self.data.len(), o_len = other.data.len();
|
let (s_len, o_len) = (self.data.len(), other.data.len());
|
||||||
if s_len < o_len { return Less; }
|
if s_len < o_len { return Less; }
|
||||||
if s_len > o_len { return Greater; }
|
if s_len > o_len { return Greater; }
|
||||||
|
|
||||||
@ -255,7 +255,7 @@ impl Mul<BigUint, BigUint> for BigUint {
|
|||||||
fn mul(&self, other: &BigUint) -> BigUint {
|
fn mul(&self, other: &BigUint) -> BigUint {
|
||||||
if self.is_zero() || other.is_zero() { return Zero::zero(); }
|
if self.is_zero() || other.is_zero() { return Zero::zero(); }
|
||||||
|
|
||||||
let s_len = self.data.len(), o_len = other.data.len();
|
let (s_len, o_len) = (self.data.len(), other.data.len());
|
||||||
if s_len == 1 { return mul_digit(other, self.data[0]); }
|
if s_len == 1 { return mul_digit(other, self.data[0]); }
|
||||||
if o_len == 1 { return mul_digit(self, other.data[0]); }
|
if o_len == 1 { return mul_digit(self, other.data[0]); }
|
||||||
|
|
||||||
@ -447,7 +447,7 @@ impl Integer for BigUint {
|
|||||||
|
|
||||||
fn gcd(&self, other: &BigUint) -> BigUint {
|
fn gcd(&self, other: &BigUint) -> BigUint {
|
||||||
// Use Euclid's algorithm
|
// Use Euclid's algorithm
|
||||||
let mut m = copy *self, n = copy *other;
|
let mut (m, n) = (copy *self, copy *other);
|
||||||
while !m.is_zero() {
|
while !m.is_zero() {
|
||||||
let temp = m;
|
let temp = m;
|
||||||
m = n % temp;
|
m = n % temp;
|
||||||
@ -1002,8 +1002,8 @@ impl Integer for BigInt {
|
|||||||
fn div_mod_floor(&self, other: &BigInt) -> (BigInt, BigInt) {
|
fn div_mod_floor(&self, other: &BigInt) -> (BigInt, BigInt) {
|
||||||
// m.sign == other.sign
|
// m.sign == other.sign
|
||||||
let (d_ui, m_ui) = self.data.div_rem(&other.data);
|
let (d_ui, m_ui) = self.data.div_rem(&other.data);
|
||||||
let d = BigInt::from_biguint(Plus, d_ui),
|
let d = BigInt::from_biguint(Plus, d_ui);
|
||||||
m = BigInt::from_biguint(Plus, m_ui);
|
let m = BigInt::from_biguint(Plus, m_ui);
|
||||||
match (self.sign, other.sign) {
|
match (self.sign, other.sign) {
|
||||||
(_, Zero) => fail!(),
|
(_, Zero) => fail!(),
|
||||||
(Plus, Plus) | (Zero, Plus) => (d, m),
|
(Plus, Plus) | (Zero, Plus) => (d, m),
|
||||||
|
@ -160,7 +160,9 @@ pub static stringnames: &'static[&'static str] = &'static[ "cbt", "_", "cr", "cs
|
|||||||
|
|
||||||
/// Parse a compiled terminfo entry, using long capability names if `longnames` is true
|
/// Parse a compiled terminfo entry, using long capability names if `longnames` is true
|
||||||
pub fn parse(file: @Reader, longnames: bool) -> Result<~TermInfo, ~str> {
|
pub fn parse(file: @Reader, longnames: bool) -> Result<~TermInfo, ~str> {
|
||||||
let bnames, snames, nnames;
|
let bnames;
|
||||||
|
let snames;
|
||||||
|
let nnames;
|
||||||
|
|
||||||
if longnames {
|
if longnames {
|
||||||
bnames = boolfnames;
|
bnames = boolfnames;
|
||||||
|
@ -140,9 +140,18 @@ fn fold_block(
|
|||||||
b.stmts.filter_mapped(|a| filter_stmt(cx, *a));
|
b.stmts.filter_mapped(|a| filter_stmt(cx, *a));
|
||||||
let filtered_view_items =
|
let filtered_view_items =
|
||||||
b.view_items.filter_mapped(|a| filter_view_item(cx, *a));
|
b.view_items.filter_mapped(|a| filter_view_item(cx, *a));
|
||||||
|
let filtered_view_items =
|
||||||
|
filtered_view_items.map(|x| fld.fold_view_item(*x));
|
||||||
|
let mut resulting_stmts = ~[];
|
||||||
|
for filtered_stmts.each |stmt| {
|
||||||
|
match fld.fold_stmt(*stmt) {
|
||||||
|
None => {}
|
||||||
|
Some(stmt) => resulting_stmts.push(stmt),
|
||||||
|
}
|
||||||
|
}
|
||||||
ast::blk_ {
|
ast::blk_ {
|
||||||
view_items: vec::map(filtered_view_items, |x| fld.fold_view_item(*x)),
|
view_items: filtered_view_items,
|
||||||
stmts: vec::map(filtered_stmts, |x| fld.fold_stmt(*x)),
|
stmts: resulting_stmts,
|
||||||
expr: b.expr.map(|x| fld.fold_expr(*x)),
|
expr: b.expr.map(|x| fld.fold_expr(*x)),
|
||||||
id: b.id,
|
id: b.id,
|
||||||
rules: b.rules,
|
rules: b.rules,
|
||||||
|
@ -380,7 +380,8 @@ pub fn missing_ctor(cx: @MatchCheckCtxt,
|
|||||||
}
|
}
|
||||||
ty::ty_nil => None,
|
ty::ty_nil => None,
|
||||||
ty::ty_bool => {
|
ty::ty_bool => {
|
||||||
let mut true_found = false, false_found = false;
|
let mut true_found = false;
|
||||||
|
let mut false_found = false;
|
||||||
for m.each |r| {
|
for m.each |r| {
|
||||||
match pat_ctor_id(cx, r[0]) {
|
match pat_ctor_id(cx, r[0]) {
|
||||||
None => (),
|
None => (),
|
||||||
@ -513,10 +514,12 @@ pub fn specialize(cx: @MatchCheckCtxt,
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
range(ref c_lo, ref c_hi) => {
|
range(ref c_lo, ref c_hi) => {
|
||||||
let m1 = compare_const_vals(c_lo, &e_v),
|
let m1 = compare_const_vals(c_lo, &e_v);
|
||||||
m2 = compare_const_vals(c_hi, &e_v);
|
let m2 = compare_const_vals(c_hi, &e_v);
|
||||||
match (m1, m2) {
|
match (m1, m2) {
|
||||||
(Some(val1), Some(val2)) => (val1 >= 0 && val2 <= 0),
|
(Some(val1), Some(val2)) => {
|
||||||
|
(val1 >= 0 && val2 <= 0)
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
cx.tcx.sess.span_err(pat_span,
|
cx.tcx.sess.span_err(pat_span,
|
||||||
"mismatched types between ranges");
|
"mismatched types between ranges");
|
||||||
@ -560,8 +563,8 @@ pub fn specialize(cx: @MatchCheckCtxt,
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
range(ref c_lo, ref c_hi) => {
|
range(ref c_lo, ref c_hi) => {
|
||||||
let m1 = compare_const_vals(c_lo, &e_v),
|
let m1 = compare_const_vals(c_lo, &e_v);
|
||||||
m2 = compare_const_vals(c_hi, &e_v);
|
let m2 = compare_const_vals(c_hi, &e_v);
|
||||||
match (m1, m2) {
|
match (m1, m2) {
|
||||||
(Some(val1), Some(val2)) => (val1 >= 0 && val2 <= 0),
|
(Some(val1), Some(val2)) => (val1 >= 0 && val2 <= 0),
|
||||||
_ => {
|
_ => {
|
||||||
@ -622,7 +625,8 @@ pub fn specialize(cx: @MatchCheckCtxt,
|
|||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
// Grab the class data that we care about.
|
// Grab the class data that we care about.
|
||||||
let class_fields, class_id;
|
let class_fields;
|
||||||
|
let class_id;
|
||||||
match ty::get(left_ty).sty {
|
match ty::get(left_ty).sty {
|
||||||
ty::ty_struct(cid, _) => {
|
ty::ty_struct(cid, _) => {
|
||||||
class_id = cid;
|
class_id = cid;
|
||||||
@ -667,8 +671,8 @@ pub fn specialize(cx: @MatchCheckCtxt,
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
range(ref c_lo, ref c_hi) => {
|
range(ref c_lo, ref c_hi) => {
|
||||||
let m1 = compare_const_vals(c_lo, &e_v),
|
let m1 = compare_const_vals(c_lo, &e_v);
|
||||||
m2 = compare_const_vals(c_hi, &e_v);
|
let m2 = compare_const_vals(c_hi, &e_v);
|
||||||
match (m1, m2) {
|
match (m1, m2) {
|
||||||
(Some(val1), Some(val2)) => (val1 >= 0 && val2 <= 0),
|
(Some(val1), Some(val2)) => (val1 >= 0 && val2 <= 0),
|
||||||
_ => {
|
_ => {
|
||||||
@ -691,11 +695,11 @@ pub fn specialize(cx: @MatchCheckCtxt,
|
|||||||
single => return Some(vec::to_owned(r.tail())),
|
single => return Some(vec::to_owned(r.tail())),
|
||||||
_ => fail!("type error")
|
_ => fail!("type error")
|
||||||
};
|
};
|
||||||
let v_lo = eval_const_expr(cx.tcx, lo),
|
let v_lo = eval_const_expr(cx.tcx, lo);
|
||||||
v_hi = eval_const_expr(cx.tcx, hi);
|
let v_hi = eval_const_expr(cx.tcx, hi);
|
||||||
|
|
||||||
let m1 = compare_const_vals(&c_lo, &v_lo),
|
let m1 = compare_const_vals(&c_lo, &v_lo);
|
||||||
m2 = compare_const_vals(&c_hi, &v_hi);
|
let m2 = compare_const_vals(&c_hi, &v_hi);
|
||||||
match (m1, m2) {
|
match (m1, m2) {
|
||||||
(Some(val1), Some(val2)) if val1 >= 0 && val2 <= 0 => {
|
(Some(val1), Some(val2)) if val1 >= 0 && val2 <= 0 => {
|
||||||
Some(vec::to_owned(r.tail()))
|
Some(vec::to_owned(r.tail()))
|
||||||
|
@ -372,12 +372,10 @@ impl<'self, O:DataFlowOperator> PropagationContext<'self, O> {
|
|||||||
in_out: &mut [uint],
|
in_out: &mut [uint],
|
||||||
loop_scopes: &mut ~[LoopScope]) {
|
loop_scopes: &mut ~[LoopScope]) {
|
||||||
match decl.node {
|
match decl.node {
|
||||||
ast::decl_local(ref locals) => {
|
ast::decl_local(local) => {
|
||||||
for locals.each |local| {
|
|
||||||
self.walk_pat(local.node.pat, in_out, loop_scopes);
|
self.walk_pat(local.node.pat, in_out, loop_scopes);
|
||||||
self.walk_opt_expr(local.node.init, in_out, loop_scopes);
|
self.walk_opt_expr(local.node.init, in_out, loop_scopes);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
ast::decl_item(_) => {}
|
ast::decl_item(_) => {}
|
||||||
}
|
}
|
||||||
|
@ -948,14 +948,10 @@ impl Liveness {
|
|||||||
pub fn propagate_through_decl(&self, decl: @decl, succ: LiveNode)
|
pub fn propagate_through_decl(&self, decl: @decl, succ: LiveNode)
|
||||||
-> LiveNode {
|
-> LiveNode {
|
||||||
match decl.node {
|
match decl.node {
|
||||||
decl_local(ref locals) => {
|
decl_local(ref local) => {
|
||||||
do locals.foldr(succ) |local, succ| {
|
|
||||||
self.propagate_through_local(*local, succ)
|
self.propagate_through_local(*local, succ)
|
||||||
}
|
}
|
||||||
}
|
decl_item(_) => succ,
|
||||||
decl_item(_) => {
|
|
||||||
succ
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,7 +325,9 @@ pub fn parent_id(cx: Context, span: span) -> ast::node_id {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Records the current parent (if any) as the parent of `child_id`.
|
/// Records the current parent (if any) as the parent of `child_id`.
|
||||||
pub fn parent_to_expr(cx: Context, child_id: ast::node_id) {
|
pub fn parent_to_expr(cx: Context, child_id: ast::node_id, sp: span) {
|
||||||
|
debug!("region::parent_to_expr(span=%?)",
|
||||||
|
cx.sess.codemap.span_to_str(sp));
|
||||||
for cx.parent.each |parent_id| {
|
for cx.parent.each |parent_id| {
|
||||||
cx.region_maps.record_parent(child_id, *parent_id);
|
cx.region_maps.record_parent(child_id, *parent_id);
|
||||||
}
|
}
|
||||||
@ -333,7 +335,7 @@ pub fn parent_to_expr(cx: Context, child_id: ast::node_id) {
|
|||||||
|
|
||||||
pub fn resolve_block(blk: &ast::blk, cx: Context, visitor: visit::vt<Context>) {
|
pub fn resolve_block(blk: &ast::blk, cx: Context, visitor: visit::vt<Context>) {
|
||||||
// Record the parent of this block.
|
// Record the parent of this block.
|
||||||
parent_to_expr(cx, blk.node.id);
|
parent_to_expr(cx, blk.node.id, blk.span);
|
||||||
|
|
||||||
// Descend.
|
// Descend.
|
||||||
let new_cx = Context {var_parent: Some(blk.node.id),
|
let new_cx = Context {var_parent: Some(blk.node.id),
|
||||||
@ -348,7 +350,7 @@ pub fn resolve_arm(arm: &ast::arm, cx: Context, visitor: visit::vt<Context>) {
|
|||||||
|
|
||||||
pub fn resolve_pat(pat: @ast::pat, cx: Context, visitor: visit::vt<Context>) {
|
pub fn resolve_pat(pat: @ast::pat, cx: Context, visitor: visit::vt<Context>) {
|
||||||
assert_eq!(cx.var_parent, cx.parent);
|
assert_eq!(cx.var_parent, cx.parent);
|
||||||
parent_to_expr(cx, pat.id);
|
parent_to_expr(cx, pat.id, pat.span);
|
||||||
visit::visit_pat(pat, cx, visitor);
|
visit::visit_pat(pat, cx, visitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -359,7 +361,7 @@ pub fn resolve_stmt(stmt: @ast::stmt, cx: Context, visitor: visit::vt<Context>)
|
|||||||
}
|
}
|
||||||
ast::stmt_expr(_, stmt_id) |
|
ast::stmt_expr(_, stmt_id) |
|
||||||
ast::stmt_semi(_, stmt_id) => {
|
ast::stmt_semi(_, stmt_id) => {
|
||||||
parent_to_expr(cx, stmt_id);
|
parent_to_expr(cx, stmt_id, stmt.span);
|
||||||
let expr_cx = Context {parent: Some(stmt_id), ..cx};
|
let expr_cx = Context {parent: Some(stmt_id), ..cx};
|
||||||
visit::visit_stmt(stmt, expr_cx, visitor);
|
visit::visit_stmt(stmt, expr_cx, visitor);
|
||||||
}
|
}
|
||||||
@ -368,7 +370,7 @@ pub fn resolve_stmt(stmt: @ast::stmt, cx: Context, visitor: visit::vt<Context>)
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn resolve_expr(expr: @ast::expr, cx: Context, visitor: visit::vt<Context>) {
|
pub fn resolve_expr(expr: @ast::expr, cx: Context, visitor: visit::vt<Context>) {
|
||||||
parent_to_expr(cx, expr.id);
|
parent_to_expr(cx, expr.id, expr.span);
|
||||||
|
|
||||||
let mut new_cx = cx;
|
let mut new_cx = cx;
|
||||||
new_cx.parent = Some(expr.id);
|
new_cx.parent = Some(expr.id);
|
||||||
@ -410,7 +412,7 @@ pub fn resolve_local(local: @ast::local,
|
|||||||
cx: Context,
|
cx: Context,
|
||||||
visitor: visit::vt<Context>) {
|
visitor: visit::vt<Context>) {
|
||||||
assert_eq!(cx.var_parent, cx.parent);
|
assert_eq!(cx.var_parent, cx.parent);
|
||||||
parent_to_expr(cx, local.node.id);
|
parent_to_expr(cx, local.node.id, local.span);
|
||||||
visit::visit_local(local, cx, visitor);
|
visit::visit_local(local, cx, visitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -423,12 +425,18 @@ pub fn resolve_item(item: @ast::item, cx: Context, visitor: visit::vt<Context>)
|
|||||||
pub fn resolve_fn(fk: &visit::fn_kind,
|
pub fn resolve_fn(fk: &visit::fn_kind,
|
||||||
decl: &ast::fn_decl,
|
decl: &ast::fn_decl,
|
||||||
body: &ast::blk,
|
body: &ast::blk,
|
||||||
_sp: span,
|
sp: span,
|
||||||
id: ast::node_id,
|
id: ast::node_id,
|
||||||
cx: Context,
|
cx: Context,
|
||||||
visitor: visit::vt<Context>) {
|
visitor: visit::vt<Context>) {
|
||||||
debug!("region::resolve_fn(id=%?, body.node.id=%?, cx.parent=%?)",
|
debug!("region::resolve_fn(id=%?, \
|
||||||
id, body.node.id, cx.parent);
|
span=%?, \
|
||||||
|
body.node.id=%?, \
|
||||||
|
cx.parent=%?)",
|
||||||
|
id,
|
||||||
|
cx.sess.codemap.span_to_str(sp),
|
||||||
|
body.node.id,
|
||||||
|
cx.parent);
|
||||||
|
|
||||||
// The arguments and `self` are parented to the body of the fn.
|
// The arguments and `self` are parented to the body of the fn.
|
||||||
let decl_cx = Context {parent: Some(body.node.id),
|
let decl_cx = Context {parent: Some(body.node.id),
|
||||||
|
@ -1282,7 +1282,8 @@ pub fn compile_submatch(bcx: block,
|
|||||||
assert!((m.len() > 0u || chk.is_some()));
|
assert!((m.len() > 0u || chk.is_some()));
|
||||||
let _icx = bcx.insn_ctxt("match::compile_submatch");
|
let _icx = bcx.insn_ctxt("match::compile_submatch");
|
||||||
let mut bcx = bcx;
|
let mut bcx = bcx;
|
||||||
let tcx = bcx.tcx(), dm = tcx.def_map;
|
let tcx = bcx.tcx();
|
||||||
|
let dm = tcx.def_map;
|
||||||
if m.len() == 0u {
|
if m.len() == 0u {
|
||||||
Br(bcx, chk.get()());
|
Br(bcx, chk.get()());
|
||||||
return;
|
return;
|
||||||
@ -1638,7 +1639,8 @@ fn create_bindings_map(bcx: block, pat: @ast::pat) -> BindingsMap {
|
|||||||
let variable_ty = node_id_type(bcx, p_id);
|
let variable_ty = node_id_type(bcx, p_id);
|
||||||
let llvariable_ty = type_of::type_of(ccx, variable_ty);
|
let llvariable_ty = type_of::type_of(ccx, variable_ty);
|
||||||
|
|
||||||
let llmatch, trmode;
|
let llmatch;
|
||||||
|
let trmode;
|
||||||
match bm {
|
match bm {
|
||||||
ast::bind_infer => {
|
ast::bind_infer => {
|
||||||
// in this case, the final type of the variable will be T,
|
// in this case, the final type of the variable will be T,
|
||||||
@ -1676,7 +1678,8 @@ pub fn trans_match_inner(scope_cx: block,
|
|||||||
return bcx;
|
return bcx;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut arm_datas = ~[], matches = ~[];
|
let mut arm_datas = ~[];
|
||||||
|
let mut matches = ~[];
|
||||||
for vec::each(arms) |arm| {
|
for vec::each(arms) |arm| {
|
||||||
let body = scope_block(bcx, arm.body.info(), "case_body");
|
let body = scope_block(bcx, arm.body.info(), "case_body");
|
||||||
let bindings_map = create_bindings_map(bcx, arm.pats[0]);
|
let bindings_map = create_bindings_map(bcx, arm.pats[0]);
|
||||||
|
@ -950,7 +950,8 @@ pub fn in_lpad_scope_cx(bcx: block, f: &fn(si: &mut scope_info)) {
|
|||||||
pub fn get_landing_pad(bcx: block) -> BasicBlockRef {
|
pub fn get_landing_pad(bcx: block) -> BasicBlockRef {
|
||||||
let _icx = bcx.insn_ctxt("get_landing_pad");
|
let _icx = bcx.insn_ctxt("get_landing_pad");
|
||||||
|
|
||||||
let mut cached = None, pad_bcx = bcx; // Guaranteed to be set below
|
let mut cached = None;
|
||||||
|
let mut pad_bcx = bcx; // Guaranteed to be set below
|
||||||
do in_lpad_scope_cx(bcx) |inf| {
|
do in_lpad_scope_cx(bcx) |inf| {
|
||||||
// If there is a valid landing pad still around, use it
|
// If there is a valid landing pad still around, use it
|
||||||
match inf.landing_pad {
|
match inf.landing_pad {
|
||||||
@ -1154,15 +1155,13 @@ pub fn trans_stmt(cx: block, s: &ast::stmt) -> block {
|
|||||||
}
|
}
|
||||||
ast::stmt_decl(d, _) => {
|
ast::stmt_decl(d, _) => {
|
||||||
match d.node {
|
match d.node {
|
||||||
ast::decl_local(ref locals) => {
|
ast::decl_local(ref local) => {
|
||||||
for locals.each |local| {
|
|
||||||
bcx = init_local(bcx, *local);
|
bcx = init_local(bcx, *local);
|
||||||
if cx.sess().opts.extra_debuginfo
|
if cx.sess().opts.extra_debuginfo
|
||||||
&& fcx_has_nonzero_span(bcx.fcx) {
|
&& fcx_has_nonzero_span(bcx.fcx) {
|
||||||
debuginfo::create_local_var(bcx, *local);
|
debuginfo::create_local_var(bcx, *local);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
ast::decl_item(i) => trans_item(*cx.fcx.ccx, i)
|
ast::decl_item(i) => trans_item(*cx.fcx.ccx, i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1296,7 +1295,8 @@ pub fn cleanup_and_leave(bcx: block,
|
|||||||
upto: Option<BasicBlockRef>,
|
upto: Option<BasicBlockRef>,
|
||||||
leave: Option<BasicBlockRef>) {
|
leave: Option<BasicBlockRef>) {
|
||||||
let _icx = bcx.insn_ctxt("cleanup_and_leave");
|
let _icx = bcx.insn_ctxt("cleanup_and_leave");
|
||||||
let mut cur = bcx, bcx = bcx;
|
let mut cur = bcx;
|
||||||
|
let mut bcx = bcx;
|
||||||
let is_lpad = leave == None;
|
let is_lpad = leave == None;
|
||||||
loop {
|
loop {
|
||||||
debug!("cleanup_and_leave: leaving %s", cur.to_str());
|
debug!("cleanup_and_leave: leaving %s", cur.to_str());
|
||||||
@ -1402,15 +1402,11 @@ pub fn block_locals(b: &ast::blk, it: &fn(@ast::local)) {
|
|||||||
match s.node {
|
match s.node {
|
||||||
ast::stmt_decl(d, _) => {
|
ast::stmt_decl(d, _) => {
|
||||||
match d.node {
|
match d.node {
|
||||||
ast::decl_local(ref locals) => {
|
ast::decl_local(ref local) => it(*local),
|
||||||
for locals.each |local| {
|
_ => {} /* fall through */
|
||||||
it(*local);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {/* fall through */ }
|
_ => {} /* fall through */
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {/* fall through */ }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1987,7 +1983,8 @@ pub fn trans_enum_variant(ccx: @CrateContext,
|
|||||||
None);
|
None);
|
||||||
|
|
||||||
let raw_llargs = create_llargs_for_fn_args(fcx, no_self, fn_args);
|
let raw_llargs = create_llargs_for_fn_args(fcx, no_self, fn_args);
|
||||||
let bcx = top_scope_block(fcx, None), lltop = bcx.llbb;
|
let bcx = top_scope_block(fcx, None);
|
||||||
|
let lltop = bcx.llbb;
|
||||||
let arg_tys = ty::ty_fn_args(node_id_type(bcx, variant.node.id));
|
let arg_tys = ty::ty_fn_args(node_id_type(bcx, variant.node.id));
|
||||||
let bcx = copy_args_to_allocas(fcx, bcx, fn_args, raw_llargs, arg_tys);
|
let bcx = copy_args_to_allocas(fcx, bcx, fn_args, raw_llargs, arg_tys);
|
||||||
|
|
||||||
|
@ -161,7 +161,8 @@ pub fn mk_closure_tys(tcx: ty::ctxt,
|
|||||||
pub fn allocate_cbox(bcx: block, sigil: ast::Sigil, cdata_ty: ty::t)
|
pub fn allocate_cbox(bcx: block, sigil: ast::Sigil, cdata_ty: ty::t)
|
||||||
-> Result {
|
-> Result {
|
||||||
let _icx = bcx.insn_ctxt("closure::allocate_cbox");
|
let _icx = bcx.insn_ctxt("closure::allocate_cbox");
|
||||||
let ccx = bcx.ccx(), tcx = ccx.tcx;
|
let ccx = bcx.ccx();
|
||||||
|
let tcx = ccx.tcx;
|
||||||
|
|
||||||
fn nuke_ref_count(bcx: block, llbox: ValueRef) {
|
fn nuke_ref_count(bcx: block, llbox: ValueRef) {
|
||||||
let _icx = bcx.insn_ctxt("closure::nuke_ref_count");
|
let _icx = bcx.insn_ctxt("closure::nuke_ref_count");
|
||||||
@ -204,7 +205,8 @@ pub fn store_environment(bcx: block,
|
|||||||
bound_values: ~[EnvValue],
|
bound_values: ~[EnvValue],
|
||||||
sigil: ast::Sigil) -> ClosureResult {
|
sigil: ast::Sigil) -> ClosureResult {
|
||||||
let _icx = bcx.insn_ctxt("closure::store_environment");
|
let _icx = bcx.insn_ctxt("closure::store_environment");
|
||||||
let ccx = bcx.ccx(), tcx = ccx.tcx;
|
let ccx = bcx.ccx();
|
||||||
|
let tcx = ccx.tcx;
|
||||||
|
|
||||||
// compute the shape of the closure
|
// compute the shape of the closure
|
||||||
let cdata_ty = mk_closure_tys(tcx, bound_values);
|
let cdata_ty = mk_closure_tys(tcx, bound_values);
|
||||||
@ -500,7 +502,8 @@ pub fn make_opaque_cbox_take_glue(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ~fn requires a deep copy.
|
// ~fn requires a deep copy.
|
||||||
let ccx = bcx.ccx(), tcx = ccx.tcx;
|
let ccx = bcx.ccx();
|
||||||
|
let tcx = ccx.tcx;
|
||||||
let llopaquecboxty = T_opaque_box_ptr(ccx);
|
let llopaquecboxty = T_opaque_box_ptr(ccx);
|
||||||
let cbox_in = Load(bcx, cboxptr);
|
let cbox_in = Load(bcx, cboxptr);
|
||||||
do with_cond(bcx, IsNotNull(bcx, cbox_in)) |bcx| {
|
do with_cond(bcx, IsNotNull(bcx, cbox_in)) |bcx| {
|
||||||
|
@ -1438,7 +1438,8 @@ pub fn align_to(cx: block, off: ValueRef, align: ValueRef) -> ValueRef {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn path_str(sess: session::Session, p: &[path_elt]) -> ~str {
|
pub fn path_str(sess: session::Session, p: &[path_elt]) -> ~str {
|
||||||
let mut r = ~"", first = true;
|
let mut r = ~"";
|
||||||
|
let mut first = true;
|
||||||
for p.each |e| {
|
for p.each |e| {
|
||||||
match *e {
|
match *e {
|
||||||
ast_map::path_name(s) | ast_map::path_mod(s) => {
|
ast_map::path_name(s) | ast_map::path_mod(s) => {
|
||||||
|
@ -332,7 +332,8 @@ pub fn trans_fail_expr(bcx: block,
|
|||||||
let mut bcx = bcx;
|
let mut bcx = bcx;
|
||||||
match fail_expr {
|
match fail_expr {
|
||||||
Some(arg_expr) => {
|
Some(arg_expr) => {
|
||||||
let ccx = bcx.ccx(), tcx = ccx.tcx;
|
let ccx = bcx.ccx();
|
||||||
|
let tcx = ccx.tcx;
|
||||||
let arg_datum = unpack_datum!(
|
let arg_datum = unpack_datum!(
|
||||||
bcx, expr::trans_to_datum(bcx, arg_expr));
|
bcx, expr::trans_to_datum(bcx, arg_expr));
|
||||||
|
|
||||||
|
@ -881,7 +881,8 @@ pub fn create_local_var(bcx: block, local: @ast::local)
|
|||||||
|
|
||||||
pub fn create_arg(bcx: block, arg: ast::arg, sp: span)
|
pub fn create_arg(bcx: block, arg: ast::arg, sp: span)
|
||||||
-> Option<@Metadata<ArgumentMetadata>> {
|
-> Option<@Metadata<ArgumentMetadata>> {
|
||||||
let fcx = bcx.fcx, cx = *fcx.ccx;
|
let fcx = bcx.fcx;
|
||||||
|
let cx = *fcx.ccx;
|
||||||
let cache = get_cache(cx);
|
let cache = get_cache(cx);
|
||||||
let tg = ArgVariableTag;
|
let tg = ArgVariableTag;
|
||||||
match cached_metadata::<@Metadata<ArgumentMetadata>>(
|
match cached_metadata::<@Metadata<ArgumentMetadata>>(
|
||||||
|
@ -436,7 +436,8 @@ pub fn trans_foreign_mod(ccx: @CrateContext,
|
|||||||
debug!("build_direct_fn(%s)", *link_name(ccx, item));
|
debug!("build_direct_fn(%s)", *link_name(ccx, item));
|
||||||
|
|
||||||
let fcx = new_fn_ctxt(ccx, ~[], decl, tys.fn_sig.output, None);
|
let fcx = new_fn_ctxt(ccx, ~[], decl, tys.fn_sig.output, None);
|
||||||
let bcx = top_scope_block(fcx, None), lltop = bcx.llbb;
|
let bcx = top_scope_block(fcx, None);
|
||||||
|
let lltop = bcx.llbb;
|
||||||
let llbasefn = base_fn(ccx, *link_name(ccx, item), tys, cc);
|
let llbasefn = base_fn(ccx, *link_name(ccx, item), tys, cc);
|
||||||
let ty = ty::lookup_item_type(ccx.tcx,
|
let ty = ty::lookup_item_type(ccx.tcx,
|
||||||
ast_util::local_def(item.id)).ty;
|
ast_util::local_def(item.id)).ty;
|
||||||
@ -462,7 +463,8 @@ pub fn trans_foreign_mod(ccx: @CrateContext,
|
|||||||
debug!("build_fast_ffi_fn(%s)", *link_name(ccx, item));
|
debug!("build_fast_ffi_fn(%s)", *link_name(ccx, item));
|
||||||
|
|
||||||
let fcx = new_fn_ctxt(ccx, ~[], decl, tys.fn_sig.output, None);
|
let fcx = new_fn_ctxt(ccx, ~[], decl, tys.fn_sig.output, None);
|
||||||
let bcx = top_scope_block(fcx, None), lltop = bcx.llbb;
|
let bcx = top_scope_block(fcx, None);
|
||||||
|
let lltop = bcx.llbb;
|
||||||
let llbasefn = base_fn(ccx, *link_name(ccx, item), tys, cc);
|
let llbasefn = base_fn(ccx, *link_name(ccx, item), tys, cc);
|
||||||
set_no_inline(fcx.llfn);
|
set_no_inline(fcx.llfn);
|
||||||
set_fixed_stack_segment(fcx.llfn);
|
set_fixed_stack_segment(fcx.llfn);
|
||||||
|
@ -566,7 +566,8 @@ pub fn combine_impl_and_methods_origins(bcx: block,
|
|||||||
// Find the bounds for the method, which are the tail of the
|
// Find the bounds for the method, which are the tail of the
|
||||||
// bounds found in the item type, as the item type combines the
|
// bounds found in the item type, as the item type combines the
|
||||||
// rcvr + method bounds.
|
// rcvr + method bounds.
|
||||||
let ccx = bcx.ccx(), tcx = bcx.tcx();
|
let ccx = bcx.ccx();
|
||||||
|
let tcx = bcx.tcx();
|
||||||
let n_m_tps = method_ty_param_count(ccx, mth_did, impl_did);
|
let n_m_tps = method_ty_param_count(ccx, mth_did, impl_did);
|
||||||
let ty::ty_param_bounds_and_ty {
|
let ty::ty_param_bounds_and_ty {
|
||||||
generics: r_m_generics,
|
generics: r_m_generics,
|
||||||
|
@ -136,7 +136,8 @@ pub fn duplicate_uniq(bcx: block, vptr: ValueRef, vec_ty: ty::t) -> Result {
|
|||||||
pub fn make_drop_glue_unboxed(bcx: block, vptr: ValueRef, vec_ty: ty::t) ->
|
pub fn make_drop_glue_unboxed(bcx: block, vptr: ValueRef, vec_ty: ty::t) ->
|
||||||
block {
|
block {
|
||||||
let _icx = bcx.insn_ctxt("tvec::make_drop_glue_unboxed");
|
let _icx = bcx.insn_ctxt("tvec::make_drop_glue_unboxed");
|
||||||
let tcx = bcx.tcx(), unit_ty = ty::sequence_element_type(tcx, vec_ty);
|
let tcx = bcx.tcx();
|
||||||
|
let unit_ty = ty::sequence_element_type(tcx, vec_ty);
|
||||||
if ty::type_needs_drop(tcx, unit_ty) {
|
if ty::type_needs_drop(tcx, unit_ty) {
|
||||||
iter_vec_unboxed(bcx, vptr, vec_ty, glue::drop_ty)
|
iter_vec_unboxed(bcx, vptr, vec_ty, glue::drop_ty)
|
||||||
} else { bcx }
|
} else { bcx }
|
||||||
|
@ -106,7 +106,8 @@ pub fn check_pat_variant(pcx: &pat_ctxt, pat: @ast::pat, path: @ast::Path,
|
|||||||
let fcx = pcx.fcx;
|
let fcx = pcx.fcx;
|
||||||
let tcx = pcx.fcx.ccx.tcx;
|
let tcx = pcx.fcx.ccx.tcx;
|
||||||
|
|
||||||
let arg_types, kind_name;
|
let arg_types;
|
||||||
|
let kind_name;
|
||||||
|
|
||||||
// structure_of requires type variables to be resolved.
|
// structure_of requires type variables to be resolved.
|
||||||
// So when we pass in <expected>, it's an error if it
|
// So when we pass in <expected>, it's an error if it
|
||||||
|
@ -1896,7 +1896,9 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
|
|||||||
|
|
||||||
// Look up the number of type parameters and the raw type, and
|
// Look up the number of type parameters and the raw type, and
|
||||||
// determine whether the class is region-parameterized.
|
// determine whether the class is region-parameterized.
|
||||||
let type_parameter_count, region_parameterized, raw_type;
|
let type_parameter_count;
|
||||||
|
let region_parameterized;
|
||||||
|
let raw_type;
|
||||||
if class_id.crate == ast::local_crate {
|
if class_id.crate == ast::local_crate {
|
||||||
region_parameterized =
|
region_parameterized =
|
||||||
tcx.region_paramd_items.find(&class_id.node).
|
tcx.region_paramd_items.find(&class_id.node).
|
||||||
@ -1983,7 +1985,9 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
|
|||||||
|
|
||||||
// Look up the number of type parameters and the raw type, and
|
// Look up the number of type parameters and the raw type, and
|
||||||
// determine whether the enum is region-parameterized.
|
// determine whether the enum is region-parameterized.
|
||||||
let type_parameter_count, region_parameterized, raw_type;
|
let type_parameter_count;
|
||||||
|
let region_parameterized;
|
||||||
|
let raw_type;
|
||||||
if enum_id.crate == ast::local_crate {
|
if enum_id.crate == ast::local_crate {
|
||||||
region_parameterized =
|
region_parameterized =
|
||||||
tcx.region_paramd_items.find(&enum_id.node).map_consume(|x| *x);
|
tcx.region_paramd_items.find(&enum_id.node).map_consume(|x| *x);
|
||||||
@ -2876,12 +2880,12 @@ pub fn check_stmt(fcx: @mut FnCtxt, stmt: @ast::stmt) {
|
|||||||
ast::stmt_decl(decl, id) => {
|
ast::stmt_decl(decl, id) => {
|
||||||
node_id = id;
|
node_id = id;
|
||||||
match decl.node {
|
match decl.node {
|
||||||
ast::decl_local(ref ls) => for ls.each |l| {
|
ast::decl_local(ref l) => {
|
||||||
check_decl_local(fcx, *l);
|
check_decl_local(fcx, *l);
|
||||||
let l_t = fcx.node_ty(l.node.id);
|
let l_t = fcx.node_ty(l.node.id);
|
||||||
saw_bot = saw_bot || ty::type_is_bot(l_t);
|
saw_bot = saw_bot || ty::type_is_bot(l_t);
|
||||||
saw_err = saw_err || ty::type_is_error(l_t);
|
saw_err = saw_err || ty::type_is_error(l_t);
|
||||||
},
|
}
|
||||||
ast::decl_item(_) => {/* ignore for now */ }
|
ast::decl_item(_) => {/* ignore for now */ }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,8 @@ fn lookup_vtables(vcx: &VtableContext,
|
|||||||
let _i = indenter();
|
let _i = indenter();
|
||||||
|
|
||||||
let tcx = vcx.tcx();
|
let tcx = vcx.tcx();
|
||||||
let mut result = ~[], i = 0u;
|
let mut result = ~[];
|
||||||
|
let mut i = 0u;
|
||||||
for substs.tps.each |ty| {
|
for substs.tps.each |ty| {
|
||||||
// ty is the value supplied for the type parameter A...
|
// ty is the value supplied for the type parameter A...
|
||||||
|
|
||||||
|
@ -107,7 +107,8 @@ fn resolve_vtable_map_entry(fcx: @mut FnCtxt, sp: span, id: ast::node_id) {
|
|||||||
|
|
||||||
fn resolve_type_vars_for_node(wbcx: @mut WbCtxt, sp: span, id: ast::node_id)
|
fn resolve_type_vars_for_node(wbcx: @mut WbCtxt, sp: span, id: ast::node_id)
|
||||||
-> Option<ty::t> {
|
-> Option<ty::t> {
|
||||||
let fcx = wbcx.fcx, tcx = fcx.ccx.tcx;
|
let fcx = wbcx.fcx;
|
||||||
|
let tcx = fcx.ccx.tcx;
|
||||||
|
|
||||||
// Resolve any borrowings for the node with id `id`
|
// Resolve any borrowings for the node with id `id`
|
||||||
match fcx.inh.adjustments.find(&id) {
|
match fcx.inh.adjustments.find(&id) {
|
||||||
|
@ -220,7 +220,9 @@ impl Combine for Glb {
|
|||||||
|
|
||||||
let tainted = this.infcx.region_vars.tainted(snapshot, r0);
|
let tainted = this.infcx.region_vars.tainted(snapshot, r0);
|
||||||
|
|
||||||
let mut a_r = None, b_r = None, only_new_vars = true;
|
let mut a_r = None;
|
||||||
|
let mut b_r = None;
|
||||||
|
let mut only_new_vars = true;
|
||||||
for tainted.each |r| {
|
for tainted.each |r| {
|
||||||
if is_var_in_set(a_vars, *r) {
|
if is_var_in_set(a_vars, *r) {
|
||||||
if a_r.is_some() {
|
if a_r.is_some() {
|
||||||
|
@ -422,7 +422,7 @@ pub fn lattice_vars<L:LatticeDir + Combine,
|
|||||||
|
|
||||||
// If both A and B have an UB type, then we can just compute the
|
// If both A and B have an UB type, then we can just compute the
|
||||||
// LUB of those types:
|
// LUB of those types:
|
||||||
let a_bnd = this.bnd(a_bounds), b_bnd = this.bnd(b_bounds);
|
let (a_bnd, b_bnd) = (this.bnd(a_bounds), this.bnd(b_bounds));
|
||||||
match (a_bnd, b_bnd) {
|
match (a_bnd, b_bnd) {
|
||||||
(Some(ref a_ty), Some(ref b_ty)) => {
|
(Some(ref a_ty), Some(ref b_ty)) => {
|
||||||
match this.infcx().try(|| lattice_dir_op(a_ty, b_ty) ) {
|
match this.infcx().try(|| lattice_dir_op(a_ty, b_ty) ) {
|
||||||
|
@ -928,7 +928,8 @@ impl RegionVarBindings {
|
|||||||
// `result_set` acts as a worklist: we explore all outgoing
|
// `result_set` acts as a worklist: we explore all outgoing
|
||||||
// edges and add any new regions we find to result_set. This
|
// edges and add any new regions we find to result_set. This
|
||||||
// is not a terribly efficient implementation.
|
// is not a terribly efficient implementation.
|
||||||
let mut result_set = ~[r0], result_index = 0;
|
let mut result_set = ~[r0];
|
||||||
|
let mut result_index = 0;
|
||||||
while result_index < result_set.len() {
|
while result_index < result_set.len() {
|
||||||
// nb: can't use uint::range() here because result_set grows
|
// nb: can't use uint::range() here because result_set grows
|
||||||
let r = result_set[result_index];
|
let r = result_set[result_index];
|
||||||
|
@ -242,7 +242,8 @@ pub fn require_same_types(
|
|||||||
t2: ty::t,
|
t2: ty::t,
|
||||||
msg: &fn() -> ~str) -> bool {
|
msg: &fn() -> ~str) -> bool {
|
||||||
|
|
||||||
let l_tcx, l_infcx;
|
let l_tcx;
|
||||||
|
let l_infcx;
|
||||||
match maybe_infcx {
|
match maybe_infcx {
|
||||||
None => {
|
None => {
|
||||||
l_tcx = tcx;
|
l_tcx = tcx;
|
||||||
|
@ -771,7 +771,7 @@ impl<T:Reader> ReaderUtil for T {
|
|||||||
fn read_le_uint_n(&self, nbytes: uint) -> u64 {
|
fn read_le_uint_n(&self, nbytes: uint) -> u64 {
|
||||||
assert!(nbytes > 0 && nbytes <= 8);
|
assert!(nbytes > 0 && nbytes <= 8);
|
||||||
|
|
||||||
let mut val = 0u64, pos = 0, i = nbytes;
|
let mut (val, pos, i) = (0u64, 0, nbytes);
|
||||||
while i > 0 {
|
while i > 0 {
|
||||||
val += (self.read_u8() as u64) << pos;
|
val += (self.read_u8() as u64) << pos;
|
||||||
pos += 8;
|
pos += 8;
|
||||||
@ -787,7 +787,7 @@ impl<T:Reader> ReaderUtil for T {
|
|||||||
fn read_be_uint_n(&self, nbytes: uint) -> u64 {
|
fn read_be_uint_n(&self, nbytes: uint) -> u64 {
|
||||||
assert!(nbytes > 0 && nbytes <= 8);
|
assert!(nbytes > 0 && nbytes <= 8);
|
||||||
|
|
||||||
let mut val = 0u64, i = nbytes;
|
let mut (val, i) = (0u64, nbytes);
|
||||||
while i > 0 {
|
while i > 0 {
|
||||||
i -= 1;
|
i -= 1;
|
||||||
val += (self.read_u8() as u64) << i * 8;
|
val += (self.read_u8() as u64) << i * 8;
|
||||||
@ -1304,7 +1304,9 @@ pub fn u64_to_le_bytes<T>(n: u64, size: uint,
|
|||||||
(n >> 56) as u8]),
|
(n >> 56) as u8]),
|
||||||
_ => {
|
_ => {
|
||||||
|
|
||||||
let mut bytes: ~[u8] = ~[], i = size, n = n;
|
let mut bytes: ~[u8] = ~[];
|
||||||
|
let mut i = size;
|
||||||
|
let mut n = n;
|
||||||
while i > 0u {
|
while i > 0u {
|
||||||
bytes.push((n & 255_u64) as u8);
|
bytes.push((n & 255_u64) as u8);
|
||||||
n >>= 8_u64;
|
n >>= 8_u64;
|
||||||
|
@ -40,14 +40,14 @@ pub mod raw {
|
|||||||
/// Determine if two shared boxes point to the same object
|
/// Determine if two shared boxes point to the same object
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn ptr_eq<T>(a: @T, b: @T) -> bool {
|
pub fn ptr_eq<T>(a: @T, b: @T) -> bool {
|
||||||
let a_ptr: *T = to_unsafe_ptr(&*a), b_ptr: *T = to_unsafe_ptr(&*b);
|
let (a_ptr, b_ptr): (*T, *T) = (to_unsafe_ptr(&*a), to_unsafe_ptr(&*b));
|
||||||
a_ptr == b_ptr
|
a_ptr == b_ptr
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Determine if two mutable shared boxes point to the same object
|
/// Determine if two mutable shared boxes point to the same object
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn mut_ptr_eq<T>(a: @mut T, b: @mut T) -> bool {
|
pub fn mut_ptr_eq<T>(a: @mut T, b: @mut T) -> bool {
|
||||||
let a_ptr: *T = to_unsafe_ptr(&*a), b_ptr: *T = to_unsafe_ptr(&*b);
|
let (a_ptr, b_ptr): (*T, *T) = (to_unsafe_ptr(&*a), to_unsafe_ptr(&*b));
|
||||||
a_ptr == b_ptr
|
a_ptr == b_ptr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -400,7 +400,7 @@ impl Integer for $T {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn gcd(&self, other: &$T) -> $T {
|
fn gcd(&self, other: &$T) -> $T {
|
||||||
// Use Euclid's algorithm
|
// Use Euclid's algorithm
|
||||||
let mut m = *self, n = *other;
|
let mut (m, n) = (*self, *other);
|
||||||
while m != 0 {
|
while m != 0 {
|
||||||
let temp = m;
|
let temp = m;
|
||||||
m = n % temp;
|
m = n % temp;
|
||||||
|
@ -237,7 +237,7 @@ impl Integer for $T {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn gcd(&self, other: &$T) -> $T {
|
fn gcd(&self, other: &$T) -> $T {
|
||||||
// Use Euclid's algorithm
|
// Use Euclid's algorithm
|
||||||
let mut m = *self, n = *other;
|
let mut (m, n) = (*self, *other);
|
||||||
while m != 0 {
|
while m != 0 {
|
||||||
let temp = m;
|
let temp = m;
|
||||||
m = n % temp;
|
m = n % temp;
|
||||||
|
@ -658,13 +658,14 @@ impl IsaacRng {
|
|||||||
/// of `rsl` as a seed, otherwise construct one algorithmically (not
|
/// of `rsl` as a seed, otherwise construct one algorithmically (not
|
||||||
/// randomly).
|
/// randomly).
|
||||||
fn init(&mut self, use_rsl: bool) {
|
fn init(&mut self, use_rsl: bool) {
|
||||||
macro_rules! init_mut_many (
|
let mut a = 0x9e3779b9;
|
||||||
($( $var:ident ),* = $val:expr ) => {
|
let mut b = a;
|
||||||
let mut $( $var = $val ),*;
|
let mut c = a;
|
||||||
}
|
let mut d = a;
|
||||||
);
|
let mut e = a;
|
||||||
init_mut_many!(a, b, c, d, e, f, g, h = 0x9e3779b9);
|
let mut f = a;
|
||||||
|
let mut g = a;
|
||||||
|
let mut h = a;
|
||||||
|
|
||||||
macro_rules! mix(
|
macro_rules! mix(
|
||||||
() => {{
|
() => {{
|
||||||
@ -718,7 +719,7 @@ impl IsaacRng {
|
|||||||
fn isaac(&mut self) {
|
fn isaac(&mut self) {
|
||||||
self.c += 1;
|
self.c += 1;
|
||||||
// abbreviations
|
// abbreviations
|
||||||
let mut a = self.a, b = self.b + self.c;
|
let mut (a, b) = (self.a, self.b + self.c);
|
||||||
|
|
||||||
static midpoint: uint = RAND_SIZE as uint / 2;
|
static midpoint: uint = RAND_SIZE as uint / 2;
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ impl Rand for StandardNormal {
|
|||||||
// do-while, so the condition should be true on the first
|
// do-while, so the condition should be true on the first
|
||||||
// run, they get overwritten anyway (0 < 1, so these are
|
// run, they get overwritten anyway (0 < 1, so these are
|
||||||
// good).
|
// good).
|
||||||
let mut x = 1.0, y = 0.0;
|
let mut (x, y) = (1.0, 0.0);
|
||||||
|
|
||||||
// XXX infinities?
|
// XXX infinities?
|
||||||
while -2.0*y < x * x {
|
while -2.0*y < x * x {
|
||||||
|
@ -342,7 +342,7 @@ impl<T: Reader> ReaderByteConversions for T {
|
|||||||
fn read_le_uint_n(&mut self, nbytes: uint) -> u64 {
|
fn read_le_uint_n(&mut self, nbytes: uint) -> u64 {
|
||||||
assert!(nbytes > 0 && nbytes <= 8);
|
assert!(nbytes > 0 && nbytes <= 8);
|
||||||
|
|
||||||
let mut val = 0u64, pos = 0, i = nbytes;
|
let mut (val, pos, i) = (0u64, 0, nbytes);
|
||||||
while i > 0 {
|
while i > 0 {
|
||||||
val += (self.read_u8() as u64) << pos;
|
val += (self.read_u8() as u64) << pos;
|
||||||
pos += 8;
|
pos += 8;
|
||||||
@ -358,7 +358,7 @@ impl<T: Reader> ReaderByteConversions for T {
|
|||||||
fn read_be_uint_n(&mut self, nbytes: uint) -> u64 {
|
fn read_be_uint_n(&mut self, nbytes: uint) -> u64 {
|
||||||
assert!(nbytes > 0 && nbytes <= 8);
|
assert!(nbytes > 0 && nbytes <= 8);
|
||||||
|
|
||||||
let mut val = 0u64, i = nbytes;
|
let mut (val, i) = (0u64, nbytes);
|
||||||
while i > 0 {
|
while i > 0 {
|
||||||
i -= 1;
|
i -= 1;
|
||||||
val += (self.read_u8() as u64) << i * 8;
|
val += (self.read_u8() as u64) << i * 8;
|
||||||
|
@ -242,7 +242,7 @@ pub fn uv_error_to_io_error(uverr: UvError) -> IoError {
|
|||||||
// XXX: Could go in str::raw
|
// XXX: Could go in str::raw
|
||||||
unsafe fn c_str_to_static_slice(s: *libc::c_char) -> &'static str {
|
unsafe fn c_str_to_static_slice(s: *libc::c_char) -> &'static str {
|
||||||
let s = s as *u8;
|
let s = s as *u8;
|
||||||
let mut curr = s, len = 0u;
|
let mut (curr, len) = (s, 0u);
|
||||||
while *curr != 0u8 {
|
while *curr != 0u8 {
|
||||||
len += 1u;
|
len += 1u;
|
||||||
curr = ptr::offset(s, len);
|
curr = ptr::offset(s, len);
|
||||||
|
@ -661,9 +661,9 @@ fn each_split_char_inner<'a>(s: &'a str,
|
|||||||
allow_trailing_empty: bool,
|
allow_trailing_empty: bool,
|
||||||
it: &fn(&'a str) -> bool) -> bool {
|
it: &fn(&'a str) -> bool) -> bool {
|
||||||
if sep < 128u as char {
|
if sep < 128u as char {
|
||||||
let b = sep as u8, l = len(s);
|
let (b, l) = (sep as u8, len(s));
|
||||||
let mut done = 0u;
|
let mut done = 0u;
|
||||||
let mut i = 0u, start = 0u;
|
let mut (i, start) = (0u, 0u);
|
||||||
while i < l && done < count {
|
while i < l && done < count {
|
||||||
if s[i] == b {
|
if s[i] == b {
|
||||||
if allow_empty || start < i {
|
if allow_empty || start < i {
|
||||||
@ -725,7 +725,7 @@ fn each_split_inner<'a>(s: &'a str,
|
|||||||
allow_trailing_empty: bool,
|
allow_trailing_empty: bool,
|
||||||
it: &fn(&'a str) -> bool) -> bool {
|
it: &fn(&'a str) -> bool) -> bool {
|
||||||
let l = len(s);
|
let l = len(s);
|
||||||
let mut i = 0u, start = 0u, done = 0u;
|
let mut (i, start, done) = (0u, 0u, 0u);
|
||||||
while i < l && done < count {
|
while i < l && done < count {
|
||||||
let CharRange {ch, next} = char_range_at(s, i);
|
let CharRange {ch, next} = char_range_at(s, i);
|
||||||
if sepfn(ch) {
|
if sepfn(ch) {
|
||||||
@ -748,9 +748,9 @@ fn each_split_inner<'a>(s: &'a str,
|
|||||||
// See Issue #1932 for why this is a naive search
|
// See Issue #1932 for why this is a naive search
|
||||||
fn iter_matches<'a,'b>(s: &'a str, sep: &'b str,
|
fn iter_matches<'a,'b>(s: &'a str, sep: &'b str,
|
||||||
f: &fn(uint, uint) -> bool) -> bool {
|
f: &fn(uint, uint) -> bool) -> bool {
|
||||||
let sep_len = len(sep), l = len(s);
|
let (sep_len, l) = (len(sep), len(s));
|
||||||
assert!(sep_len > 0u);
|
assert!(sep_len > 0u);
|
||||||
let mut i = 0u, match_start = 0u, match_i = 0u;
|
let mut (i, match_start, match_i) = (0u, 0u, 0u);
|
||||||
|
|
||||||
while i < l {
|
while i < l {
|
||||||
if s[i] == sep[match_i] {
|
if s[i] == sep[match_i] {
|
||||||
@ -977,7 +977,7 @@ pub fn each_split_within<'a>(ss: &'a str,
|
|||||||
* The original string with all occurances of `from` replaced with `to`
|
* The original string with all occurances of `from` replaced with `to`
|
||||||
*/
|
*/
|
||||||
pub fn replace(s: &str, from: &str, to: &str) -> ~str {
|
pub fn replace(s: &str, from: &str, to: &str) -> ~str {
|
||||||
let mut result = ~"", first = true;
|
let mut (result, first) = (~"", true);
|
||||||
for iter_between_matches(s, from) |start, end| {
|
for iter_between_matches(s, from) |start, end| {
|
||||||
if first {
|
if first {
|
||||||
first = false;
|
first = false;
|
||||||
@ -1761,7 +1761,7 @@ pub fn contains_char(haystack: &str, needle: char) -> bool {
|
|||||||
* * needle - The string to look for
|
* * needle - The string to look for
|
||||||
*/
|
*/
|
||||||
pub fn starts_with<'a,'b>(haystack: &'a str, needle: &'b str) -> bool {
|
pub fn starts_with<'a,'b>(haystack: &'a str, needle: &'b str) -> bool {
|
||||||
let haystack_len = len(haystack), needle_len = len(needle);
|
let (haystack_len, needle_len) = (len(haystack), len(needle));
|
||||||
if needle_len == 0u { true }
|
if needle_len == 0u { true }
|
||||||
else if needle_len > haystack_len { false }
|
else if needle_len > haystack_len { false }
|
||||||
else { match_at(haystack, needle, 0u) }
|
else { match_at(haystack, needle, 0u) }
|
||||||
@ -1776,7 +1776,7 @@ pub fn starts_with<'a,'b>(haystack: &'a str, needle: &'b str) -> bool {
|
|||||||
* * needle - The string to look for
|
* * needle - The string to look for
|
||||||
*/
|
*/
|
||||||
pub fn ends_with<'a,'b>(haystack: &'a str, needle: &'b str) -> bool {
|
pub fn ends_with<'a,'b>(haystack: &'a str, needle: &'b str) -> bool {
|
||||||
let haystack_len = len(haystack), needle_len = len(needle);
|
let (haystack_len, needle_len) = (len(haystack), len(needle));
|
||||||
if needle_len == 0u { true }
|
if needle_len == 0u { true }
|
||||||
else if needle_len > haystack_len { false }
|
else if needle_len > haystack_len { false }
|
||||||
else { match_at(haystack, needle, haystack_len - needle_len) }
|
else { match_at(haystack, needle, haystack_len - needle_len) }
|
||||||
@ -1951,7 +1951,7 @@ pub fn with_capacity(capacity: uint) -> ~str {
|
|||||||
pub fn count_chars(s: &str, start: uint, end: uint) -> uint {
|
pub fn count_chars(s: &str, start: uint, end: uint) -> uint {
|
||||||
assert!(is_char_boundary(s, start));
|
assert!(is_char_boundary(s, start));
|
||||||
assert!(is_char_boundary(s, end));
|
assert!(is_char_boundary(s, end));
|
||||||
let mut i = start, len = 0u;
|
let mut (i, len) = (start, 0u);
|
||||||
while i < end {
|
while i < end {
|
||||||
let next = char_range_at(s, i).next;
|
let next = char_range_at(s, i).next;
|
||||||
len += 1u;
|
len += 1u;
|
||||||
@ -1964,7 +1964,7 @@ pub fn count_chars(s: &str, start: uint, end: uint) -> uint {
|
|||||||
/// starting from `start`.
|
/// starting from `start`.
|
||||||
pub fn count_bytes<'b>(s: &'b str, start: uint, n: uint) -> uint {
|
pub fn count_bytes<'b>(s: &'b str, start: uint, n: uint) -> uint {
|
||||||
assert!(is_char_boundary(s, start));
|
assert!(is_char_boundary(s, start));
|
||||||
let mut end = start, cnt = n;
|
let mut (end, cnt) = (start, n);
|
||||||
let l = len(s);
|
let l = len(s);
|
||||||
while cnt > 0u {
|
while cnt > 0u {
|
||||||
assert!(end < l);
|
assert!(end < l);
|
||||||
@ -2300,7 +2300,10 @@ pub fn as_buf<T>(s: &str, f: &fn(*u8, uint) -> T) -> T {
|
|||||||
pub fn subslice_offset(outer: &str, inner: &str) -> uint {
|
pub fn subslice_offset(outer: &str, inner: &str) -> uint {
|
||||||
do as_buf(outer) |a, a_len| {
|
do as_buf(outer) |a, a_len| {
|
||||||
do as_buf(inner) |b, b_len| {
|
do as_buf(inner) |b, b_len| {
|
||||||
let a_start: uint, a_end: uint, b_start: uint, b_end: uint;
|
let a_start: uint;
|
||||||
|
let a_end: uint;
|
||||||
|
let b_start: uint;
|
||||||
|
let b_end: uint;
|
||||||
unsafe {
|
unsafe {
|
||||||
a_start = cast::transmute(a); a_end = a_len + cast::transmute(a);
|
a_start = cast::transmute(a); a_end = a_len + cast::transmute(a);
|
||||||
b_start = cast::transmute(b); b_end = b_len + cast::transmute(b);
|
b_start = cast::transmute(b); b_end = b_len + cast::transmute(b);
|
||||||
@ -2404,7 +2407,7 @@ pub mod raw {
|
|||||||
|
|
||||||
/// Create a Rust string from a null-terminated *u8 buffer
|
/// Create a Rust string from a null-terminated *u8 buffer
|
||||||
pub unsafe fn from_buf(buf: *u8) -> ~str {
|
pub unsafe fn from_buf(buf: *u8) -> ~str {
|
||||||
let mut curr = buf, i = 0u;
|
let mut (curr, i) = (buf, 0u);
|
||||||
while *curr != 0u8 {
|
while *curr != 0u8 {
|
||||||
i += 1u;
|
i += 1u;
|
||||||
curr = ptr::offset(buf, i);
|
curr = ptr::offset(buf, i);
|
||||||
|
@ -53,7 +53,7 @@ impl<A:ToStr> ToStr for (A,) {
|
|||||||
impl<A:ToStr+Hash+Eq, B:ToStr+Hash+Eq> ToStr for HashMap<A, B> {
|
impl<A:ToStr+Hash+Eq, B:ToStr+Hash+Eq> ToStr for HashMap<A, B> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn to_str(&self) -> ~str {
|
fn to_str(&self) -> ~str {
|
||||||
let mut acc = ~"{", first = true;
|
let mut (acc, first) = (~"{", true);
|
||||||
for self.each |key, value| {
|
for self.each |key, value| {
|
||||||
if first {
|
if first {
|
||||||
first = false;
|
first = false;
|
||||||
@ -73,7 +73,7 @@ impl<A:ToStr+Hash+Eq, B:ToStr+Hash+Eq> ToStr for HashMap<A, B> {
|
|||||||
impl<A:ToStr+Hash+Eq> ToStr for HashSet<A> {
|
impl<A:ToStr+Hash+Eq> ToStr for HashSet<A> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn to_str(&self) -> ~str {
|
fn to_str(&self) -> ~str {
|
||||||
let mut acc = ~"{", first = true;
|
let mut (acc, first) = (~"{", true);
|
||||||
for self.each |element| {
|
for self.each |element| {
|
||||||
if first {
|
if first {
|
||||||
first = false;
|
first = false;
|
||||||
@ -121,7 +121,7 @@ impl<A:ToStr,B:ToStr,C:ToStr> ToStr for (A, B, C) {
|
|||||||
impl<'self,A:ToStr> ToStr for &'self [A] {
|
impl<'self,A:ToStr> ToStr for &'self [A] {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn to_str(&self) -> ~str {
|
fn to_str(&self) -> ~str {
|
||||||
let mut acc = ~"[", first = true;
|
let mut (acc, first) = (~"[", true);
|
||||||
for self.each |elt| {
|
for self.each |elt| {
|
||||||
if first {
|
if first {
|
||||||
first = false;
|
first = false;
|
||||||
@ -139,7 +139,7 @@ impl<'self,A:ToStr> ToStr for &'self [A] {
|
|||||||
impl<A:ToStr> ToStr for ~[A] {
|
impl<A:ToStr> ToStr for ~[A] {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn to_str(&self) -> ~str {
|
fn to_str(&self) -> ~str {
|
||||||
let mut acc = ~"[", first = true;
|
let mut (acc, first) = (~"[", true);
|
||||||
for self.each |elt| {
|
for self.each |elt| {
|
||||||
if first {
|
if first {
|
||||||
first = false;
|
first = false;
|
||||||
@ -157,7 +157,7 @@ impl<A:ToStr> ToStr for ~[A] {
|
|||||||
impl<A:ToStr> ToStr for @[A] {
|
impl<A:ToStr> ToStr for @[A] {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn to_str(&self) -> ~str {
|
fn to_str(&self) -> ~str {
|
||||||
let mut acc = ~"[", first = true;
|
let mut (acc, first) = (~"[", true);
|
||||||
for self.each |elt| {
|
for self.each |elt| {
|
||||||
if first {
|
if first {
|
||||||
first = false;
|
first = false;
|
||||||
|
@ -412,7 +412,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_tuple_cmp() {
|
fn test_tuple_cmp() {
|
||||||
let small = (1u, 2u, 3u), big = (3u, 2u, 1u);
|
let (small, big) = ((1u, 2u, 3u), (3u, 2u, 1u));
|
||||||
|
|
||||||
// Eq
|
// Eq
|
||||||
assert_eq!(small, small);
|
assert_eq!(small, small);
|
||||||
|
@ -749,7 +749,7 @@ pub fn truncate<T>(v: &mut ~[T], newlen: uint) {
|
|||||||
pub fn dedup<T:Eq>(v: &mut ~[T]) {
|
pub fn dedup<T:Eq>(v: &mut ~[T]) {
|
||||||
unsafe {
|
unsafe {
|
||||||
if v.len() < 1 { return; }
|
if v.len() < 1 { return; }
|
||||||
let mut last_written = 0, next_to_read = 1;
|
let mut (last_written, next_to_read) = (0, 1);
|
||||||
do as_const_buf(*v) |p, ln| {
|
do as_const_buf(*v) |p, ln| {
|
||||||
// We have a mutable reference to v, so we can make arbitrary
|
// We have a mutable reference to v, so we can make arbitrary
|
||||||
// changes. (cf. push and pop)
|
// changes. (cf. push and pop)
|
||||||
@ -1365,7 +1365,7 @@ pub fn bsearch_elem<T:TotalOrd>(v: &[T], x: &T) -> Option<uint> {
|
|||||||
* Convert a vector of pairs into a pair of vectors, by reference. As unzip().
|
* Convert a vector of pairs into a pair of vectors, by reference. As unzip().
|
||||||
*/
|
*/
|
||||||
pub fn unzip_slice<T:Copy,U:Copy>(v: &[(T, U)]) -> (~[T], ~[U]) {
|
pub fn unzip_slice<T:Copy,U:Copy>(v: &[(T, U)]) -> (~[T], ~[U]) {
|
||||||
let mut ts = ~[], us = ~[];
|
let mut (ts, us) = (~[], ~[]);
|
||||||
for each(v) |p| {
|
for each(v) |p| {
|
||||||
let (t, u) = *p;
|
let (t, u) = *p;
|
||||||
ts.push(t);
|
ts.push(t);
|
||||||
@ -1383,7 +1383,7 @@ pub fn unzip_slice<T:Copy,U:Copy>(v: &[(T, U)]) -> (~[T], ~[U]) {
|
|||||||
* of the i-th tuple of the input vector.
|
* of the i-th tuple of the input vector.
|
||||||
*/
|
*/
|
||||||
pub fn unzip<T,U>(v: ~[(T, U)]) -> (~[T], ~[U]) {
|
pub fn unzip<T,U>(v: ~[(T, U)]) -> (~[T], ~[U]) {
|
||||||
let mut ts = ~[], us = ~[];
|
let mut (ts, us) = (~[], ~[]);
|
||||||
do consume(v) |_i, p| {
|
do consume(v) |_i, p| {
|
||||||
let (t, u) = p;
|
let (t, u) = p;
|
||||||
ts.push(t);
|
ts.push(t);
|
||||||
|
@ -413,7 +413,10 @@ pub type local = spanned<local_>;
|
|||||||
pub type decl = spanned<decl_>;
|
pub type decl = spanned<decl_>;
|
||||||
|
|
||||||
#[deriving(Eq, Encodable, Decodable)]
|
#[deriving(Eq, Encodable, Decodable)]
|
||||||
pub enum decl_ { decl_local(~[@local]), decl_item(@item), }
|
pub enum decl_ {
|
||||||
|
decl_local(@local),
|
||||||
|
decl_item(@item),
|
||||||
|
}
|
||||||
|
|
||||||
#[deriving(Eq, Encodable, Decodable)]
|
#[deriving(Eq, Encodable, Decodable)]
|
||||||
pub struct arm {
|
pub struct arm {
|
||||||
|
@ -279,7 +279,8 @@ pub fn trait_method_to_ty_method(method: &trait_method) -> ty_method {
|
|||||||
|
|
||||||
pub fn split_trait_methods(trait_methods: &[trait_method])
|
pub fn split_trait_methods(trait_methods: &[trait_method])
|
||||||
-> (~[ty_method], ~[@method]) {
|
-> (~[ty_method], ~[@method]) {
|
||||||
let mut reqd = ~[], provd = ~[];
|
let mut reqd = ~[];
|
||||||
|
let mut provd = ~[];
|
||||||
for trait_methods.each |trt_method| {
|
for trait_methods.each |trt_method| {
|
||||||
match *trt_method {
|
match *trt_method {
|
||||||
required(ref tm) => reqd.push(copy *tm),
|
required(ref tm) => reqd.push(copy *tm),
|
||||||
|
@ -385,7 +385,7 @@ impl AstBuilder for @ExtCtxt {
|
|||||||
init: Some(ex),
|
init: Some(ex),
|
||||||
id: self.next_id(),
|
id: self.next_id(),
|
||||||
});
|
});
|
||||||
let decl = respan(sp, ast::decl_local(~[local]));
|
let decl = respan(sp, ast::decl_local(local));
|
||||||
@respan(sp, ast::stmt_decl(@decl, self.next_id()))
|
@respan(sp, ast::stmt_decl(@decl, self.next_id()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -416,7 +416,9 @@ impl<'self> MethodDef<'self> {
|
|||||||
type_ident: ident, generics: &Generics)
|
type_ident: ident, generics: &Generics)
|
||||||
-> (ast::explicit_self, ~[@expr], ~[@expr], ~[(ident, @ast::Ty)]) {
|
-> (ast::explicit_self, ~[@expr], ~[@expr], ~[(ident, @ast::Ty)]) {
|
||||||
|
|
||||||
let mut self_args = ~[], nonself_args = ~[], arg_tys = ~[];
|
let mut self_args = ~[];
|
||||||
|
let mut nonself_args = ~[];
|
||||||
|
let mut arg_tys = ~[];
|
||||||
let mut nonstatic = false;
|
let mut nonstatic = false;
|
||||||
|
|
||||||
let ast_explicit_self = match self.explicit_self {
|
let ast_explicit_self = match self.explicit_self {
|
||||||
@ -522,8 +524,9 @@ impl<'self> MethodDef<'self> {
|
|||||||
nonself_args: &[@expr])
|
nonself_args: &[@expr])
|
||||||
-> @expr {
|
-> @expr {
|
||||||
|
|
||||||
let mut raw_fields = ~[], // ~[[fields of self], [fields of next Self arg], [etc]]
|
let mut raw_fields = ~[]; // ~[[fields of self],
|
||||||
patterns = ~[];
|
// [fields of next Self arg], [etc]]
|
||||||
|
let mut patterns = ~[];
|
||||||
for uint::range(0, self_args.len()) |i| {
|
for uint::range(0, self_args.len()) |i| {
|
||||||
let (pat, ident_expr) = create_struct_pattern(cx, span,
|
let (pat, ident_expr) = create_struct_pattern(cx, span,
|
||||||
type_ident, struct_def,
|
type_ident, struct_def,
|
||||||
|
@ -264,8 +264,8 @@ pub fn create_struct_pattern(cx: @ExtCtxt,
|
|||||||
|
|
||||||
let matching_path = cx.path(span, ~[ struct_ident ]);
|
let matching_path = cx.path(span, ~[ struct_ident ]);
|
||||||
|
|
||||||
let mut paths = ~[], ident_expr = ~[];
|
let mut paths = ~[];
|
||||||
|
let mut ident_expr = ~[];
|
||||||
let mut struct_type = Unknown;
|
let mut struct_type = Unknown;
|
||||||
|
|
||||||
for struct_def.fields.eachi |i, struct_field| {
|
for struct_def.fields.eachi |i, struct_field| {
|
||||||
@ -326,7 +326,8 @@ pub fn create_enum_variant_pattern(cx: @ExtCtxt,
|
|||||||
|
|
||||||
let matching_path = cx.path_ident(span, variant_ident);
|
let matching_path = cx.path_ident(span, variant_ident);
|
||||||
|
|
||||||
let mut paths = ~[], ident_expr = ~[];
|
let mut paths = ~[];
|
||||||
|
let mut ident_expr = ~[];
|
||||||
for uint::range(0, variant_args.len()) |i| {
|
for uint::range(0, variant_args.len()) |i| {
|
||||||
let path = cx.path_ident(span,
|
let path = cx.path_ident(span,
|
||||||
cx.ident_of(fmt!("%s_%u", prefix, i)));
|
cx.ident_of(fmt!("%s_%u", prefix, i)));
|
||||||
|
@ -302,8 +302,9 @@ pub fn expand_stmt(extsbox: @mut SyntaxEnv,
|
|||||||
s: &stmt_,
|
s: &stmt_,
|
||||||
sp: span,
|
sp: span,
|
||||||
fld: @ast_fold,
|
fld: @ast_fold,
|
||||||
orig: @fn(&stmt_, span, @ast_fold) -> (stmt_, span))
|
orig: @fn(&stmt_, span, @ast_fold)
|
||||||
-> (stmt_, span) {
|
-> (Option<stmt_>, span))
|
||||||
|
-> (Option<stmt_>, span) {
|
||||||
let (mac, pth, tts, semi) = match *s {
|
let (mac, pth, tts, semi) = match *s {
|
||||||
stmt_mac(ref mac, semi) => {
|
stmt_mac(ref mac, semi) => {
|
||||||
match mac.node {
|
match mac.node {
|
||||||
@ -342,8 +343,17 @@ pub fn expand_stmt(extsbox: @mut SyntaxEnv,
|
|||||||
};
|
};
|
||||||
|
|
||||||
//keep going, outside-in
|
//keep going, outside-in
|
||||||
let fully_expanded = copy fld.fold_stmt(expanded).node;
|
let fully_expanded = match fld.fold_stmt(expanded) {
|
||||||
|
Some(stmt) => {
|
||||||
|
let fully_expanded = &stmt.node;
|
||||||
cx.bt_pop();
|
cx.bt_pop();
|
||||||
|
copy *fully_expanded
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
cx.span_fatal(pth.span,
|
||||||
|
"macro didn't expand to a statement")
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
(fully_expanded, sp)
|
(fully_expanded, sp)
|
||||||
}
|
}
|
||||||
@ -355,8 +365,8 @@ pub fn expand_stmt(extsbox: @mut SyntaxEnv,
|
|||||||
};
|
};
|
||||||
|
|
||||||
(match fully_expanded {
|
(match fully_expanded {
|
||||||
stmt_expr(e, stmt_id) if semi => stmt_semi(e, stmt_id),
|
stmt_expr(e, stmt_id) if semi => Some(stmt_semi(e, stmt_id)),
|
||||||
_ => { fully_expanded } /* might already have a semi */
|
_ => { Some(fully_expanded) } /* might already have a semi */
|
||||||
}, sp)
|
}, sp)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -26,10 +26,10 @@ pub trait ast_fold {
|
|||||||
fn fold_item_underscore(@self, &item_) -> item_;
|
fn fold_item_underscore(@self, &item_) -> item_;
|
||||||
fn fold_method(@self, @method) -> @method;
|
fn fold_method(@self, @method) -> @method;
|
||||||
fn fold_block(@self, &blk) -> blk;
|
fn fold_block(@self, &blk) -> blk;
|
||||||
fn fold_stmt(@self, &stmt) -> @stmt;
|
fn fold_stmt(@self, &stmt) -> Option<@stmt>;
|
||||||
fn fold_arm(@self, &arm) -> arm;
|
fn fold_arm(@self, &arm) -> arm;
|
||||||
fn fold_pat(@self, @pat) -> @pat;
|
fn fold_pat(@self, @pat) -> @pat;
|
||||||
fn fold_decl(@self, @decl) -> @decl;
|
fn fold_decl(@self, @decl) -> Option<@decl>;
|
||||||
fn fold_expr(@self, @expr) -> @expr;
|
fn fold_expr(@self, @expr) -> @expr;
|
||||||
fn fold_ty(@self, @Ty) -> @Ty;
|
fn fold_ty(@self, @Ty) -> @Ty;
|
||||||
fn fold_mod(@self, &_mod) -> _mod;
|
fn fold_mod(@self, &_mod) -> _mod;
|
||||||
@ -55,10 +55,10 @@ pub struct AstFoldFns {
|
|||||||
fold_item_underscore: @fn(&item_, @ast_fold) -> item_,
|
fold_item_underscore: @fn(&item_, @ast_fold) -> item_,
|
||||||
fold_method: @fn(@method, @ast_fold) -> @method,
|
fold_method: @fn(@method, @ast_fold) -> @method,
|
||||||
fold_block: @fn(&blk_, span, @ast_fold) -> (blk_, span),
|
fold_block: @fn(&blk_, span, @ast_fold) -> (blk_, span),
|
||||||
fold_stmt: @fn(&stmt_, span, @ast_fold) -> (stmt_, span),
|
fold_stmt: @fn(&stmt_, span, @ast_fold) -> (Option<stmt_>, span),
|
||||||
fold_arm: @fn(&arm, @ast_fold) -> arm,
|
fold_arm: @fn(&arm, @ast_fold) -> arm,
|
||||||
fold_pat: @fn(&pat_, span, @ast_fold) -> (pat_, span),
|
fold_pat: @fn(&pat_, span, @ast_fold) -> (pat_, span),
|
||||||
fold_decl: @fn(&decl_, span, @ast_fold) -> (decl_, span),
|
fold_decl: @fn(&decl_, span, @ast_fold) -> (Option<decl_>, span),
|
||||||
fold_expr: @fn(&expr_, span, @ast_fold) -> (expr_, span),
|
fold_expr: @fn(&expr_, span, @ast_fold) -> (expr_, span),
|
||||||
fold_ty: @fn(&ty_, span, @ast_fold) -> (ty_, span),
|
fold_ty: @fn(&ty_, span, @ast_fold) -> (ty_, span),
|
||||||
fold_mod: @fn(&_mod, @ast_fold) -> _mod,
|
fold_mod: @fn(&_mod, @ast_fold) -> _mod,
|
||||||
@ -340,22 +340,39 @@ fn noop_fold_method(m: @method, fld: @ast_fold) -> @method {
|
|||||||
|
|
||||||
|
|
||||||
pub fn noop_fold_block(b: &blk_, fld: @ast_fold) -> blk_ {
|
pub fn noop_fold_block(b: &blk_, fld: @ast_fold) -> blk_ {
|
||||||
|
let view_items = b.view_items.map(|x| fld.fold_view_item(*x));
|
||||||
|
let mut stmts = ~[];
|
||||||
|
for b.stmts.each |stmt| {
|
||||||
|
match fld.fold_stmt(*stmt) {
|
||||||
|
None => {}
|
||||||
|
Some(stmt) => stmts.push(stmt)
|
||||||
|
}
|
||||||
|
}
|
||||||
ast::blk_ {
|
ast::blk_ {
|
||||||
view_items: b.view_items.map(|x| fld.fold_view_item(*x)),
|
view_items: view_items,
|
||||||
stmts: b.stmts.map(|x| fld.fold_stmt(*x)),
|
stmts: stmts,
|
||||||
expr: b.expr.map(|x| fld.fold_expr(*x)),
|
expr: b.expr.map(|x| fld.fold_expr(*x)),
|
||||||
id: fld.new_id(b.id),
|
id: fld.new_id(b.id),
|
||||||
rules: b.rules,
|
rules: b.rules,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn noop_fold_stmt(s: &stmt_, fld: @ast_fold) -> stmt_ {
|
fn noop_fold_stmt(s: &stmt_, fld: @ast_fold) -> Option<stmt_> {
|
||||||
let fold_mac = |x| fold_mac_(x, fld);
|
let fold_mac = |x| fold_mac_(x, fld);
|
||||||
match *s {
|
match *s {
|
||||||
stmt_decl(d, nid) => stmt_decl(fld.fold_decl(d), fld.new_id(nid)),
|
stmt_decl(d, nid) => {
|
||||||
stmt_expr(e, nid) => stmt_expr(fld.fold_expr(e), fld.new_id(nid)),
|
match fld.fold_decl(d) {
|
||||||
stmt_semi(e, nid) => stmt_semi(fld.fold_expr(e), fld.new_id(nid)),
|
Some(d) => Some(stmt_decl(d, fld.new_id(nid))),
|
||||||
stmt_mac(ref mac, semi) => stmt_mac(fold_mac(mac), semi)
|
None => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stmt_expr(e, nid) => {
|
||||||
|
Some(stmt_expr(fld.fold_expr(e), fld.new_id(nid)))
|
||||||
|
}
|
||||||
|
stmt_semi(e, nid) => {
|
||||||
|
Some(stmt_semi(fld.fold_expr(e), fld.new_id(nid)))
|
||||||
|
}
|
||||||
|
stmt_mac(ref mac, semi) => Some(stmt_mac(fold_mac(mac), semi))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -411,13 +428,13 @@ pub fn noop_fold_pat(p: &pat_, fld: @ast_fold) -> pat_ {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn noop_fold_decl(d: &decl_, fld: @ast_fold) -> decl_ {
|
fn noop_fold_decl(d: &decl_, fld: @ast_fold) -> Option<decl_> {
|
||||||
match *d {
|
match *d {
|
||||||
decl_local(ref ls) => decl_local(ls.map(|x| fld.fold_local(*x))),
|
decl_local(ref l) => Some(decl_local(fld.fold_local(*l))),
|
||||||
decl_item(it) => {
|
decl_item(it) => {
|
||||||
match fld.fold_item(it) {
|
match fld.fold_item(it) {
|
||||||
Some(it_folded) => decl_item(it_folded),
|
Some(it_folded) => Some(decl_item(it_folded)),
|
||||||
None => decl_local(~[]),
|
None => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -738,10 +755,10 @@ pub fn default_ast_fold() -> ast_fold_fns {
|
|||||||
fold_item_underscore: noop_fold_item_underscore,
|
fold_item_underscore: noop_fold_item_underscore,
|
||||||
fold_method: noop_fold_method,
|
fold_method: noop_fold_method,
|
||||||
fold_block: wrap(noop_fold_block),
|
fold_block: wrap(noop_fold_block),
|
||||||
fold_stmt: wrap(noop_fold_stmt),
|
fold_stmt: |x, s, fld| (noop_fold_stmt(x, fld), s),
|
||||||
fold_arm: noop_fold_arm,
|
fold_arm: noop_fold_arm,
|
||||||
fold_pat: wrap(noop_fold_pat),
|
fold_pat: wrap(noop_fold_pat),
|
||||||
fold_decl: wrap(noop_fold_decl),
|
fold_decl: |x, s, fld| (noop_fold_decl(x, fld), s),
|
||||||
fold_expr: wrap(noop_fold_expr),
|
fold_expr: wrap(noop_fold_expr),
|
||||||
fold_ty: wrap(noop_fold_ty),
|
fold_ty: wrap(noop_fold_ty),
|
||||||
fold_mod: noop_fold_mod,
|
fold_mod: noop_fold_mod,
|
||||||
@ -799,9 +816,12 @@ impl ast_fold for AstFoldFns {
|
|||||||
let (n, s) = (self.fold_block)(&x.node, x.span, self as @ast_fold);
|
let (n, s) = (self.fold_block)(&x.node, x.span, self as @ast_fold);
|
||||||
spanned { node: n, span: (self.new_span)(s) }
|
spanned { node: n, span: (self.new_span)(s) }
|
||||||
}
|
}
|
||||||
fn fold_stmt(@self, x: &stmt) -> @stmt {
|
fn fold_stmt(@self, x: &stmt) -> Option<@stmt> {
|
||||||
let (n, s) = (self.fold_stmt)(&x.node, x.span, self as @ast_fold);
|
let (n_opt, s) = (self.fold_stmt)(&x.node, x.span, self as @ast_fold);
|
||||||
@spanned { node: n, span: (self.new_span)(s) }
|
match n_opt {
|
||||||
|
Some(n) => Some(@spanned { node: n, span: (self.new_span)(s) }),
|
||||||
|
None => None,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fn fold_arm(@self, x: &arm) -> arm {
|
fn fold_arm(@self, x: &arm) -> arm {
|
||||||
(self.fold_arm)(x, self as @ast_fold)
|
(self.fold_arm)(x, self as @ast_fold)
|
||||||
@ -814,9 +834,12 @@ impl ast_fold for AstFoldFns {
|
|||||||
span: (self.new_span)(s),
|
span: (self.new_span)(s),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn fold_decl(@self, x: @decl) -> @decl {
|
fn fold_decl(@self, x: @decl) -> Option<@decl> {
|
||||||
let (n, s) = (self.fold_decl)(&x.node, x.span, self as @ast_fold);
|
let (n_opt, s) = (self.fold_decl)(&x.node, x.span, self as @ast_fold);
|
||||||
@spanned { node: n, span: (self.new_span)(s) }
|
match n_opt {
|
||||||
|
Some(n) => Some(@spanned { node: n, span: (self.new_span)(s) }),
|
||||||
|
None => None,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fn fold_expr(@self, x: @expr) -> @expr {
|
fn fold_expr(@self, x: @expr) -> @expr {
|
||||||
let (n, s) = (self.fold_expr)(&x.node, x.span, self as @ast_fold);
|
let (n, s) = (self.fold_expr)(&x.node, x.span, self as @ast_fold);
|
||||||
|
@ -58,7 +58,8 @@ pub fn strip_doc_comment_decoration(comment: &str) -> ~str {
|
|||||||
|
|
||||||
/// remove whitespace-only lines from the start/end of lines
|
/// remove whitespace-only lines from the start/end of lines
|
||||||
fn vertical_trim(lines: ~[~str]) -> ~[~str] {
|
fn vertical_trim(lines: ~[~str]) -> ~[~str] {
|
||||||
let mut i = 0u, j = lines.len();
|
let mut i = 0u;
|
||||||
|
let mut j = lines.len();
|
||||||
while i < j && lines[i].trim().is_empty() {
|
while i < j && lines[i].trim().is_empty() {
|
||||||
i += 1u;
|
i += 1u;
|
||||||
}
|
}
|
||||||
|
@ -387,7 +387,10 @@ fn scan_digits(rdr: @mut StringReader, radix: uint) -> ~str {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn scan_number(c: char, rdr: @mut StringReader) -> token::Token {
|
fn scan_number(c: char, rdr: @mut StringReader) -> token::Token {
|
||||||
let mut num_str, base = 10u, c = c, n = nextch(rdr);
|
let mut num_str;
|
||||||
|
let mut base = 10u;
|
||||||
|
let mut c = c;
|
||||||
|
let mut n = nextch(rdr);
|
||||||
if c == '0' && n == 'x' {
|
if c == '0' && n == 'x' {
|
||||||
bump(rdr);
|
bump(rdr);
|
||||||
bump(rdr);
|
bump(rdr);
|
||||||
@ -510,7 +513,8 @@ fn scan_number(c: char, rdr: @mut StringReader) -> token::Token {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn scan_numeric_escape(rdr: @mut StringReader, n_hex_digits: uint) -> char {
|
fn scan_numeric_escape(rdr: @mut StringReader, n_hex_digits: uint) -> char {
|
||||||
let mut accum_int = 0, i = n_hex_digits;
|
let mut accum_int = 0;
|
||||||
|
let mut i = n_hex_digits;
|
||||||
while i != 0u {
|
while i != 0u {
|
||||||
let n = rdr.curr;
|
let n = rdr.curr;
|
||||||
bump(rdr);
|
bump(rdr);
|
||||||
|
@ -64,6 +64,7 @@ pub enum ObsoleteSyntax {
|
|||||||
ObsoleteConstItem,
|
ObsoleteConstItem,
|
||||||
ObsoleteFixedLengthVectorType,
|
ObsoleteFixedLengthVectorType,
|
||||||
ObsoleteNamedExternModule,
|
ObsoleteNamedExternModule,
|
||||||
|
ObsoleteMultipleLocalDecl,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl to_bytes::IterBytes for ObsoleteSyntax {
|
impl to_bytes::IterBytes for ObsoleteSyntax {
|
||||||
@ -224,6 +225,11 @@ impl Parser {
|
|||||||
"instead of `extern mod foo { ... }`, write `mod foo { \
|
"instead of `extern mod foo { ... }`, write `mod foo { \
|
||||||
extern { ... } }`"
|
extern { ... } }`"
|
||||||
),
|
),
|
||||||
|
ObsoleteMultipleLocalDecl => (
|
||||||
|
"declaration of multiple locals at once",
|
||||||
|
"instead of e.g. `let a = 1, b = 2`, write \
|
||||||
|
`let (a, b) = (1, 2)`."
|
||||||
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
self.report(sp, kind, kind_str, desc);
|
self.report(sp, kind, kind_str, desc);
|
||||||
|
@ -84,7 +84,7 @@ use parse::obsolete::ObsoleteMode;
|
|||||||
use parse::obsolete::{ObsoleteLifetimeNotation, ObsoleteConstManagedPointer};
|
use parse::obsolete::{ObsoleteLifetimeNotation, ObsoleteConstManagedPointer};
|
||||||
use parse::obsolete::{ObsoletePurity, ObsoleteStaticMethod};
|
use parse::obsolete::{ObsoletePurity, ObsoleteStaticMethod};
|
||||||
use parse::obsolete::{ObsoleteConstItem, ObsoleteFixedLengthVectorType};
|
use parse::obsolete::{ObsoleteConstItem, ObsoleteFixedLengthVectorType};
|
||||||
use parse::obsolete::{ObsoleteNamedExternModule};
|
use parse::obsolete::{ObsoleteNamedExternModule, ObsoleteMultipleLocalDecl};
|
||||||
use parse::token::{can_begin_expr, is_ident, is_ident_or_path};
|
use parse::token::{can_begin_expr, is_ident, is_ident_or_path};
|
||||||
use parse::token::{is_plain_ident, INTERPOLATED, keywords, special_idents, token_to_binop};
|
use parse::token::{is_plain_ident, INTERPOLATED, keywords, special_idents, token_to_binop};
|
||||||
use parse::token;
|
use parse::token;
|
||||||
@ -2573,11 +2573,12 @@ impl Parser {
|
|||||||
fn parse_let(&self) -> @decl {
|
fn parse_let(&self) -> @decl {
|
||||||
let is_mutbl = self.eat_keyword(keywords::Mut);
|
let is_mutbl = self.eat_keyword(keywords::Mut);
|
||||||
let lo = self.span.lo;
|
let lo = self.span.lo;
|
||||||
let mut locals = ~[self.parse_local(is_mutbl)];
|
let mut local = self.parse_local(is_mutbl);
|
||||||
while self.eat(&token::COMMA) {
|
while self.eat(&token::COMMA) {
|
||||||
locals.push(self.parse_local(is_mutbl));
|
let _ = self.parse_local(is_mutbl);
|
||||||
|
self.obsolete(*self.span, ObsoleteMultipleLocalDecl);
|
||||||
}
|
}
|
||||||
return @spanned(lo, self.last_span.hi, decl_local(locals));
|
return @spanned(lo, self.last_span.hi, decl_local(local));
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse a structure field
|
// parse a structure field
|
||||||
@ -3840,15 +3841,18 @@ impl Parser {
|
|||||||
// parse the part of an "enum" decl following the '{'
|
// parse the part of an "enum" decl following the '{'
|
||||||
fn parse_enum_def(&self, _generics: &ast::Generics) -> enum_def {
|
fn parse_enum_def(&self, _generics: &ast::Generics) -> enum_def {
|
||||||
let mut variants = ~[];
|
let mut variants = ~[];
|
||||||
let mut all_nullary = true, have_disr = false;
|
let mut all_nullary = true;
|
||||||
|
let mut have_disr = false;
|
||||||
while *self.token != token::RBRACE {
|
while *self.token != token::RBRACE {
|
||||||
let variant_attrs = self.parse_outer_attributes();
|
let variant_attrs = self.parse_outer_attributes();
|
||||||
let vlo = self.span.lo;
|
let vlo = self.span.lo;
|
||||||
|
|
||||||
let vis = self.parse_visibility();
|
let vis = self.parse_visibility();
|
||||||
|
|
||||||
let ident, kind;
|
let ident;
|
||||||
let mut args = ~[], disr_expr = None;
|
let kind;
|
||||||
|
let mut args = ~[];
|
||||||
|
let mut disr_expr = None;
|
||||||
ident = self.parse_ident();
|
ident = self.parse_ident();
|
||||||
if self.eat(&token::LBRACE) {
|
if self.eat(&token::LBRACE) {
|
||||||
// Parse a struct variant.
|
// Parse a struct variant.
|
||||||
@ -4352,7 +4356,8 @@ impl Parser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn is_view_item(&self) -> bool {
|
fn is_view_item(&self) -> bool {
|
||||||
let tok, next_tok;
|
let tok;
|
||||||
|
let next_tok;
|
||||||
if !self.is_keyword(keywords::Pub) && !self.is_keyword(keywords::Priv) {
|
if !self.is_keyword(keywords::Pub) && !self.is_keyword(keywords::Priv) {
|
||||||
tok = copy *self.token;
|
tok = copy *self.token;
|
||||||
next_tok = self.look_ahead(1);
|
next_tok = self.look_ahead(1);
|
||||||
|
@ -1444,14 +1444,12 @@ pub fn print_local_decl(s: @ps, loc: @ast::local) {
|
|||||||
pub fn print_decl(s: @ps, decl: @ast::decl) {
|
pub fn print_decl(s: @ps, decl: @ast::decl) {
|
||||||
maybe_print_comment(s, decl.span.lo);
|
maybe_print_comment(s, decl.span.lo);
|
||||||
match decl.node {
|
match decl.node {
|
||||||
ast::decl_local(ref locs) => {
|
ast::decl_local(ref loc) => {
|
||||||
space_if_not_bol(s);
|
space_if_not_bol(s);
|
||||||
ibox(s, indent_unit);
|
ibox(s, indent_unit);
|
||||||
word_nbsp(s, "let");
|
word_nbsp(s, "let");
|
||||||
|
|
||||||
// if any are mut, all are mut
|
if loc.node.is_mutbl {
|
||||||
if locs.any(|l| l.node.is_mutbl) {
|
|
||||||
assert!(locs.all(|l| l.node.is_mutbl));
|
|
||||||
word_nbsp(s, "mut");
|
word_nbsp(s, "mut");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1468,7 +1466,8 @@ pub fn print_decl(s: @ps, decl: @ast::decl) {
|
|||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
commasep(s, consistent, *locs, print_local);
|
|
||||||
|
print_local(s, *loc);
|
||||||
end(s);
|
end(s);
|
||||||
}
|
}
|
||||||
ast::decl_item(item) => print_item(s, item)
|
ast::decl_item(item) => print_item(s, item)
|
||||||
|
@ -430,11 +430,7 @@ pub fn visit_stmt<E>(s: @stmt, e: E, v: vt<E>) {
|
|||||||
|
|
||||||
pub fn visit_decl<E: Copy>(d: @decl, e: E, v: vt<E>) {
|
pub fn visit_decl<E: Copy>(d: @decl, e: E, v: vt<E>) {
|
||||||
match d.node {
|
match d.node {
|
||||||
decl_local(ref locs) => {
|
decl_local(ref loc) => (v.visit_local)(*loc, e, v),
|
||||||
for locs.each |loc| {
|
|
||||||
(v.visit_local)(*loc, e, v)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
decl_item(it) => (v.visit_item)(it, e, v)
|
decl_item(it) => (v.visit_item)(it, e, v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,9 @@ fn fannkuch_redux(n: i32) -> i32 {
|
|||||||
let mut perm = vec::from_elem(n as uint, 0i32);
|
let mut perm = vec::from_elem(n as uint, 0i32);
|
||||||
let mut perm1 = vec::from_fn(n as uint, |i| i as i32);
|
let mut perm1 = vec::from_fn(n as uint, |i| i as i32);
|
||||||
let mut count = vec::from_elem(n as uint, 0i32);
|
let mut count = vec::from_elem(n as uint, 0i32);
|
||||||
let mut max_flips_count = 0i32, perm_count = 0i32, checksum = 0i32;
|
let mut max_flips_count = 0i32;
|
||||||
|
let mut perm_count = 0i32;
|
||||||
|
let mut checksum = 0i32;
|
||||||
|
|
||||||
let mut r = n;
|
let mut r = n;
|
||||||
loop {
|
loop {
|
||||||
|
@ -99,7 +99,9 @@ impl RepeatFasta {
|
|||||||
alu,
|
alu,
|
||||||
LINE_LEN);
|
LINE_LEN);
|
||||||
|
|
||||||
let mut pos = 0, bytes, n = n;
|
let mut pos = 0;
|
||||||
|
let mut bytes;
|
||||||
|
let mut n = n;
|
||||||
while n > 0 {
|
while n > 0 {
|
||||||
bytes = min(LINE_LEN, n);
|
bytes = min(LINE_LEN, n);
|
||||||
fwrite(transmute(&buf[pos]), bytes as size_t, 1, stdout);
|
fwrite(transmute(&buf[pos]), bytes as size_t, 1, stdout);
|
||||||
@ -158,7 +160,8 @@ impl RandomFasta {
|
|||||||
|
|
||||||
fn make(&mut self, n: uint) {
|
fn make(&mut self, n: uint) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let lines = n / LINE_LEN, chars_left = n % LINE_LEN;
|
let lines = n / LINE_LEN;
|
||||||
|
let chars_left = n % LINE_LEN;
|
||||||
let mut buf = [0, ..LINE_LEN + 1];
|
let mut buf = [0, ..LINE_LEN + 1];
|
||||||
|
|
||||||
for lines.times {
|
for lines.times {
|
||||||
|
@ -10,7 +10,8 @@ static LIMIT: f64 = 2.0;
|
|||||||
#[fixed_stack_segment]
|
#[fixed_stack_segment]
|
||||||
fn main() {
|
fn main() {
|
||||||
unsafe {
|
unsafe {
|
||||||
let w: i32 = FromStr::from_str(os::args()[1]).get(), h = w;
|
let w: i32 = FromStr::from_str(os::args()[1]).get();
|
||||||
|
let h = w;
|
||||||
let mut byte_acc: i8 = 0;
|
let mut byte_acc: i8 = 0;
|
||||||
let mut bit_num: i32 = 0;
|
let mut bit_num: i32 = 0;
|
||||||
|
|
||||||
|
@ -92,7 +92,8 @@ fn advance(bodies: &mut [Planet, ..N_BODIES], dt: f64, steps: i32) {
|
|||||||
let d2 = d[0]*d[0] + d[1]*d[1] + d[2]*d[2];
|
let d2 = d[0]*d[0] + d[1]*d[1] + d[2]*d[2];
|
||||||
let mag = dt / (d2 * f64::sqrt(d2));
|
let mag = dt / (d2 * f64::sqrt(d2));
|
||||||
|
|
||||||
let a_mass = bodies[i].mass, b_mass = bodies[j].mass;
|
let a_mass = bodies[i].mass;
|
||||||
|
let b_mass = bodies[j].mass;
|
||||||
bodies[i].v[0] -= d[0] * b_mass * mag;
|
bodies[i].v[0] -= d[0] * b_mass * mag;
|
||||||
bodies[i].v[1] -= d[1] * b_mass * mag;
|
bodies[i].v[1] -= d[1] * b_mass * mag;
|
||||||
bodies[i].v[2] -= d[2] * b_mass * mag;
|
bodies[i].v[2] -= d[2] * b_mass * mag;
|
||||||
|
@ -45,7 +45,9 @@ fn mult_AtAv(v: &mut [f64], out: &mut [f64], tmp: &mut [f64]) {
|
|||||||
#[fixed_stack_segment]
|
#[fixed_stack_segment]
|
||||||
fn main() {
|
fn main() {
|
||||||
let n: uint = FromStr::from_str(os::args()[1]).get();
|
let n: uint = FromStr::from_str(os::args()[1]).get();
|
||||||
let mut u = vec::from_elem(n, 1f64), v = u.clone(), tmp = u.clone();
|
let mut u = vec::from_elem(n, 1f64);
|
||||||
|
let mut v = u.clone();
|
||||||
|
let mut tmp = u.clone();
|
||||||
for 8.times {
|
for 8.times {
|
||||||
mult_AtAv(u, v, tmp);
|
mult_AtAv(u, v, tmp);
|
||||||
mult_AtAv(v, u, tmp);
|
mult_AtAv(v, u, tmp);
|
||||||
|
@ -49,7 +49,8 @@ fn block_overarching_alias_mut() {
|
|||||||
fn loop_aliased_mut() {
|
fn loop_aliased_mut() {
|
||||||
// In this instance, the borrow is carried through the loop.
|
// In this instance, the borrow is carried through the loop.
|
||||||
|
|
||||||
let mut v = ~3, w = ~4;
|
let mut v = ~3;
|
||||||
|
let mut w = ~4;
|
||||||
let mut _x = &w;
|
let mut _x = &w;
|
||||||
loop {
|
loop {
|
||||||
borrow_mut(v); //~ ERROR cannot borrow
|
borrow_mut(v); //~ ERROR cannot borrow
|
||||||
@ -60,7 +61,8 @@ fn loop_aliased_mut() {
|
|||||||
fn while_aliased_mut() {
|
fn while_aliased_mut() {
|
||||||
// In this instance, the borrow is carried through the loop.
|
// In this instance, the borrow is carried through the loop.
|
||||||
|
|
||||||
let mut v = ~3, w = ~4;
|
let mut v = ~3;
|
||||||
|
let mut w = ~4;
|
||||||
let mut _x = &w;
|
let mut _x = &w;
|
||||||
while cond() {
|
while cond() {
|
||||||
borrow_mut(v); //~ ERROR cannot borrow
|
borrow_mut(v); //~ ERROR cannot borrow
|
||||||
@ -71,7 +73,8 @@ fn while_aliased_mut() {
|
|||||||
fn for_loop_aliased_mut() {
|
fn for_loop_aliased_mut() {
|
||||||
// In this instance, the borrow is carried through the loop.
|
// In this instance, the borrow is carried through the loop.
|
||||||
|
|
||||||
let mut v = ~3, w = ~4;
|
let mut v = ~3;
|
||||||
|
let mut w = ~4;
|
||||||
let mut _x = &w;
|
let mut _x = &w;
|
||||||
for for_func {
|
for for_func {
|
||||||
borrow_mut(v); //~ ERROR cannot borrow
|
borrow_mut(v); //~ ERROR cannot borrow
|
||||||
@ -82,7 +85,8 @@ fn for_loop_aliased_mut() {
|
|||||||
fn loop_aliased_mut_break() {
|
fn loop_aliased_mut_break() {
|
||||||
// In this instance, the borrow is carried through the loop.
|
// In this instance, the borrow is carried through the loop.
|
||||||
|
|
||||||
let mut v = ~3, w = ~4;
|
let mut v = ~3;
|
||||||
|
let mut w = ~4;
|
||||||
let mut _x = &w;
|
let mut _x = &w;
|
||||||
loop {
|
loop {
|
||||||
borrow_mut(v);
|
borrow_mut(v);
|
||||||
@ -95,7 +99,8 @@ fn loop_aliased_mut_break() {
|
|||||||
fn while_aliased_mut_break() {
|
fn while_aliased_mut_break() {
|
||||||
// In this instance, the borrow is carried through the loop.
|
// In this instance, the borrow is carried through the loop.
|
||||||
|
|
||||||
let mut v = ~3, w = ~4;
|
let mut v = ~3;
|
||||||
|
let mut w = ~4;
|
||||||
let mut _x = &w;
|
let mut _x = &w;
|
||||||
while cond() {
|
while cond() {
|
||||||
borrow_mut(v);
|
borrow_mut(v);
|
||||||
@ -108,7 +113,8 @@ fn while_aliased_mut_break() {
|
|||||||
fn for_aliased_mut_break() {
|
fn for_aliased_mut_break() {
|
||||||
// In this instance, the borrow is carried through the loop.
|
// In this instance, the borrow is carried through the loop.
|
||||||
|
|
||||||
let mut v = ~3, w = ~4;
|
let mut v = ~3;
|
||||||
|
let mut w = ~4;
|
||||||
let mut _x = &w;
|
let mut _x = &w;
|
||||||
for for_func {
|
for for_func {
|
||||||
// here we cannot be sure that `for_func` respects the break below
|
// here we cannot be sure that `for_func` respects the break below
|
||||||
@ -120,7 +126,8 @@ fn for_aliased_mut_break() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn while_aliased_mut_cond(cond: bool, cond2: bool) {
|
fn while_aliased_mut_cond(cond: bool, cond2: bool) {
|
||||||
let mut v = ~3, w = ~4;
|
let mut v = ~3;
|
||||||
|
let mut w = ~4;
|
||||||
let mut x = &mut w;
|
let mut x = &mut w;
|
||||||
while cond {
|
while cond {
|
||||||
**x += 1;
|
**x += 1;
|
||||||
|
@ -48,13 +48,15 @@ fn aliased_mut() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn aliased_other() {
|
fn aliased_other() {
|
||||||
let mut v = ~3, w = ~4;
|
let mut v = ~3;
|
||||||
|
let mut w = ~4;
|
||||||
let _x = &mut w;
|
let _x = &mut w;
|
||||||
borrow(v);
|
borrow(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn aliased_other_reassign() {
|
fn aliased_other_reassign() {
|
||||||
let mut v = ~3, w = ~4;
|
let mut v = ~3;
|
||||||
|
let mut w = ~4;
|
||||||
let mut _x = &mut w;
|
let mut _x = &mut w;
|
||||||
_x = &mut v;
|
_x = &mut v;
|
||||||
borrow(v); //~ ERROR cannot borrow `*v`
|
borrow(v); //~ ERROR cannot borrow `*v`
|
||||||
|
@ -23,8 +23,8 @@ fn siphash(k0 : u64, k1 : u64) -> siphash {
|
|||||||
|
|
||||||
fn mk_result(st : SipState) -> u64 {
|
fn mk_result(st : SipState) -> u64 {
|
||||||
|
|
||||||
let v0 = st.v0,
|
let v0 = st.v0;
|
||||||
v1 = st.v1;
|
let v1 = st.v1;
|
||||||
return v0 ^ v1;
|
return v0 ^ v1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
// negative cases
|
// negative cases
|
||||||
let mut a = 3; //~ ERROR: variable does not need to be mutable
|
let mut a = 3; //~ ERROR: variable does not need to be mutable
|
||||||
let mut a = 2, b = 3; //~ ERROR: variable does not need to be mutable
|
let mut a = 2; //~ ERROR: variable does not need to be mutable
|
||||||
//~^ ERROR: variable does not need to be mutable
|
let mut b = 3; //~ ERROR: variable does not need to be mutable
|
||||||
let mut a = ~[3]; //~ ERROR: variable does not need to be mutable
|
let mut a = ~[3]; //~ ERROR: variable does not need to be mutable
|
||||||
|
|
||||||
// positive cases
|
// positive cases
|
||||||
|
@ -26,7 +26,8 @@ fn f21() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn f30(cond: bool) {
|
fn f30(cond: bool) {
|
||||||
let x = ~"hi", y = ~"ho";
|
let x = ~"hi";
|
||||||
|
let y = ~"ho";
|
||||||
let _y = if cond {
|
let _y = if cond {
|
||||||
x
|
x
|
||||||
} else {
|
} else {
|
||||||
@ -37,7 +38,8 @@ fn f30(cond: bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn f40(cond: bool) {
|
fn f40(cond: bool) {
|
||||||
let x = ~"hi", y = ~"ho";
|
let x = ~"hi";
|
||||||
|
let y = ~"ho";
|
||||||
let _y = match cond {
|
let _y = match cond {
|
||||||
true => x,
|
true => x,
|
||||||
false => y
|
false => y
|
||||||
@ -47,7 +49,8 @@ fn f40(cond: bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn f50(cond: bool) {
|
fn f50(cond: bool) {
|
||||||
let x = ~"hi", y = ~"ho";
|
let x = ~"hi";
|
||||||
|
let y = ~"ho";
|
||||||
let _y = match cond {
|
let _y = match cond {
|
||||||
_ if guard(x) => 10,
|
_ if guard(x) => 10,
|
||||||
true => 10,
|
true => 10,
|
||||||
|
@ -10,7 +10,8 @@
|
|||||||
|
|
||||||
// error-pattern:so long
|
// error-pattern:so long
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = ~[], y = ~[3];
|
let x = ~[];
|
||||||
|
let y = ~[3];
|
||||||
fail!("so long");
|
fail!("so long");
|
||||||
x += y;
|
x += y;
|
||||||
~"good" + ~"bye";
|
~"good" + ~"bye";
|
||||||
|
@ -31,7 +31,10 @@ fn enum_uints(start: uint, end: uint) -> ~[uint] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let a = 'a' as u8, j = 'j' as u8, k = 1, l = 9;
|
let a = 'a' as u8;
|
||||||
|
let j = 'j' as u8;
|
||||||
|
let k = 1;
|
||||||
|
let l = 9;
|
||||||
let chars = enum_chars(a, j);
|
let chars = enum_chars(a, j);
|
||||||
let ints = enum_uints(k, l);
|
let ints = enum_uints(k, l);
|
||||||
|
|
||||||
|
@ -24,7 +24,9 @@ fn f1(a: &mut X, b: &mut int, c: int) -> int {
|
|||||||
fn f2(a: int, f: &fn(int)) -> int { f(1); return a; }
|
fn f2(a: int, f: &fn(int)) -> int { f(1); return a; }
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let mut a = X {x: 1}, b = 2, c = 3;
|
let mut a = X {x: 1};
|
||||||
|
let mut b = 2;
|
||||||
|
let mut c = 3;
|
||||||
assert_eq!(f1(&mut a, &mut b, c), 6);
|
assert_eq!(f1(&mut a, &mut b, c), 6);
|
||||||
assert_eq!(a.x, 0);
|
assert_eq!(a.x, 0);
|
||||||
assert_eq!(b, 10);
|
assert_eq!(b, 10);
|
||||||
|
@ -17,7 +17,8 @@ fn testfn(cond: bool) {
|
|||||||
// borrow x and y
|
// borrow x and y
|
||||||
let mut r_x = &*x;
|
let mut r_x = &*x;
|
||||||
let mut r_y = &*y;
|
let mut r_y = &*y;
|
||||||
let mut r = r_x, exp = 3;
|
let mut r = r_x;
|
||||||
|
let mut exp = 3;
|
||||||
|
|
||||||
if cond {
|
if cond {
|
||||||
r = r_y;
|
r = r_y;
|
||||||
|
@ -16,7 +16,11 @@ enum E<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let e0 = E0, e11 = E1(1), e12 = E1(2), e21 = E2(1,1), e22 = E2(1, 2);
|
let e0 = E0;
|
||||||
|
let e11 = E1(1);
|
||||||
|
let e12 = E1(2);
|
||||||
|
let e21 = E2(1, 1);
|
||||||
|
let e22 = E2(1, 2);
|
||||||
|
|
||||||
// in order for both Ord and TotalOrd
|
// in order for both Ord and TotalOrd
|
||||||
let es = [e0, e11, e12, e21, e22];
|
let es = [e0, e11, e12, e21, e22];
|
||||||
@ -26,8 +30,10 @@ pub fn main() {
|
|||||||
let ord = i.cmp(&j);
|
let ord = i.cmp(&j);
|
||||||
|
|
||||||
let eq = i == j;
|
let eq = i == j;
|
||||||
let lt = i < j, le = i <= j;
|
let lt = i < j;
|
||||||
let gt = i > j, ge = i >= j;
|
let le = i <= j;
|
||||||
|
let gt = i > j;
|
||||||
|
let ge = i >= j;
|
||||||
|
|
||||||
// Eq
|
// Eq
|
||||||
assert_eq!(*e1 == *e2, eq);
|
assert_eq!(*e1 == *e2, eq);
|
||||||
|
@ -15,7 +15,8 @@ struct S<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let s1 = S {x: 1, y: 1}, s2 = S {x: 1, y: 2};
|
let s1 = S {x: 1, y: 1};
|
||||||
|
let s2 = S {x: 1, y: 2};
|
||||||
|
|
||||||
// in order for both Ord and TotalOrd
|
// in order for both Ord and TotalOrd
|
||||||
let ss = [s1, s2];
|
let ss = [s1, s2];
|
||||||
@ -25,8 +26,10 @@ pub fn main() {
|
|||||||
let ord = i.cmp(&j);
|
let ord = i.cmp(&j);
|
||||||
|
|
||||||
let eq = i == j;
|
let eq = i == j;
|
||||||
let lt = i < j, le = i <= j;
|
let lt = i < j;
|
||||||
let gt = i > j, ge = i >= j;
|
let le = i <= j;
|
||||||
|
let gt = i > j;
|
||||||
|
let ge = i >= j;
|
||||||
|
|
||||||
// Eq
|
// Eq
|
||||||
assert_eq!(*s1 == *s2, eq);
|
assert_eq!(*s1 == *s2, eq);
|
||||||
|
@ -13,7 +13,8 @@ struct TS<T>(T,T);
|
|||||||
|
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let ts1 = TS(1, 1), ts2 = TS(1,2);
|
let ts1 = TS(1, 1);
|
||||||
|
let ts2 = TS(1, 2);
|
||||||
|
|
||||||
// in order for both Ord and TotalOrd
|
// in order for both Ord and TotalOrd
|
||||||
let tss = [ts1, ts2];
|
let tss = [ts1, ts2];
|
||||||
@ -23,8 +24,10 @@ pub fn main() {
|
|||||||
let ord = i.cmp(&j);
|
let ord = i.cmp(&j);
|
||||||
|
|
||||||
let eq = i == j;
|
let eq = i == j;
|
||||||
let lt = i < j, le = i <= j;
|
let lt = i < j;
|
||||||
let gt = i > j, ge = i >= j;
|
let le = i <= j;
|
||||||
|
let gt = i > j;
|
||||||
|
let ge = i >= j;
|
||||||
|
|
||||||
// Eq
|
// Eq
|
||||||
assert_eq!(*ts1 == *ts2, eq);
|
assert_eq!(*ts1 == *ts2, eq);
|
||||||
|
@ -14,7 +14,8 @@ struct A<'self> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let a = A { x: &1 }, b = A { x: &2 };
|
let a = A { x: &1 };
|
||||||
|
let b = A { x: &2 };
|
||||||
|
|
||||||
assert_eq!(a, a);
|
assert_eq!(a, a);
|
||||||
assert_eq!(b, b);
|
assert_eq!(b, b);
|
||||||
|
@ -8,4 +8,9 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
pub fn main() { let x = 10, y = x; assert!((y == 10)); }
|
pub fn main() {
|
||||||
|
let x = 10;
|
||||||
|
let y = x;
|
||||||
|
assert!((y == 10));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,8 @@ fn magic2(x: @int) { debug!(x); }
|
|||||||
struct A { a: @int }
|
struct A { a: @int }
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let a = A {a: @10}, b = @10;
|
let a = A {a: @10};
|
||||||
|
let b = @10;
|
||||||
magic(a); magic(A {a: @20});
|
magic(a); magic(A {a: @20});
|
||||||
magic2(b); magic2(@20);
|
magic2(b); magic2(@20);
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,8 @@
|
|||||||
// Check that functions can modify local state.
|
// Check that functions can modify local state.
|
||||||
|
|
||||||
fn sums_to(v: ~[int], sum: int) -> bool {
|
fn sums_to(v: ~[int], sum: int) -> bool {
|
||||||
let mut i = 0u, sum0 = 0;
|
let mut i = 0u;
|
||||||
|
let mut sum0 = 0;
|
||||||
while i < v.len() {
|
while i < v.len() {
|
||||||
sum0 += v[i];
|
sum0 += v[i];
|
||||||
i += 1u;
|
i += 1u;
|
||||||
@ -20,7 +21,8 @@ fn sums_to(v: ~[int], sum: int) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn sums_to_using_uniq(v: ~[int], sum: int) -> bool {
|
fn sums_to_using_uniq(v: ~[int], sum: int) -> bool {
|
||||||
let mut i = 0u, sum0 = ~0;
|
let mut i = 0u;
|
||||||
|
let mut sum0 = ~0;
|
||||||
while i < v.len() {
|
while i < v.len() {
|
||||||
*sum0 += v[i];
|
*sum0 += v[i];
|
||||||
i += 1u;
|
i += 1u;
|
||||||
@ -29,7 +31,8 @@ fn sums_to_using_uniq(v: ~[int], sum: int) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn sums_to_using_rec(v: ~[int], sum: int) -> bool {
|
fn sums_to_using_rec(v: ~[int], sum: int) -> bool {
|
||||||
let mut i = 0u, sum0 = F {f: 0};
|
let mut i = 0u;
|
||||||
|
let mut sum0 = F {f: 0};
|
||||||
while i < v.len() {
|
while i < v.len() {
|
||||||
sum0.f += v[i];
|
sum0.f += v[i];
|
||||||
i += 1u;
|
i += 1u;
|
||||||
@ -40,7 +43,8 @@ fn sums_to_using_rec(v: ~[int], sum: int) -> bool {
|
|||||||
struct F<T> { f: T }
|
struct F<T> { f: T }
|
||||||
|
|
||||||
fn sums_to_using_uniq_rec(v: ~[int], sum: int) -> bool {
|
fn sums_to_using_uniq_rec(v: ~[int], sum: int) -> bool {
|
||||||
let mut i = 0u, sum0 = F {f: ~0};
|
let mut i = 0u;
|
||||||
|
let mut sum0 = F {f: ~0};
|
||||||
while i < v.len() {
|
while i < v.len() {
|
||||||
*sum0.f += v[i];
|
*sum0.f += v[i];
|
||||||
i += 1u;
|
i += 1u;
|
||||||
|
@ -14,7 +14,8 @@ use std::cmp::Eq;
|
|||||||
use std::vec;
|
use std::vec;
|
||||||
|
|
||||||
fn iter<T>(v: ~[T], it: &fn(&T) -> bool) -> bool {
|
fn iter<T>(v: ~[T], it: &fn(&T) -> bool) -> bool {
|
||||||
let mut i = 0u, l = v.len();
|
let mut i = 0u;
|
||||||
|
let mut l = v.len();
|
||||||
while i < l {
|
while i < l {
|
||||||
if !it(&v[i]) { return false; }
|
if !it(&v[i]) { return false; }
|
||||||
i += 1u;
|
i += 1u;
|
||||||
|
@ -8,4 +8,8 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
pub fn main() { let x = 10, y = 20; let z = x + y; assert!((z == 30)); }
|
pub fn main() {
|
||||||
|
let (x, y) = (10, 20);
|
||||||
|
let z = x + y;
|
||||||
|
assert!((z == 30));
|
||||||
|
}
|
||||||
|
@ -30,7 +30,10 @@ fn enum_uints(start: uint, end: uint) -> ~[uint] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let a = 'a' as u8, j = 'j' as u8, k = 1u, l = 10u;
|
let a = 'a' as u8;
|
||||||
|
let j = 'j' as u8;
|
||||||
|
let k = 1u;
|
||||||
|
let l = 10u;
|
||||||
let chars = enum_chars(a, j);
|
let chars = enum_chars(a, j);
|
||||||
let ints = enum_uints(k, l);
|
let ints = enum_uints(k, l);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user