auto merge of #8802 : pcwalton/rust/compile-speed, r=brson

r? @brson
This commit is contained in:
bors 2013-08-27 19:35:44 -07:00
commit 578e680477
143 changed files with 3070 additions and 1783 deletions

View file

@ -121,54 +121,54 @@ fn main() {
io::println("\nTreeMap:");
{
let mut map = TreeMap::new::<uint, uint>();
let mut map: TreeMap<uint,uint> = TreeMap::new();
ascending(&mut map, n_keys);
}
{
let mut map = TreeMap::new::<uint, uint>();
let mut map: TreeMap<uint,uint> = TreeMap::new();
descending(&mut map, n_keys);
}
{
io::println(" Random integers:");
let mut map = TreeMap::new::<uint, uint>();
let mut map: TreeMap<uint,uint> = TreeMap::new();
vector(&mut map, n_keys, rand);
}
io::println("\nHashMap:");
{
let mut map = HashMap::new::<uint, uint>();
let mut map: HashMap<uint,uint> = HashMap::new();
ascending(&mut map, n_keys);
}
{
let mut map = HashMap::new::<uint, uint>();
let mut map: HashMap<uint,uint> = HashMap::new();
descending(&mut map, n_keys);
}
{
io::println(" Random integers:");
let mut map = HashMap::new::<uint, uint>();
let mut map: HashMap<uint,uint> = HashMap::new();
vector(&mut map, n_keys, rand);
}
io::println("\nTrieMap:");
{
let mut map = TrieMap::new::<uint>();
let mut map: TrieMap<uint> = TrieMap::new();
ascending(&mut map, n_keys);
}
{
let mut map = TrieMap::new::<uint>();
let mut map: TrieMap<uint> = TrieMap::new();
descending(&mut map, n_keys);
}
{
io::println(" Random integers:");
let mut map = TrieMap::new::<uint>();
let mut map: TrieMap<uint> = TrieMap::new();
vector(&mut map, n_keys, rand);
}
}

View file

@ -169,16 +169,28 @@ fn main() {
{
let mut rng = rand::IsaacRng::new_seeded(seed);
let mut results = empty_results();
results.bench_int(&mut rng, num_keys, max, || HashSet::new::<uint>());
results.bench_str(&mut rng, num_keys, || HashSet::new::<~str>());
results.bench_int(&mut rng, num_keys, max, || {
let s: HashSet<uint> = HashSet::new();
s
});
results.bench_str(&mut rng, num_keys, || {
let s: HashSet<~str> = HashSet::new();
s
});
write_results("std::hashmap::HashSet", &results);
}
{
let mut rng = rand::IsaacRng::new_seeded(seed);
let mut results = empty_results();
results.bench_int(&mut rng, num_keys, max, || TreeSet::new::<uint>());
results.bench_str(&mut rng, num_keys, || TreeSet::new::<~str>());
results.bench_int(&mut rng, num_keys, max, || {
let s: TreeSet<uint> = TreeSet::new();
s
});
results.bench_str(&mut rng, num_keys, || {
let s: TreeSet<~str> = TreeSet::new();
s
});
write_results("extra::treemap::TreeSet", &results);
}

View file

@ -0,0 +1,37 @@
#[no_std];
struct S<T> {
contents: T,
}
impl<T> S<T> {
fn new<U>(x: T, _: U) -> S<T> {
S {
contents: x,
}
}
}
trait Trait<T> {
fn new<U>(x: T, y: U) -> Self;
}
struct S2 {
contents: int,
}
impl Trait<int> for S2 {
fn new<U>(x: int, _: U) -> S2 {
S2 {
contents: x,
}
}
}
fn main() {
let _ = S::new::<int,float>(1, 1.0); //~ ERROR the impl referenced by this path has 1 type parameter, but 0 type parameters were supplied
let _ = S::<'self,int>::new::<float>(1, 1.0); //~ ERROR this impl has no lifetime parameter
let _: S2 = Trait::new::<int,float>(1, 1.0); //~ ERROR the trait referenced by this path has 1 type parameter, but 0 type parameters were supplied
let _: S2 = Trait::<'self,int>::new::<float>(1, 1.0); //~ ERROR this trait has no lifetime parameter
}

View file

@ -1,15 +0,0 @@
// Test that attempt to alias `&mut` pointer while pointee is borrowed
// yields an error.
//
// Example from src/middle/borrowck/doc.rs
use std::util::swap;
fn foo(t0: &mut int) {
let p: &int = &*t0; // Freezes `*t0`
let q: &const &mut int = &const t0; //~ ERROR cannot borrow `t0`
**q = 22; //~ ERROR cannot assign to an `&mut` in a `&const` pointer
}
fn main() {
}

View file

@ -11,16 +11,6 @@ fn foo(t0: & &mut int) {
**t1 = 22; //~ ERROR cannot assign
}
fn foo2(t0: &const &mut int) {
// Note: reborrowing from an &const actually yields two errors, since it
// is unsafe in two ways: we can't control the aliasing, and we can't
// control the mutation.
let t1 = t0;
let p: &int = &**t0; //~ ERROR cannot borrow an `&mut` in a `&const` pointer
//~^ ERROR unsafe borrow of aliasable, const value
**t1 = 22; //~ ERROR cannot assign
}
fn foo3(t0: &mut &mut int) {
let t1 = &mut *t0;
let p: &int = &**t0; //~ ERROR cannot borrow
@ -28,4 +18,4 @@ fn foo3(t0: &mut &mut int) {
}
fn main() {
}
}

View file

@ -13,8 +13,7 @@
use std::hashmap::HashMap;
fn main() {
let mut buggy_map :HashMap<uint, &uint> =
HashMap::new::<uint, &uint>();
let mut buggy_map: HashMap<uint, &uint> = HashMap::new();
buggy_map.insert(42, &*~1); //~ ERROR borrowed value does not live long enough
// but it is ok if we use a temporary

View file

@ -14,29 +14,18 @@ struct Foo {
impl Foo {
pub fn f(&self) {}
pub fn g(&const self) {}
pub fn h(&mut self) {}
}
fn a(x: &mut Foo) {
x.f();
x.g();
x.h();
}
fn b(x: &Foo) {
x.f();
x.g();
x.h(); //~ ERROR cannot borrow
}
fn c(x: &const Foo) {
x.f(); //~ ERROR cannot borrow
//~^ ERROR unsafe borrow
x.g();
x.h(); //~ ERROR cannot borrow
//~^ ERROR unsafe borrow
}
fn main() {
}

View file

@ -32,14 +32,6 @@ fn pre_freeze() {
borrow_mut(v); //~ ERROR cannot borrow
}
fn pre_const() {
// In this instance, the freeze starts before the mut borrow.
let mut v = ~3;
let _w = &const v;
borrow_mut(v);
}
fn post_freeze() {
// In this instance, the const alias starts after the borrow.

View file

@ -29,16 +29,5 @@ fn has_mut_vec_but_tries_to_change_it() {
}
}
fn takes_const_elt(_v: &const int, f: &fn()) {
f();
}
fn has_mut_vec_and_tries_to_change_it() {
let mut v = ~[1, 2, 3];
do takes_const_elt(&const v[0]) {
v[1] = 4;
}
}
fn main() {
}

View file

@ -1,45 +0,0 @@
// 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.
fn process<T>(_t: T) {}
fn match_const_opt_by_mut_ref(v: &const Option<int>) {
match *v {
Some(ref mut i) => process(i), //~ ERROR cannot borrow
//~^ ERROR unsafe borrow of aliasable, const value
None => ()
}
}
fn match_const_opt_by_const_ref(v: &const Option<int>) {
match *v {
Some(ref const i) => process(i),
//~^ ERROR unsafe borrow of aliasable, const value
None => ()
}
}
fn match_const_opt_by_imm_ref(v: &const Option<int>) {
match *v {
Some(ref i) => process(i), //~ ERROR cannot borrow
//~^ ERROR unsafe borrow of aliasable, const value
None => ()
}
}
fn match_const_opt_by_value(v: &const Option<int>) {
match *v {
Some(i) => process(i),
None => ()
}
}
fn main() {
}

View file

@ -35,12 +35,6 @@ fn aliased_imm() {
borrow(v);
}
fn aliased_const() {
let mut v = ~3;
let _w = &const v;
borrow(v);
}
fn aliased_mut() {
let mut v = ~3;
let _w = &mut v;

View file

@ -23,13 +23,10 @@ fn main() {
// @int <: X
//
// This constraint forces X to be
// @const int.
r(@3);
// Here the type check fails because @const is gone and there is no
// supertype.
r(@3); //~ ERROR mismatched types
// Here the type check succeeds but the
// mutability check will fail, because the
// type of r has been inferred to be
// fn(@const int) -> @const int
*r(@mut 3) = 4; //~ ERROR cannot assign to const dereference of @ pointer
// Here the type check succeeds.
*r(@mut 3) = 4;
}

View file

@ -1,25 +0,0 @@
// 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.
struct Bike {
name: ~str,
}
trait BikeMethods {
fn woops(&const self) -> ~str;
}
impl BikeMethods for Bike {
fn woops() -> ~str { ~"foo" }
//~^ ERROR has a `&const self` declaration in the trait, but not in the impl
}
pub fn main() {
}

View file

@ -1,22 +0,0 @@
// 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.
pub trait Nummy {
fn from_inty<T>() -> Self;
}
impl Nummy for float {
fn from_inty<T>() -> float { 0.0 }
}
fn main() {
let _1:float = Nummy::from_inty::<int>(); //~ ERROR not enough type
//~^ NOTE Static methods have an extra implicit type parameter
}

View file

@ -14,8 +14,8 @@ use std::hashmap::HashMap;
// Test that trait types printed in error msgs include the type arguments.
fn main() {
let x: @Map<~str, ~str> = @HashMap::new::<~str, ~str>() as
@Map<~str, ~str>;
let x: @HashMap<~str, ~str> = @HashMap::new();
let x: @Map<~str, ~str> = x as @Map<~str, ~str>;
let y: @Map<uint, ~str> = @x;
//~^ ERROR expected trait std::container::Map but found @-ptr
}

View file

@ -1,23 +0,0 @@
// 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.
extern mod extra;
fn main() {
unsafe fn f(v: *const int) {
*v = 1 //~ ERROR cannot assign
}
unsafe {
let mut a = 0;
let v = &mut a;
f(v);
}
}

View file

@ -23,17 +23,17 @@ let x: u64<int>; //~ ERROR type parameters are not allowed on this type
let x: float<int>; //~ ERROR type parameters are not allowed on this type
let x: char<int>; //~ ERROR type parameters are not allowed on this type
let x: int<'static>; //~ ERROR region parameters are not allowed on this type
let x: i8<'static>; //~ ERROR region parameters are not allowed on this type
let x: i16<'static>; //~ ERROR region parameters are not allowed on this type
let x: i32<'static>; //~ ERROR region parameters are not allowed on this type
let x: i64<'static>; //~ ERROR region parameters are not allowed on this type
let x: uint<'static>; //~ ERROR region parameters are not allowed on this type
let x: u8<'static>; //~ ERROR region parameters are not allowed on this type
let x: u16<'static>; //~ ERROR region parameters are not allowed on this type
let x: u32<'static>; //~ ERROR region parameters are not allowed on this type
let x: u64<'static>; //~ ERROR region parameters are not allowed on this type
let x: float<'static>; //~ ERROR region parameters are not allowed on this type
let x: char<'static>; //~ ERROR region parameters are not allowed on this type
let x: int<'static>; //~ ERROR lifetime parameters are not allowed on this type
let x: i8<'static>; //~ ERROR lifetime parameters are not allowed on this type
let x: i16<'static>; //~ ERROR lifetime parameters are not allowed on this type
let x: i32<'static>; //~ ERROR lifetime parameters are not allowed on this type
let x: i64<'static>; //~ ERROR lifetime parameters are not allowed on this type
let x: uint<'static>; //~ ERROR lifetime parameters are not allowed on this type
let x: u8<'static>; //~ ERROR lifetime parameters are not allowed on this type
let x: u16<'static>; //~ ERROR lifetime parameters are not allowed on this type
let x: u32<'static>; //~ ERROR lifetime parameters are not allowed on this type
let x: u64<'static>; //~ ERROR lifetime parameters are not allowed on this type
let x: float<'static>; //~ ERROR lifetime parameters are not allowed on this type
let x: char<'static>; //~ ERROR lifetime parameters are not allowed on this type
}

View file

@ -1,4 +1,5 @@
// aux-build:private_variant_xc.rs
// xfail-test
extern mod private_variant_xc;

View file

@ -25,8 +25,4 @@ fn a_fn3<'a,'b>(e: a_class<'a>) -> a_class<'b> {
//~^ ERROR cannot infer an appropriate lifetime
}
fn a_fn4<'a,'b>() {
let _: int<'a> = 1; //~ ERROR region parameters are not allowed on this type
}
fn main() { }

View file

@ -26,13 +26,6 @@ fn matcher2(x: opts) {
}
}
fn matcher3(x: opts) {
match x {
a(ref mut i) | b(ref const i) => {} //~ ERROR variable `i` is bound with different mode in pattern #2 than in pattern #1
c(_) => {}
}
}
fn matcher4(x: opts) {
match x {
a(ref mut i) | b(ref i) => {} //~ ERROR variable `i` is bound with different mode in pattern #2 than in pattern #1

View file

@ -6,5 +6,5 @@ mod a {
}
fn main() {
let _ = a::S::new(); //~ ERROR function `new` is private
let _ = a::S::new(); //~ ERROR method `new` is private
}

View file

@ -7,10 +7,10 @@ fn main() {
// normal method on struct
let _ = xc_private_method_lib::Struct{ x: 10 }.meth_struct(); //~ ERROR method `meth_struct` is private
// static method on struct
let _ = xc_private_method_lib::Struct::static_meth_struct(); //~ ERROR function `static_meth_struct` is private
let _ = xc_private_method_lib::Struct::static_meth_struct(); //~ ERROR method `static_meth_struct` is private
// normal method on enum
let _ = xc_private_method_lib::Variant1(20).meth_enum(); //~ ERROR method `meth_enum` is private
// static method on enum
let _ = xc_private_method_lib::Enum::static_meth_enum(); //~ ERROR function `static_meth_enum` is private
let _ = xc_private_method_lib::Enum::static_meth_enum(); //~ ERROR method `static_meth_enum` is private
}

View file

@ -1,3 +1,5 @@
// xfail-test
// 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.

View file

@ -1,3 +1,5 @@
// xfail-test
// 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.

View file

@ -13,17 +13,14 @@
trait MyIter {
fn test_imm(&self);
fn test_const(&const self);
}
impl<'self> MyIter for &'self [int] {
fn test_imm(&self) { assert_eq!(self[0], 1) }
fn test_const(&const self) { assert_eq!(self[0], 1) }
}
impl<'self> MyIter for &'self str {
fn test_imm(&self) { assert_eq!(*self, "test") }
fn test_const(&const self) { assert_eq!(self[0], 't' as u8) }
}
pub fn main() {
@ -40,15 +37,6 @@ pub fn main() {
// XXX: Other types of mutable vecs don't currently exist
([1]).test_const();
(~[1]).test_const();
(@[1]).test_const();
(&[1]).test_const();
("test").test_const();
(~"test").test_const();
(@"test").test_const();
(&"test").test_const();
// NB: We don't do this double autoreffing for &mut self because that would
// allow creating a mutable pointer to a temporary, which would be a source
// of confusion

View file

@ -13,7 +13,7 @@ struct Foo {
}
impl Foo {
pub fn f(&const self) {}
pub fn f(&self) {}
}
fn g(x: &mut Foo) {

View file

@ -1,3 +1,5 @@
// xfail-pretty
// 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.
@ -24,32 +26,9 @@ fn match_ref_unused(v: Option<int>) {
}
}
fn match_const_reg(v: &const Option<int>) -> int {
match *v {
Some(ref i) => {*i} //~ ERROR cannot borrow
//~^ ERROR unsafe borrow
None => {0}
}
}
fn impure(_i: int) {
}
fn match_const_reg_unused(v: &const Option<int>) {
match *v {
Some(_) => {impure(0)} // OK because nothing is captured
None => {}
}
}
fn match_const_reg_impure(v: &const Option<int>) {
match *v {
Some(ref i) => {impure(*i)} //~ ERROR cannot borrow
//~^ ERROR unsafe borrow
None => {}
}
}
fn match_imm_reg(v: &Option<int>) {
match *v {
Some(ref i) => {impure(*i)} // OK because immutable

View file

@ -25,7 +25,6 @@ struct Innermost {
}
fn borrow(_v: &int) {}
fn borrow_const(_v: &const int) {}
fn box_mut(v: &mut ~int) {
borrow(*v); // OK: &mut -> &imm
@ -51,17 +50,5 @@ fn box_imm_recs(v: &Outer) {
borrow(v.f.g.h); // OK
}
fn box_const(v: &const ~int) {
borrow_const(*v); //~ ERROR unsafe borrow
}
fn box_const_rec(v: &const Rec) {
borrow_const(v.f); //~ ERROR unsafe borrow
}
fn box_const_recs(v: &const Outer) {
borrow_const(v.f.g.h); //~ ERROR unsafe borrow
}
fn main() {
}

View file

@ -49,8 +49,8 @@ impl<T> cat<T> {
}
impl<T> Container for cat<T> {
fn len(&const self) -> uint { self.meows as uint }
fn is_empty(&const self) -> bool { self.meows == 0 }
fn len(&self) -> uint { self.meows as uint }
fn is_empty(&self) -> bool { self.meows == 0 }
}
impl<T> Mutable for cat<T> {

View file

@ -3,14 +3,14 @@ struct SpeechMaker {
}
impl SpeechMaker {
pub fn how_many(&const self) -> uint { self.speeches }
pub fn how_many(&self) -> uint { self.speeches }
}
fn foo(speaker: &const SpeechMaker) -> uint {
fn foo(speaker: &SpeechMaker) -> uint {
speaker.how_many() + 33
}
pub fn main() {
let lincoln = SpeechMaker {speeches: 22};
assert_eq!(foo(&const lincoln), 55);
assert_eq!(foo(&lincoln), 55);
}

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn f(_: &const [int]) {}
fn f(_: &[int]) {}
pub fn main() {
let v = [ 1, 2, 3 ];

View file

@ -36,5 +36,6 @@ struct Lots {
}
fn main() {
assert!(Zero::zero::<Lots>().is_zero());
let lots: Lots = Zero::zero();
assert!(lots.is_zero());
}

View file

@ -13,11 +13,12 @@ extern mod extra;
use std::num::Float;
pub fn main() {
let nan = Float::NaN::<float>();
let nan: float = Float::NaN();
assert!((nan).is_NaN());
let inf = Float::infinity::<float>();
assert_eq!(-inf, Float::neg_infinity::<float>());
let inf: float = Float::infinity();
let neg_inf: float = Float::neg_infinity();
assert_eq!(-inf, neg_inf);
assert!( nan != nan);
assert!( nan != -nan);

View file

@ -13,7 +13,7 @@
use std::hashmap::HashMap;
pub fn main() {
let mut buggy_map: HashMap<uint, &uint> = HashMap::new::<uint, &uint>();
let mut buggy_map: HashMap<uint, &uint> = HashMap::new();
let x = ~1;
buggy_map.insert(42, &*x);
}

View file

@ -1,3 +1,5 @@
// xfail-test
// 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.

View file

@ -0,0 +1,33 @@
struct S<T> {
contents: T,
}
impl<T> S<T> {
fn new<U>(x: T, _: U) -> S<T> {
S {
contents: x,
}
}
}
trait Trait<T> {
fn new<U>(x: T, y: U) -> Self;
}
struct S2 {
contents: int,
}
impl Trait<int> for S2 {
fn new<U>(x: int, _: U) -> S2 {
S2 {
contents: x,
}
}
}
fn main() {
let _ = S::<int>::new::<float>(1, 1.0);
let _: S2 = Trait::<int>::new::<float>(1, 1.0);
}

View file

@ -1,3 +1,5 @@
// xfail-pretty
// 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.

View file

@ -1,3 +1,5 @@
// xfail-pretty
// 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.

View file

@ -59,7 +59,7 @@ fn main () {
assert_eq!(0i.thing(3.14, 1), (3.14, 1));
assert_eq!(B::staticthing(&0i, 3.14, 1), (3.14, 1));
assert_eq!(B::staticthing::<float, int, int>(&0i, 3.14, 1), (3.14, 1));
assert_eq!(B::<float>::staticthing::<int>(&0i, 3.14, 1), (3.14, 1));
assert_eq!(g(0i, 3.14, 1), (3.14, 1));
assert_eq!(g(false, 3.14, 1), (3.14, 1));

View file

@ -14,7 +14,7 @@ mod base {
use std::io;
pub trait HasNew<T> {
fn new() -> T;
fn new() -> Self;
}
pub struct Foo {
@ -41,6 +41,6 @@ mod base {
}
pub fn main() {
let _f: base::Foo = base::HasNew::new::<base::Foo, base::Foo>();
let _b: base::Bar = base::HasNew::new::<base::Bar, base::Bar>();
let _f: base::Foo = base::HasNew::<base::Foo>::new();
let _b: base::Bar = base::HasNew::<base::Bar>::new();
}