Merge remote-tracking branch 'mozilla/master' into incoming
Conflicts: src/librustc/middle/astencode.rs src/librustc/middle/check_const.rs
This commit is contained in:
commit
5d3ca4b843
137 changed files with 2252 additions and 1559 deletions
1
src/test/auxiliary/static_mut_xc.rs
Normal file
1
src/test/auxiliary/static_mut_xc.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
pub static mut a: int = 3;
|
||||
|
|
@ -86,7 +86,7 @@ fn make_graph(N: uint, edges: ~[(node_id, node_id)]) -> graph {
|
|||
HashSet::new()
|
||||
};
|
||||
|
||||
for vec::each(edges) |e| {
|
||||
for edges.iter().advance |e| {
|
||||
match *e {
|
||||
(i, j) => {
|
||||
graph[i].insert(j);
|
||||
|
|
@ -441,7 +441,7 @@ fn main() {
|
|||
let stop = time::precise_time_s();
|
||||
|
||||
let mut total_edges = 0;
|
||||
vec::each(graph, |edges| { total_edges += edges.len(); true });
|
||||
for graph.iter().advance |edges| { total_edges += edges.len(); }
|
||||
|
||||
io::stdout().write_line(fmt!("Generated graph with %? edges in %? seconds.",
|
||||
total_edges / 2,
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ fn run(args: &[~str]) {
|
|||
server(&from_parent, &to_parent);
|
||||
}
|
||||
|
||||
for vec::each(worker_results) |r| {
|
||||
for worker_results.iter().advance |r| {
|
||||
r.recv();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ fn run(args: &[~str]) {
|
|||
server(&from_parent, &to_parent);
|
||||
}
|
||||
|
||||
for vec::each(worker_results) |r| {
|
||||
for worker_results.iter().advance |r| {
|
||||
r.recv();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -188,7 +188,7 @@ fn rendezvous(nn: uint, set: ~[color]) {
|
|||
|
||||
// save each creature's meeting stats
|
||||
let mut report = ~[];
|
||||
for vec::each(to_creature) |_to_one| {
|
||||
for to_creature.iter().advance |_to_one| {
|
||||
report.push(from_creatures_log.recv());
|
||||
}
|
||||
|
||||
|
|
@ -196,7 +196,7 @@ fn rendezvous(nn: uint, set: ~[color]) {
|
|||
io::println(show_color_list(set));
|
||||
|
||||
// print each creature's stats
|
||||
for vec::each(report) |rep| {
|
||||
for report.iter().advance |rep| {
|
||||
io::println(*rep);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ fn sort_and_fmt(mm: &HashMap<~[u8], uint>, total: uint) -> ~str {
|
|||
let mut pairs = ~[];
|
||||
|
||||
// map -> [(k,%)]
|
||||
for mm.each |&key, &val| {
|
||||
for mm.iter().advance |(&key, &val)| {
|
||||
pairs.push((key, pct(val, total)));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,10 +8,8 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::vec;
|
||||
|
||||
fn main() {
|
||||
for vec::each(~[0]) |_i| { //~ ERROR A for-loop body must return (), but
|
||||
for 2.times { //~ ERROR A for-loop body must return (), but
|
||||
true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ struct Foo {
|
|||
|
||||
impl Foo {
|
||||
pub fn foo(&mut self, fun: &fn(&int)) {
|
||||
for self.n.each |f| {
|
||||
for self.n.iter().advance |f| {
|
||||
fun(f);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,10 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::vec;
|
||||
|
||||
fn main() {
|
||||
for vec::each(fail!()) |i| {
|
||||
let _ = i * 2; //~ ERROR the type of this value must be known
|
||||
};
|
||||
let x = fail!();
|
||||
x.clone(); //~ ERROR the type of this value must be known in this context
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,6 @@
|
|||
|
||||
pub mod a {}
|
||||
|
||||
pub mod a {} //~ ERROR duplicate definition of type `a`
|
||||
pub mod a {} //~ ERROR duplicate definition of module `a`
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
30
src/test/compile-fail/lint-change-warnings.rs
Normal file
30
src/test/compile-fail/lint-change-warnings.rs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#[deny(warnings)];
|
||||
|
||||
fn main() {
|
||||
while true {} //~ ERROR: infinite
|
||||
}
|
||||
|
||||
#[allow(warnings)]
|
||||
fn foo() {
|
||||
while true {}
|
||||
}
|
||||
|
||||
#[warn(warnings)]
|
||||
fn bar() {
|
||||
while true {} //~ WARNING: infinite
|
||||
}
|
||||
|
||||
#[forbid(warnings)]
|
||||
fn baz() {
|
||||
while true {} //~ ERROR: warnings
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@ use std::vec;
|
|||
|
||||
fn main() {
|
||||
let a: ~[int] = ~[];
|
||||
vec::each(a, |_| -> bool {
|
||||
a.iter().advance(|_| -> bool {
|
||||
//~^ ERROR mismatched types
|
||||
});
|
||||
}
|
||||
|
|
|
|||
17
src/test/compile-fail/static-mut-bad-types.rs
Normal file
17
src/test/compile-fail/static-mut-bad-types.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
static mut a: int = 3;
|
||||
|
||||
fn main() {
|
||||
unsafe {
|
||||
a = true; //~ ERROR: mismatched types
|
||||
}
|
||||
}
|
||||
21
src/test/compile-fail/static-mut-foreign-requires-unsafe.rs
Normal file
21
src/test/compile-fail/static-mut-foreign-requires-unsafe.rs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::libc;
|
||||
|
||||
extern {
|
||||
static mut a: libc::c_int;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
a += 3; //~ ERROR: requires unsafe
|
||||
a = 4; //~ ERROR: requires unsafe
|
||||
let _b = a; //~ ERROR: requires unsafe
|
||||
}
|
||||
13
src/test/compile-fail/static-mut-not-constant.rs
Normal file
13
src/test/compile-fail/static-mut-not-constant.rs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
static mut a: ~int = ~3; //~ ERROR: disallowed operator in constant
|
||||
|
||||
fn main() {}
|
||||
26
src/test/compile-fail/static-mut-not-pat.rs
Normal file
26
src/test/compile-fail/static-mut-not-pat.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// Constants (static variables) can be used to match in patterns, but mutable
|
||||
// statics cannot. This ensures that there's some form of error if this is
|
||||
// attempted.
|
||||
|
||||
static mut a: int = 3;
|
||||
|
||||
fn main() {
|
||||
// If they can't be matched against, then it's possible to capture the same
|
||||
// name as a variable, hence this should be an unreachable pattern situation
|
||||
// instead of spitting out a custom error about some identifier collisions
|
||||
// (we should allow shadowing)
|
||||
match 4 {
|
||||
a => {}
|
||||
_ => {} //~ ERROR: unreachable pattern
|
||||
}
|
||||
}
|
||||
17
src/test/compile-fail/static-mut-requires-unsafe.rs
Normal file
17
src/test/compile-fail/static-mut-requires-unsafe.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
static mut a: int = 3;
|
||||
|
||||
fn main() {
|
||||
a += 3; //~ ERROR: requires unsafe
|
||||
a = 4; //~ ERROR: requires unsafe
|
||||
let _b = a; //~ ERROR: requires unsafe
|
||||
}
|
||||
|
|
@ -12,21 +12,19 @@
|
|||
// making method calls, but only if there aren't any matches without
|
||||
// it.
|
||||
|
||||
use std::vec;
|
||||
|
||||
trait iterable<A> {
|
||||
fn iterate(&self, blk: &fn(x: &A) -> bool) -> bool;
|
||||
}
|
||||
|
||||
impl<'self,A> iterable<A> for &'self [A] {
|
||||
fn iterate(&self, f: &fn(x: &A) -> bool) -> bool {
|
||||
vec::each(*self, f)
|
||||
self.iter().advance(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<A> iterable<A> for ~[A] {
|
||||
fn iterate(&self, f: &fn(x: &A) -> bool) -> bool {
|
||||
vec::each(*self, f)
|
||||
self.iter().advance(f)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
25
src/test/run-pass/attr-no-drop-flag-size.rs
Normal file
25
src/test/run-pass/attr-no-drop-flag-size.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::sys::size_of;
|
||||
|
||||
#[no_drop_flag]
|
||||
struct Test<T> {
|
||||
a: T
|
||||
}
|
||||
|
||||
#[unsafe_destructor]
|
||||
impl<T> Drop for Test<T> {
|
||||
fn finalize(&self) { }
|
||||
}
|
||||
|
||||
fn main() {
|
||||
assert_eq!(size_of::<int>(), size_of::<Test<int>>());
|
||||
}
|
||||
|
|
@ -8,11 +8,10 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::vec;
|
||||
|
||||
pub fn main() {
|
||||
let mut sum = 0;
|
||||
for vec::each(~[1, 2, 3, 4, 5]) |x| {
|
||||
let xs = ~[1, 2, 3, 4, 5];
|
||||
for xs.iter().advance |x| {
|
||||
sum += *x;
|
||||
}
|
||||
assert_eq!(sum, 15);
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ pub fn main() {
|
|||
let v = ~[-1f, 0f, 1f, 2f, 3f];
|
||||
|
||||
// Statement form does not require parentheses:
|
||||
for vec::each(v) |i| {
|
||||
for v.iter().advance |i| {
|
||||
info!("%?", *i);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,12 +8,10 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::vec;
|
||||
|
||||
fn want_slice(v: &[int]) -> int {
|
||||
let mut sum = 0;
|
||||
for vec::each(v) |i| { sum += *i; }
|
||||
return sum;
|
||||
for v.iter().advance |i| { sum += *i; }
|
||||
sum
|
||||
}
|
||||
|
||||
fn has_mut_vec(v: ~[int]) -> int {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,8 @@ pub fn main() {
|
|||
assert_eq!(i, 10);
|
||||
loop { i += 1; if i == 20 { break; } }
|
||||
assert_eq!(i, 20);
|
||||
for vec::each(~[1, 2, 3, 4, 5, 6]) |x| {
|
||||
let xs = [1, 2, 3, 4, 5, 6];
|
||||
for xs.iter().advance |x| {
|
||||
if *x == 3 { break; } assert!((*x <= 3));
|
||||
}
|
||||
i = 0;
|
||||
|
|
@ -26,7 +27,8 @@ pub fn main() {
|
|||
i += 1; if i % 2 == 0 { loop; } assert!((i % 2 != 0));
|
||||
if i >= 10 { break; }
|
||||
}
|
||||
for vec::each(~[1, 2, 3, 4, 5, 6]) |x| {
|
||||
let ys = ~[1, 2, 3, 4, 5, 6];
|
||||
for ys.iter().advance |x| {
|
||||
if *x % 2 == 0 { loop; }
|
||||
assert!((*x % 2 != 0));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,29 +61,8 @@ impl<T> Mutable for cat<T> {
|
|||
}
|
||||
|
||||
impl<T> Map<int, T> for cat<T> {
|
||||
fn each<'a>(&'a self, f: &fn(&int, &'a T) -> bool) -> bool {
|
||||
let mut n = int::abs(self.meows);
|
||||
while n > 0 {
|
||||
if !f(&n, &self.name) { return false; }
|
||||
n -= 1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
fn contains_key(&self, k: &int) -> bool { *k <= self.meows }
|
||||
|
||||
fn each_key(&self, f: &fn(v: &int) -> bool) -> bool {
|
||||
self.each(|k, _| f(k))
|
||||
}
|
||||
|
||||
fn each_value<'a>(&'a self, f: &fn(v: &'a T) -> bool) -> bool {
|
||||
self.each(|_, v| f(v))
|
||||
}
|
||||
|
||||
fn mutate_values(&mut self, _f: &fn(&int, &mut T) -> bool) -> bool {
|
||||
fail!("nope")
|
||||
}
|
||||
|
||||
fn insert(&mut self, k: int, _: T) -> bool {
|
||||
self.meows += k;
|
||||
true
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// xfail-fast
|
||||
// xfail-test
|
||||
// FIXME: #7385: hits a codegen bug on OS X x86_64
|
||||
|
||||
/*!
|
||||
* Try to double-check that static fns have the right size (with or
|
||||
|
|
@ -23,6 +24,6 @@ struct S<'self>(&'self fn());
|
|||
static closures: &'static [S<'static>] = &[S(f), S(f)];
|
||||
|
||||
pub fn main() {
|
||||
for std::vec::each(bare_fns) |&bare_fn| { bare_fn() }
|
||||
for std::vec::each(closures) |&closure| { (*closure)() }
|
||||
for bare_fns.iter().advance |&bare_fn| { bare_fn() }
|
||||
for closures.iter().advance |&closure| { (*closure)() }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,5 @@
|
|||
use std::libc;
|
||||
use std::sys;
|
||||
use std::vec;
|
||||
|
||||
extern {
|
||||
pub unsafe fn vec_reserve_shared_actual(t: *sys::TypeDesc,
|
||||
v: **vec::raw::VecRepr,
|
||||
n: libc::size_t);
|
||||
pub unsafe fn free(p: *u8);
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
|
|
|
|||
|
|
@ -8,10 +8,11 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// xfail-test: #3511: does not currently compile, due to rvalue issues
|
||||
|
||||
use std::vec;
|
||||
|
||||
struct Pair { x: int, y: int }
|
||||
|
||||
pub fn main() {
|
||||
for vec::each(~[Pair {x: 10, y: 20}, Pair {x: 30, y: 0}]) |elt| {
|
||||
assert_eq!(elt.x + elt.y, 30);
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ trait sum {
|
|||
impl<'self> sum for &'self [int] {
|
||||
fn sum(self) -> int {
|
||||
let mut sum = 0;
|
||||
for vec::each(self) |e| { sum += *e; }
|
||||
for self.iter().advance |e| { sum += *e; }
|
||||
return sum;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,15 +10,14 @@
|
|||
|
||||
// xfail-fast
|
||||
|
||||
use std::bool;
|
||||
use std::int;
|
||||
use std::libc::c_void;
|
||||
use std::ptr;
|
||||
use std::sys;
|
||||
use std::vec::UnboxedVecRepr;
|
||||
use intrinsic::{TyDesc, get_tydesc, visit_tydesc, TyVisitor, Opaque};
|
||||
use std::unstable::intrinsics::{TyDesc, get_tydesc, visit_tydesc, TyVisitor, Opaque};
|
||||
|
||||
#[doc = "High-level interfaces to `intrinsic::visit_ty` reflection system."]
|
||||
#[doc = "High-level interfaces to `std::unstable::intrinsics::visit_ty` reflection system."]
|
||||
|
||||
/// Trait for visitor that wishes to reflect on data.
|
||||
trait movable_ptr {
|
||||
|
|
@ -637,7 +636,9 @@ impl TyVisitor for my_visitor {
|
|||
}
|
||||
|
||||
fn get_tydesc_for<T>(_t: T) -> *TyDesc {
|
||||
get_tydesc::<T>()
|
||||
unsafe {
|
||||
get_tydesc::<T>()
|
||||
}
|
||||
}
|
||||
|
||||
struct Triple { x: int, y: int, z: int }
|
||||
|
|
@ -651,8 +652,8 @@ pub fn main() {
|
|||
vals: ~[]});
|
||||
let v = ptr_visit_adaptor(Inner {inner: u});
|
||||
let td = get_tydesc_for(r);
|
||||
unsafe { error!("tydesc sz: %u, align: %u",
|
||||
(*td).size, (*td).align); }
|
||||
error!("tydesc sz: %u, align: %u",
|
||||
(*td).size, (*td).align);
|
||||
let v = @v as @TyVisitor;
|
||||
visit_tydesc(td, v);
|
||||
|
||||
|
|
@ -661,8 +662,7 @@ pub fn main() {
|
|||
println(fmt!("val: %s", *s));
|
||||
}
|
||||
error!("%?", u.vals.clone());
|
||||
assert!(u.vals == ~[
|
||||
~"1", ~"2", ~"3", ~"true", ~"false", ~"5", ~"4", ~"3", ~"12"
|
||||
]);
|
||||
assert_eq!(u.vals.clone(),
|
||||
~[ ~"1", ~"2", ~"3", ~"true", ~"false", ~"5", ~"4", ~"3", ~"12"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,141 +8,153 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// xfail-test
|
||||
use intrinsic::{TyDesc, get_tydesc, visit_tydesc, TyVisitor};
|
||||
struct my_visitor(@mut { types: ~[str] });
|
||||
use std::unstable::intrinsics::{TyDesc, get_tydesc, visit_tydesc, TyVisitor, Opaque};
|
||||
|
||||
impl TyVisitor for my_visitor {
|
||||
fn visit_bot() -> bool {
|
||||
self.types += ~["bot"];
|
||||
struct MyVisitor {
|
||||
types: @mut ~[~str],
|
||||
}
|
||||
|
||||
impl TyVisitor for MyVisitor {
|
||||
fn visit_bot(&self) -> bool {
|
||||
self.types.push(~"bot");
|
||||
error!("visited bot type");
|
||||
true
|
||||
}
|
||||
fn visit_nil() -> bool {
|
||||
self.types += ~["nil"];
|
||||
fn visit_nil(&self) -> bool {
|
||||
self.types.push(~"nil");
|
||||
error!("visited nil type");
|
||||
true
|
||||
}
|
||||
fn visit_bool() -> bool {
|
||||
self.types += ~["bool"];
|
||||
fn visit_bool(&self) -> bool {
|
||||
self.types.push(~"bool");
|
||||
error!("visited bool type");
|
||||
true
|
||||
}
|
||||
fn visit_int() -> bool {
|
||||
self.types += ~["int"];
|
||||
fn visit_int(&self) -> bool {
|
||||
self.types.push(~"int");
|
||||
error!("visited int type");
|
||||
true
|
||||
}
|
||||
fn visit_i8() -> bool {
|
||||
self.types += ~["i8"];
|
||||
fn visit_i8(&self) -> bool {
|
||||
self.types.push(~"i8");
|
||||
error!("visited i8 type");
|
||||
true
|
||||
}
|
||||
fn visit_i16() -> bool {
|
||||
self.types += ~["i16"];
|
||||
fn visit_i16(&self) -> bool {
|
||||
self.types.push(~"i16");
|
||||
error!("visited i16 type");
|
||||
true
|
||||
}
|
||||
fn visit_i32() -> bool { true }
|
||||
fn visit_i64() -> bool { true }
|
||||
fn visit_i32(&self) -> bool { true }
|
||||
fn visit_i64(&self) -> bool { true }
|
||||
|
||||
fn visit_uint() -> bool { true }
|
||||
fn visit_u8() -> bool { true }
|
||||
fn visit_u16() -> bool { true }
|
||||
fn visit_u32() -> bool { true }
|
||||
fn visit_u64() -> bool { true }
|
||||
fn visit_uint(&self) -> bool { true }
|
||||
fn visit_u8(&self) -> bool { true }
|
||||
fn visit_u16(&self) -> bool { true }
|
||||
fn visit_u32(&self) -> bool { true }
|
||||
fn visit_u64(&self) -> bool { true }
|
||||
|
||||
fn visit_float() -> bool { true }
|
||||
fn visit_f32() -> bool { true }
|
||||
fn visit_f64() -> bool { true }
|
||||
fn visit_float(&self) -> bool { true }
|
||||
fn visit_f32(&self) -> bool { true }
|
||||
fn visit_f64(&self) -> bool { true }
|
||||
|
||||
fn visit_char() -> bool { true }
|
||||
fn visit_str() -> bool { true }
|
||||
fn visit_char(&self) -> bool { true }
|
||||
fn visit_str(&self) -> bool { true }
|
||||
|
||||
fn visit_estr_box() -> bool { true }
|
||||
fn visit_estr_uniq() -> bool { true }
|
||||
fn visit_estr_slice() -> bool { true }
|
||||
fn visit_estr_fixed(_sz: uint, _sz: uint,
|
||||
fn visit_estr_box(&self) -> bool { true }
|
||||
fn visit_estr_uniq(&self) -> bool { true }
|
||||
fn visit_estr_slice(&self) -> bool { true }
|
||||
fn visit_estr_fixed(&self,
|
||||
_sz: uint, _sz: uint,
|
||||
_align: uint) -> bool { true }
|
||||
|
||||
fn visit_box(_mtbl: uint, _inner: *TyDesc) -> bool { true }
|
||||
fn visit_uniq(_mtbl: uint, _inner: *TyDesc) -> bool { true }
|
||||
fn visit_ptr(_mtbl: uint, _inner: *TyDesc) -> bool { true }
|
||||
fn visit_rptr(_mtbl: uint, _inner: *TyDesc) -> bool { true }
|
||||
fn visit_box(&self, _mtbl: uint, _inner: *TyDesc) -> bool { true }
|
||||
fn visit_uniq(&self, _mtbl: uint, _inner: *TyDesc) -> bool { true }
|
||||
fn visit_ptr(&self, _mtbl: uint, _inner: *TyDesc) -> bool { true }
|
||||
fn visit_rptr(&self, _mtbl: uint, _inner: *TyDesc) -> bool { true }
|
||||
|
||||
fn visit_vec(_mtbl: uint, inner: *TyDesc) -> bool {
|
||||
self.types += ~["["];
|
||||
visit_tydesc(inner, my_visitor(*self) as TyVisitor);
|
||||
self.types += ~["]"];
|
||||
fn visit_vec(&self, _mtbl: uint, _inner: *TyDesc) -> bool { true }
|
||||
fn visit_unboxed_vec(&self, _mtbl: uint, _inner: *TyDesc) -> bool { true }
|
||||
fn visit_evec_box(&self, _mtbl: uint, _inner: *TyDesc) -> bool { true }
|
||||
fn visit_evec_uniq(&self, _mtbl: uint, inner: *TyDesc) -> bool {
|
||||
self.types.push(~"[");
|
||||
unsafe {
|
||||
visit_tydesc(inner, (@*self) as @TyVisitor);
|
||||
}
|
||||
self.types.push(~"]");
|
||||
true
|
||||
}
|
||||
fn visit_unboxed_vec(_mtbl: uint, _inner: *TyDesc) -> bool { true }
|
||||
fn visit_evec_box(_mtbl: uint, _inner: *TyDesc) -> bool { true }
|
||||
fn visit_evec_uniq(_mtbl: uint, _inner: *TyDesc) -> bool { true }
|
||||
fn visit_evec_slice(_mtbl: uint, _inner: *TyDesc) -> bool { true }
|
||||
fn visit_evec_fixed(_n: uint, _sz: uint, _align: uint,
|
||||
fn visit_evec_slice(&self, _mtbl: uint, _inner: *TyDesc) -> bool { true }
|
||||
fn visit_evec_fixed(&self, _n: uint, _sz: uint, _align: uint,
|
||||
_mtbl: uint, _inner: *TyDesc) -> bool { true }
|
||||
|
||||
fn visit_enter_rec(_n_fields: uint,
|
||||
fn visit_enter_rec(&self, _n_fields: uint,
|
||||
_sz: uint, _align: uint) -> bool { true }
|
||||
fn visit_rec_field(_i: uint, _name: &str,
|
||||
fn visit_rec_field(&self, _i: uint, _name: &str,
|
||||
_mtbl: uint, _inner: *TyDesc) -> bool { true }
|
||||
fn visit_leave_rec(_n_fields: uint,
|
||||
fn visit_leave_rec(&self, _n_fields: uint,
|
||||
_sz: uint, _align: uint) -> bool { true }
|
||||
|
||||
fn visit_enter_class(_n_fields: uint,
|
||||
fn visit_enter_class(&self, _n_fields: uint,
|
||||
_sz: uint, _align: uint) -> bool { true }
|
||||
fn visit_class_field(_i: uint, _name: &str,
|
||||
fn visit_class_field(&self, _i: uint, _name: &str,
|
||||
_mtbl: uint, _inner: *TyDesc) -> bool { true }
|
||||
fn visit_leave_class(_n_fields: uint,
|
||||
fn visit_leave_class(&self, _n_fields: uint,
|
||||
_sz: uint, _align: uint) -> bool { true }
|
||||
|
||||
fn visit_enter_tup(_n_fields: uint,
|
||||
fn visit_enter_tup(&self, _n_fields: uint,
|
||||
_sz: uint, _align: uint) -> bool { true }
|
||||
fn visit_tup_field(_i: uint, _inner: *TyDesc) -> bool { true }
|
||||
fn visit_leave_tup(_n_fields: uint,
|
||||
fn visit_tup_field(&self, _i: uint, _inner: *TyDesc) -> bool { true }
|
||||
fn visit_leave_tup(&self, _n_fields: uint,
|
||||
_sz: uint, _align: uint) -> bool { true }
|
||||
|
||||
fn visit_enter_enum(_n_variants: uint,
|
||||
fn visit_enter_enum(&self, _n_variants: uint,
|
||||
_get_disr: extern unsafe fn(ptr: *Opaque) -> int,
|
||||
_sz: uint, _align: uint) -> bool { true }
|
||||
fn visit_enter_enum_variant(_variant: uint,
|
||||
fn visit_enter_enum_variant(&self,
|
||||
_variant: uint,
|
||||
_disr_val: int,
|
||||
_n_fields: uint,
|
||||
_name: &str) -> bool { true }
|
||||
fn visit_enum_variant_field(_i: uint, _inner: *TyDesc) -> bool { true }
|
||||
fn visit_leave_enum_variant(_variant: uint,
|
||||
fn visit_enum_variant_field(&self, _i: uint, _offset: uint, _inner: *TyDesc) -> bool { true }
|
||||
fn visit_leave_enum_variant(&self,
|
||||
_variant: uint,
|
||||
_disr_val: int,
|
||||
_n_fields: uint,
|
||||
_name: &str) -> bool { true }
|
||||
fn visit_leave_enum(_n_variants: uint,
|
||||
fn visit_leave_enum(&self,
|
||||
_n_variants: uint,
|
||||
_get_disr: extern unsafe fn(ptr: *Opaque) -> int,
|
||||
_sz: uint, _align: uint) -> bool { true }
|
||||
|
||||
fn visit_enter_fn(_purity: uint, _proto: uint,
|
||||
fn visit_enter_fn(&self, _purity: uint, _proto: uint,
|
||||
_n_inputs: uint, _retstyle: uint) -> bool { true }
|
||||
fn visit_fn_input(_i: uint, _mode: uint, _inner: *TyDesc) -> bool { true }
|
||||
fn visit_fn_output(_retstyle: uint, _inner: *TyDesc) -> bool { true }
|
||||
fn visit_leave_fn(_purity: uint, _proto: uint,
|
||||
fn visit_fn_input(&self, _i: uint, _mode: uint, _inner: *TyDesc) -> bool { true }
|
||||
fn visit_fn_output(&self, _retstyle: uint, _inner: *TyDesc) -> bool { true }
|
||||
fn visit_leave_fn(&self, _purity: uint, _proto: uint,
|
||||
_n_inputs: uint, _retstyle: uint) -> bool { true }
|
||||
|
||||
|
||||
fn visit_trait() -> bool { true }
|
||||
fn visit_var() -> bool { true }
|
||||
fn visit_var_integral() -> bool { true }
|
||||
fn visit_param(_i: uint) -> bool { true }
|
||||
fn visit_self() -> bool { true }
|
||||
fn visit_type() -> bool { true }
|
||||
fn visit_opaque_box() -> bool { true }
|
||||
fn visit_constr(_inner: *TyDesc) -> bool { true }
|
||||
fn visit_closure_ptr(_ck: uint) -> bool { true }
|
||||
fn visit_trait(&self) -> bool { true }
|
||||
fn visit_var(&self) -> bool { true }
|
||||
fn visit_var_integral(&self) -> bool { true }
|
||||
fn visit_param(&self, _i: uint) -> bool { true }
|
||||
fn visit_self(&self) -> bool { true }
|
||||
fn visit_type(&self) -> bool { true }
|
||||
fn visit_opaque_box(&self) -> bool { true }
|
||||
fn visit_constr(&self, _inner: *TyDesc) -> bool { true }
|
||||
fn visit_closure_ptr(&self, _ck: uint) -> bool { true }
|
||||
}
|
||||
|
||||
fn visit_ty<T>(v: TyVisitor) {
|
||||
visit_tydesc(get_tydesc::<T>(), v);
|
||||
fn visit_ty<T>(v: @TyVisitor) {
|
||||
unsafe {
|
||||
visit_tydesc(get_tydesc::<T>(), v);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let v = my_visitor(@mut {types: ~[]});
|
||||
let vv = v as TyVisitor;
|
||||
let v = @MyVisitor {types: @mut ~[]};
|
||||
let vv = v as @TyVisitor;
|
||||
|
||||
visit_ty::<bool>(vv);
|
||||
visit_ty::<int>(vv);
|
||||
|
|
@ -150,9 +162,8 @@ pub fn main() {
|
|||
visit_ty::<i16>(vv);
|
||||
visit_ty::<~[int]>(vv);
|
||||
|
||||
for (v.types.clone()).each {|s|
|
||||
io::println(fmt!("type: %s", s));
|
||||
for v.types.iter().advance |&s| {
|
||||
println(fmt!("type: %s", s));
|
||||
}
|
||||
assert!(v.types == ["bool", "int", "i8", "i16",
|
||||
"[", "int", "]"]);
|
||||
assert_eq!((*v.types).clone(), ~[~"bool", ~"int", ~"i8", ~"i16", ~"[", ~"int", ~"]"]);
|
||||
}
|
||||
|
|
|
|||
46
src/test/run-pass/static-mut-foreign.rs
Normal file
46
src/test/run-pass/static-mut-foreign.rs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// Constants (static variables) can be used to match in patterns, but mutable
|
||||
// statics cannot. This ensures that there's some form of error if this is
|
||||
// attempted.
|
||||
|
||||
use std::libc;
|
||||
|
||||
#[nolink]
|
||||
extern {
|
||||
static mut debug_static_mut: libc::c_int;
|
||||
pub fn debug_static_mut_check_four();
|
||||
}
|
||||
|
||||
unsafe fn static_bound(_: &'static libc::c_int) {}
|
||||
|
||||
fn static_bound_set(a: &'static mut libc::c_int) {
|
||||
*a = 3;
|
||||
}
|
||||
|
||||
unsafe fn run() {
|
||||
assert!(debug_static_mut == 3);
|
||||
debug_static_mut = 4;
|
||||
assert!(debug_static_mut == 4);
|
||||
debug_static_mut_check_four();
|
||||
debug_static_mut += 1;
|
||||
assert!(debug_static_mut == 5);
|
||||
debug_static_mut *= 3;
|
||||
assert!(debug_static_mut == 15);
|
||||
debug_static_mut = -3;
|
||||
assert!(debug_static_mut == -3);
|
||||
static_bound(&debug_static_mut);
|
||||
static_bound_set(&mut debug_static_mut);
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
unsafe { run() }
|
||||
}
|
||||
46
src/test/run-pass/static-mut-xc.rs
Normal file
46
src/test/run-pass/static-mut-xc.rs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// Constants (static variables) can be used to match in patterns, but mutable
|
||||
// statics cannot. This ensures that there's some form of error if this is
|
||||
// attempted.
|
||||
|
||||
// xfail-fast
|
||||
// aux-build:static_mut_xc.rs
|
||||
|
||||
extern mod static_mut_xc;
|
||||
|
||||
unsafe fn static_bound(_: &'static int) {}
|
||||
|
||||
fn static_bound_set(a: &'static mut int) {
|
||||
*a = 3;
|
||||
}
|
||||
|
||||
unsafe fn run() {
|
||||
assert!(static_mut_xc::a == 3);
|
||||
static_mut_xc::a = 4;
|
||||
assert!(static_mut_xc::a == 4);
|
||||
static_mut_xc::a += 1;
|
||||
assert!(static_mut_xc::a == 5);
|
||||
static_mut_xc::a *= 3;
|
||||
assert!(static_mut_xc::a == 15);
|
||||
static_mut_xc::a = -3;
|
||||
assert!(static_mut_xc::a == -3);
|
||||
static_bound(&static_mut_xc::a);
|
||||
static_bound_set(&mut static_mut_xc::a);
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
unsafe { run() }
|
||||
}
|
||||
|
||||
pub mod inner {
|
||||
pub static mut a: int = 4;
|
||||
}
|
||||
|
|
@ -31,7 +31,10 @@ trait map<T> {
|
|||
impl<T> map<T> for ~[T] {
|
||||
fn map<U:Copy>(&self, f: &fn(&T) -> U) -> ~[U] {
|
||||
let mut r = ~[];
|
||||
for std::vec::each(*self) |x| { r += ~[f(x)]; }
|
||||
// FIXME: #7355 generates bad code with Iterator
|
||||
for std::uint::range(0, self.len()) |i| {
|
||||
r += ~[f(&self[i])];
|
||||
}
|
||||
r
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue