auto merge of #11595 : eddyb/rust/env-et-self-no-more, r=nikomatsakis

Non-exhaustive change list:
* `self` is now present in argument lists (modulo type-checking code I don't trust myself to refactor)
* methods have the same calling convention as bare functions (including the self argument)
* the env param is gone from all bare functions (and methods), only used by closures and `proc`s
* bare functions can only be coerced to closures and `proc`s if they are statically resolved, as they now require creating a wrapper specific to that function, to avoid indirect wrappers (equivalent to `impl<..Args, Ret> Fn<..Args, Ret> for fn(..Args) -> Ret`) that might not be optimizable by LLVM and don't work for `proc`s
* refactored some `trans::closure` code, leading to the removal of `trans::glue::make_free_glue` and `ty_opaque_closure_ptr`
This commit is contained in:
bors 2014-01-27 09:31:44 -08:00
commit d6d7812da8
88 changed files with 1437 additions and 2139 deletions

View file

@ -0,0 +1,19 @@
// Copyright 2014 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 foo() {}
fn main() {
let f = foo;
let f_closure: || = f;
//~^ ERROR: cannot coerce non-statically resolved bare fn
let f_proc: proc() = f;
//~^ ERROR: cannot coerce non-statically resolved bare fn
}

View file

@ -1,4 +1,4 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
@ -11,11 +11,10 @@
struct A;
impl A {
fn m(&self) {
fn x() {
self.m()
//~^ ERROR can't capture dynamic environment in a fn item
//~^^ ERROR `self` is not allowed in this context
}
fn x() {
self.m() //~ ERROR can't capture dynamic environment in a fn item
//~^ ERROR unresolved name `self`
}
}
}
fn main() {}

View file

@ -0,0 +1,22 @@
// Copyright 2014 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.
#[allow(dead_assignment)];
#[allow(unused_variable)];
#[allow(dead_code)];
#[deny(unused_mut)];
struct Foo;
impl Foo {
fn foo(mut self) {} //~ ERROR: variable does not need to be mutable
fn bar(mut ~self) {} //~ ERROR: variable does not need to be mutable
}
fn main() {}

View file

@ -1,4 +1,4 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
@ -13,7 +13,7 @@ trait foo {
}
impl foo for int {
fn bar(&self) -> int {
//~^ ERROR method `bar` has 0 parameters but the declaration in trait `foo::bar` has 1
//~^ ERROR method `bar` has 1 parameter but the declaration in trait `foo::bar` has 2
*self
}
}

View file

@ -0,0 +1,47 @@
// Copyright 2014 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 id<T>(x: T) -> T {
x
}
#[deriving(Eq)]
struct Foo<T>(T);
#[deriving(Eq)]
enum Bar<T> {
Bar(T)
}
pub fn main() {
let f: |int| -> int = id;
assert_eq!(f(5), 5);
let f: proc(int) -> int = id;
assert_eq!(f(5), 5);
let f: |int| -> Foo<int> = Foo;
assert_eq!(f(5), Foo(5));
let f: proc(int) -> Foo<int> = Foo;
assert_eq!(f(5), Foo(5));
let f: |int| -> Bar<int> = Bar;
assert_eq!(f(5), Bar(5));
let f: proc(int) -> Bar<int> = Bar;
assert_eq!(f(5), Bar(5));
let f: |int| -> Option<int> = Some;
assert_eq!(f(5), Some(5));
let f: proc(int) -> Option<int> = Some;
assert_eq!(f(5), Some(5));
}

View file

@ -13,7 +13,7 @@
fn test_fn() {
type t = 'static || -> int;
fn ten() -> int { return 10; }
let rs: t = { ten };
let rs: t = ten;
assert!((rs() == 10));
}

View file

@ -436,20 +436,6 @@ impl<V:TyVisitor + movable_ptr> TyVisitor for ptr_visit_adaptor<V> {
if ! self.inner().visit_type() { return false; }
true
}
fn visit_opaque_box(&mut self) -> bool {
self.align_to::<@u8>();
if ! self.inner().visit_opaque_box() { return false; }
self.bump_past::<@u8>();
true
}
fn visit_closure_ptr(&mut self, ck: uint) -> bool {
self.align_to::<(uint,uint)>();
if ! self.inner().visit_closure_ptr(ck) { return false; }
self.bump_past::<(uint,uint)>();
true
}
}
struct my_visitor(@RefCell<Stuff>);
@ -611,8 +597,6 @@ impl TyVisitor for my_visitor {
fn visit_param(&mut self, _i: uint) -> bool { true }
fn visit_self(&mut self) -> bool { true }
fn visit_type(&mut self) -> bool { true }
fn visit_opaque_box(&mut self) -> bool { true }
fn visit_closure_ptr(&mut self, _ck: uint) -> bool { true }
}
fn get_tydesc_for<T>(_t: T) -> *TyDesc {

View file

@ -137,8 +137,6 @@ impl TyVisitor for MyVisitor {
fn visit_param(&mut self, _i: uint) -> bool { true }
fn visit_self(&mut self) -> bool { true }
fn visit_type(&mut self) -> bool { true }
fn visit_opaque_box(&mut self) -> bool { true }
fn visit_closure_ptr(&mut self, _ck: uint) -> bool { true }
}
fn visit_ty<T>(v: &mut MyVisitor) {