auto merge of #5480 : pcwalton/rust/at-const, r=pcwalton

r? @catamorphism
This commit is contained in:
bors 2013-03-21 20:39:51 -07:00
commit d52408d46a
54 changed files with 277 additions and 295 deletions

View file

@ -19,6 +19,7 @@ struct arc_destruct<T> {
_data: int,
}
#[unsafe_destructor]
impl<T:Const> Drop for arc_destruct<T> {
fn finalize(&self) {}
}

View file

@ -56,6 +56,7 @@ struct r {
_l: @nillist,
}
#[unsafe_destructor]
impl Drop for r {
fn finalize(&self) {}
}

View file

@ -13,7 +13,6 @@ fn main() {
a: int,
w: B,
x: @B,
y: @const B,
z: @mut B
}
struct B {
@ -23,7 +22,6 @@ fn main() {
a: 1,
w: B {a: 1},
x: @B {a: 1},
y: @const B {a: 1},
z: @mut B {a: 1}
};
@ -37,6 +35,5 @@ fn main() {
// in these cases we pass through a box, so the mut
// of the box is dominant
p.x.a = 2; //~ ERROR assigning to immutable field
p.y.a = 2; //~ ERROR assigning to const field
p.z.a = 2;
}

View file

@ -12,9 +12,12 @@ struct defer {
x: &'self [&'self str],
}
#[unsafe_destructor]
impl Drop for defer<'self> {
fn finalize(&self) {
error!("%?", self.x);
unsafe {
error!("%?", self.x);
}
}
}

View file

@ -1,37 +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 match_imm_box(v: &const @Option<int>) -> int {
match *v {
@Some(ref i) => {*i}
@None => {0}
}
}
fn match_const_box(v: &const @const Option<int>) -> int {
match *v {
@Some(ref i) => { *i } // ok because this is pure
@None => {0}
}
}
fn process(_i: int) {}
fn match_const_box_and_do_bad_things(v: &const @const Option<int>) {
match *v {
@Some(ref i) => { //~ ERROR illegal borrow unless pure
process(*i) //~ NOTE impure due to access to impure function
}
@None => {}
}
}
fn main() {
}

View file

@ -50,18 +50,6 @@ fn box_imm_recs(v: @Outer) {
borrow(v.f.g.h); // OK
}
fn box_const(v: @const ~int) {
borrow(*v); //~ ERROR illegal borrow unless pure
}
fn box_const_rec(v: @const Rec) {
borrow(v.f); //~ ERROR illegal borrow unless pure
}
fn box_const_recs(v: @const Outer) {
borrow(v.f.g.h); //~ ERROR illegal borrow unless pure
}
fn main() {
}

View file

@ -1,17 +0,0 @@
fn mutate(x: &mut @const int) {
*x = @3;
}
fn give_away1(y: @mut @mut int) {
mutate(y); //~ ERROR values differ in mutability
}
fn give_away2(y: @mut @const int) {
mutate(y);
}
fn give_away3(y: @mut @int) {
mutate(y); //~ ERROR values differ in mutability
}
fn main() {}

View file

@ -11,7 +11,6 @@
#[legacy_modes];
fn takes_mut(&&x: @mut int) { }
fn takes_const(&&x: @const int) { }
fn takes_imm(&&x: @int) { }
fn apply<T>(t: T, f: &fn(T)) {
@ -20,10 +19,8 @@ fn apply<T>(t: T, f: &fn(T)) {
fn main() {
apply(@3, takes_mut); //~ ERROR (values differ in mutability)
apply(@3, takes_const);
apply(@3, takes_imm);
apply(@mut 3, takes_mut);
apply(@mut 3, takes_const);
apply(@mut 3, takes_imm); //~ ERROR (values differ in mutability)
}

View file

@ -25,9 +25,6 @@ fn main() {
// @mut int.
let f: @mut int = r();
// OK.
let g: @const int = r();
// Bad.
let h: @int = r(); //~ ERROR (values differ in mutability)
}

View file

@ -16,10 +16,13 @@ struct foo {
}
#[unsafe_destructor]
impl Drop for foo {
fn finalize(&self) {
io::println("Goodbye, World!");
*self.x += 1;
unsafe {
io::println("Goodbye, World!");
*self.x += 1;
}
}
}

View file

@ -0,0 +1,12 @@
struct Foo {
f: @mut int,
}
impl Drop for Foo { //~ ERROR cannot implement a destructor on a struct that is not Owned
fn finalize(&self) {
*self.f = 10;
}
}
fn main() { }

View file

@ -1,19 +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 main() {
fn f(&&v: @const int) {
*v = 1 //~ ERROR assigning to dereference of const @ pointer
}
let v = @0;
f(v);
}

View file

@ -17,6 +17,7 @@ fn main() {
_x: Port<()>,
}
#[unsafe_destructor]
impl Drop for foo {
fn finalize(&self) {}
}

View file

@ -12,9 +12,12 @@ struct r {
i: @mut int,
}
#[unsafe_destructor]
impl Drop for r {
fn finalize(&self) {
*(self.i) = *(self.i) + 1;
unsafe {
*(self.i) = *(self.i) + 1;
}
}
}

View file

@ -1,33 +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 box_impl<T> {
f: T,
}
fn box_impl<T>(f: T) -> box_impl<T> {
box_impl {
f: f
}
}
fn set_box_impl<T>(b: box_impl<@const T>, v: @const T) {
b.f = v;
}
fn main() {
let b = box_impl::<@int>(@3);
set_box_impl(b, @mut 5);
//~^ ERROR values differ in mutability
// No error when type of parameter actually IS @const int
let b = box_impl::<@const int>(@3);
set_box_impl(b, @mut 5);
}

View file

@ -1,30 +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 box<T> {
f: T
}
struct box_impl<T>(box<T>);
fn set_box_impl<T>(b: box_impl<@const T>, v: @const T) {
b.f = v;
}
fn main() {
let b = box_impl::<@int>(box::<@int> {f: @3});
set_box_impl(b, @mut 5);
//~^ ERROR values differ in mutability
// No error when type of parameter actually IS @const int
let x: @const int = @3; // only way I could find to upcast
let b = box_impl::<@const int>(box::<@const int>{f: x});
set_box_impl(b, @mut 5);
}

View file

@ -1,41 +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.
trait box_trait<T> {
fn get(&self) -> T;
fn set(&self, t: T);
}
struct box<T> {
f: T
}
struct box_impl<T>(box<T>);
impl<T:Copy> box_trait<T> for box_impl<T> {
fn get(&self) -> T { return self.f; }
fn set(&self, t: T) { self.f = t; }
}
fn set_box_trait<T>(b: @box_trait<@const T>, v: @const T) {
b.set(v);
}
fn set_box_impl<T>(b: box_impl<@const T>, v: @const T) {
b.set(v);
}
fn main() {
let b = box_impl::<@int>(box::<@int> {f: @3});
set_box_trait(@b as @box_trait<@int>, @mut 5);
//~^ ERROR values differ in mutability
set_box_impl(b, @mut 5);
//~^ ERROR values differ in mutability
}

View file

@ -10,22 +10,12 @@
trait Mumbo {
fn jumbo(&self, x: @uint) -> uint;
fn jambo(&self, x: @const uint) -> uint;
fn jbmbo(&self) -> @uint;
}
impl Mumbo for uint {
// Cannot have a larger effect than the trait:
unsafe fn jumbo(&self, x: @uint) { *self + *x; }
//~^ ERROR expected impure fn but found unsafe fn
// Cannot accept a narrower range of parameters:
fn jambo(&self, x: @uint) { *self + *x; }
//~^ ERROR values differ in mutability
// Cannot return a wider range of values:
fn jbmbo(&self) -> @const uint { @const 0 }
//~^ ERROR values differ in mutability
}
fn main() {}

View file

@ -1,31 +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.
trait Mumbo {
fn jumbo(&self, x: @uint) -> uint;
}
impl Mumbo for uint {
// Note: this method def is ok, it is more accepting and
// less effecting than the trait method:
pure fn jumbo(&self, x: @const uint) -> uint { *self + *x }
}
fn main() {
let a = 3u;
let b = a.jumbo(@mut 6);
let x = @a as @Mumbo;
let y = x.jumbo(@mut 6); //~ ERROR values differ in mutability
let z = x.jumbo(@6);
}

View file

@ -12,9 +12,12 @@ struct r {
i: @mut int,
}
#[unsafe_destructor]
impl Drop for r {
fn finalize(&self) {
*(self.i) = *(self.i) + 1;
unsafe {
*(self.i) = *(self.i) + 1;
}
}
}

View file

@ -17,6 +17,7 @@ struct faily_box {
fn faily_box(i: @int) -> faily_box { faily_box { i: i } }
#[unsafe_destructor]
impl Drop for faily_box {
fn finalize(&self) {
fail!(~"quux");

View file

@ -12,6 +12,7 @@ struct S<T> {
x: T
}
#[unsafe_destructor]
impl<T> ::core::ops::Drop for S<T> {
fn finalize(&self) {
io::println("bye");

View file

@ -17,9 +17,12 @@ struct r {
struct Box { x: r }
#[unsafe_destructor]
impl Drop for r {
fn finalize(&self) {
*(self.i) = *(self.i) + 1;
unsafe {
*(self.i) = *(self.i) + 1;
}
}
}

View file

@ -155,6 +155,7 @@ pub mod pipes {
p: Option<*packet<T>>,
}
#[unsafe_destructor]
impl<T:Owned> Drop for send_packet<T> {
fn finalize(&self) {
unsafe {
@ -187,6 +188,7 @@ pub mod pipes {
p: Option<*packet<T>>,
}
#[unsafe_destructor]
impl<T:Owned> Drop for recv_packet<T> {
fn finalize(&self) {
unsafe {

View file

@ -13,9 +13,12 @@ struct defer {
b: &'self mut bool,
}
#[unsafe_destructor]
impl Drop for defer/&self {
fn finalize(&self) {
*(self.b) = true;
unsafe {
*(self.b) = true;
}
}
}

View file

@ -13,9 +13,12 @@ struct defer {
b: &'self mut bool,
}
#[unsafe_destructor]
impl Drop for defer/&self {
fn finalize(&self) {
*(self.b) = true;
unsafe {
*(self.b) = true;
}
}
}

View file

@ -12,9 +12,12 @@ struct r {
b: @mut int,
}
#[unsafe_destructor]
impl Drop for r {
fn finalize(&self) {
*(self.b) += 1;
unsafe {
*(self.b) += 1;
}
}
}

View file

@ -13,10 +13,13 @@ struct dtor {
}
#[unsafe_destructor]
impl Drop for dtor {
fn finalize(&self) {
// abuse access to shared mutable state to write this code
*self.x -= 1;
unsafe {
*self.x -= 1;
}
}
}

View file

@ -12,9 +12,12 @@ struct r {
i: @mut int,
}
#[unsafe_destructor]
impl Drop for r {
fn finalize(&self) {
*(self.i) += 1;
unsafe {
*(self.i) += 1;
}
}
}

View file

@ -12,9 +12,12 @@ struct shrinky_pointer {
i: @@mut int,
}
#[unsafe_destructor]
impl Drop for shrinky_pointer {
fn finalize(&self) {
error!(~"Hello!"); **(self.i) -= 1;
unsafe {
error!(~"Hello!"); **(self.i) -= 1;
}
}
}

View file

@ -16,9 +16,12 @@ struct finish<T> {
arg: Arg<T>
}
#[unsafe_destructor]
impl<T:Copy> Drop for finish<T> {
fn finalize(&self) {
(self.arg.fin)(self.arg.val);
unsafe {
(self.arg.fin)(self.arg.val);
}
}
}

View file

@ -18,9 +18,12 @@ struct close_res {
}
#[unsafe_destructor]
impl Drop for close_res {
fn finalize(&self) {
*(self.i) = false;
unsafe {
*(self.i) = false;
}
}
}

View file

@ -20,15 +20,18 @@ struct notify {
ch: Chan<bool>, v: @mut bool,
}
#[unsafe_destructor]
impl Drop for notify {
fn finalize(&self) {
error!("notify: task=%? v=%x unwinding=%b b=%b",
task::get_task(),
ptr::addr_of(&(*(self.v))) as uint,
task::failing(),
*(self.v));
let b = *(self.v);
self.ch.send(b);
unsafe {
error!("notify: task=%? v=%x unwinding=%b b=%b",
task::get_task(),
ptr::addr_of(&(*(self.v))) as uint,
task::failing(),
*(self.v));
let b = *(self.v);
self.ch.send(b);
}
}
}

View file

@ -12,9 +12,12 @@ struct r {
i: @mut int,
}
#[unsafe_destructor]
impl Drop for r {
fn finalize(&self) {
*(self.i) = *(self.i) + 1;
unsafe {
*(self.i) = *(self.i) + 1;
}
}
}

View file

@ -15,6 +15,7 @@ struct complainer {
c: @int,
}
#[unsafe_destructor]
impl Drop for complainer {
fn finalize(&self) {}
}

View file

@ -13,9 +13,12 @@ struct foo {
x: @mut int,
}
#[unsafe_destructor]
impl Drop for foo {
fn finalize(&self) {
*self.x += 1;
unsafe {
*self.x += 1;
}
}
}