diff --git a/src/libcore/managed.rs b/src/libcore/managed.rs index 1bef895ea0b..b177dced888 100644 --- a/src/libcore/managed.rs +++ b/src/libcore/managed.rs @@ -49,23 +49,43 @@ pub pure fn mut_ptr_eq(a: @mut T, b: @mut T) -> bool { } #[cfg(notest)] -impl Eq for @const T { +impl Eq for @T { #[inline(always)] - pure fn eq(&self, other: &@const T) -> bool { *(*self) == *(*other) } + pure fn eq(&self, other: &@T) -> bool { *(*self) == *(*other) } #[inline(always)] - pure fn ne(&self, other: &@const T) -> bool { *(*self) != *(*other) } + pure fn ne(&self, other: &@T) -> bool { *(*self) != *(*other) } } #[cfg(notest)] -impl Ord for @const T { +impl Eq for @mut T { #[inline(always)] - pure fn lt(&self, other: &@const T) -> bool { *(*self) < *(*other) } + pure fn eq(&self, other: &@mut T) -> bool { *(*self) == *(*other) } #[inline(always)] - pure fn le(&self, other: &@const T) -> bool { *(*self) <= *(*other) } + pure fn ne(&self, other: &@mut T) -> bool { *(*self) != *(*other) } +} + +#[cfg(notest)] +impl Ord for @T { #[inline(always)] - pure fn ge(&self, other: &@const T) -> bool { *(*self) >= *(*other) } + pure fn lt(&self, other: &@T) -> bool { *(*self) < *(*other) } #[inline(always)] - pure fn gt(&self, other: &@const T) -> bool { *(*self) > *(*other) } + pure fn le(&self, other: &@T) -> bool { *(*self) <= *(*other) } + #[inline(always)] + pure fn ge(&self, other: &@T) -> bool { *(*self) >= *(*other) } + #[inline(always)] + pure fn gt(&self, other: &@T) -> bool { *(*self) > *(*other) } +} + +#[cfg(notest)] +impl Ord for @mut T { + #[inline(always)] + pure fn lt(&self, other: &@mut T) -> bool { *(*self) < *(*other) } + #[inline(always)] + pure fn le(&self, other: &@mut T) -> bool { *(*self) <= *(*other) } + #[inline(always)] + pure fn ge(&self, other: &@mut T) -> bool { *(*self) >= *(*other) } + #[inline(always)] + pure fn gt(&self, other: &@mut T) -> bool { *(*self) > *(*other) } } #[test] diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index f5e83a1beae..573f90af020 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -58,6 +58,7 @@ pub enum ObsoleteSyntax { ObsoleteMode, ObsoleteImplicitSelf, ObsoleteLifetimeNotation, + ObsoleteConstManagedPointer, } impl to_bytes::IterBytes for ObsoleteSyntax { @@ -193,6 +194,10 @@ pub impl Parser { "instead of `&foo/bar`, write `&'foo bar`; instead of \ `bar/&foo`, write `&bar<'foo>" ), + ObsoleteConstManagedPointer => ( + "const `@` pointer", + "instead of `@const Foo`, write `@Foo`" + ), }; self.report(sp, kind, kind_str, desc); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 421c1805f6a..95f8afd538a 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -79,7 +79,7 @@ use parse::obsolete::{ObsoleteRecordType, ObsoleteRecordPattern}; use parse::obsolete::{ObsoleteAssertion, ObsoletePostFnTySigil}; use parse::obsolete::{ObsoleteBareFnType, ObsoleteNewtypeEnum}; use parse::obsolete::{ObsoleteMode, ObsoleteImplicitSelf}; -use parse::obsolete::{ObsoleteLifetimeNotation}; +use parse::obsolete::{ObsoleteLifetimeNotation, ObsoleteConstManagedPointer}; use parse::prec::{as_prec, token_to_binop}; use parse::token::{can_begin_expr, is_ident, is_ident_or_path}; use parse::token::{is_plain_ident, INTERPOLATED, special_idents}; @@ -710,6 +710,9 @@ pub impl Parser { if mt.mutbl != m_imm && sigil == OwnedSigil { self.obsolete(*self.last_span, ObsoleteMutOwnedPointer); } + if mt.mutbl == m_const && sigil == ManagedSigil { + self.obsolete(*self.last_span, ObsoleteConstManagedPointer); + } ctor(mt) } @@ -1636,6 +1639,10 @@ pub impl Parser { token::AT => { self.bump(); let m = self.parse_mutability(); + if m == m_const { + self.obsolete(*self.last_span, ObsoleteConstManagedPointer); + } + let e = self.parse_prefix_expr(); hi = e.span.hi; // HACK: turn @[...] into a @-evec diff --git a/src/test/compile-fail/borrowck-assign-to-subfield.rs b/src/test/compile-fail/borrowck-assign-to-subfield.rs index 736e950cd82..610802ca68b 100644 --- a/src/test/compile-fail/borrowck-assign-to-subfield.rs +++ b/src/test/compile-fail/borrowck-assign-to-subfield.rs @@ -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; } diff --git a/src/test/compile-fail/borrowck-pat-enum-in-box.rs b/src/test/compile-fail/borrowck-pat-enum-in-box.rs deleted file mode 100644 index bd1001bf38c..00000000000 --- a/src/test/compile-fail/borrowck-pat-enum-in-box.rs +++ /dev/null @@ -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 or the MIT license -// , 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 { - match *v { - @Some(ref i) => {*i} - @None => {0} - } -} - -fn match_const_box(v: &const @const Option) -> 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) { - match *v { - @Some(ref i) => { //~ ERROR illegal borrow unless pure - process(*i) //~ NOTE impure due to access to impure function - } - @None => {} - } -} - -fn main() { -} diff --git a/src/test/compile-fail/borrowck-uniq-via-box.rs b/src/test/compile-fail/borrowck-uniq-via-box.rs index 914b5caa011..e1c0e67ff8d 100644 --- a/src/test/compile-fail/borrowck-uniq-via-box.rs +++ b/src/test/compile-fail/borrowck-uniq-via-box.rs @@ -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() { } diff --git a/src/test/compile-fail/coerce-bad-variance.rs b/src/test/compile-fail/coerce-bad-variance.rs deleted file mode 100644 index 6ce969c7eaf..00000000000 --- a/src/test/compile-fail/coerce-bad-variance.rs +++ /dev/null @@ -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() {} diff --git a/src/test/compile-fail/fn-variance-1.rs b/src/test/compile-fail/fn-variance-1.rs index c5c29bd3ecf..6f3ccfd35ac 100644 --- a/src/test/compile-fail/fn-variance-1.rs +++ b/src/test/compile-fail/fn-variance-1.rs @@ -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, f: &fn(T)) { @@ -20,10 +19,8 @@ fn apply(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) } diff --git a/src/test/compile-fail/fn-variance-2.rs b/src/test/compile-fail/fn-variance-2.rs index 2a30f9fb96f..61668cbdb9e 100644 --- a/src/test/compile-fail/fn-variance-2.rs +++ b/src/test/compile-fail/fn-variance-2.rs @@ -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) } diff --git a/src/test/compile-fail/mutable-huh-box-assign.rs b/src/test/compile-fail/mutable-huh-box-assign.rs deleted file mode 100644 index bb06cbb6d03..00000000000 --- a/src/test/compile-fail/mutable-huh-box-assign.rs +++ /dev/null @@ -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 or the MIT license -// , 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); -} diff --git a/src/test/compile-fail/tps-invariant-class.rs b/src/test/compile-fail/tps-invariant-class.rs deleted file mode 100644 index 0411eeb05eb..00000000000 --- a/src/test/compile-fail/tps-invariant-class.rs +++ /dev/null @@ -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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -struct box_impl { - f: T, -} - -fn box_impl(f: T) -> box_impl { - box_impl { - f: f - } -} - -fn set_box_impl(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); -} diff --git a/src/test/compile-fail/tps-invariant-enum.rs b/src/test/compile-fail/tps-invariant-enum.rs deleted file mode 100644 index 9e19ecdcb75..00000000000 --- a/src/test/compile-fail/tps-invariant-enum.rs +++ /dev/null @@ -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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -struct box { - f: T -} - -struct box_impl(box); - -fn set_box_impl(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); -} diff --git a/src/test/compile-fail/tps-invariant-trait.rs b/src/test/compile-fail/tps-invariant-trait.rs deleted file mode 100644 index 127aa23d6ab..00000000000 --- a/src/test/compile-fail/tps-invariant-trait.rs +++ /dev/null @@ -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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -trait box_trait { - fn get(&self) -> T; - fn set(&self, t: T); -} - -struct box { - f: T -} - -struct box_impl(box); - -impl box_trait for box_impl { - fn get(&self) -> T { return self.f; } - fn set(&self, t: T) { self.f = t; } -} - -fn set_box_trait(b: @box_trait<@const T>, v: @const T) { - b.set(v); -} - -fn set_box_impl(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 -} diff --git a/src/test/compile-fail/trait-impl-method-mismatch.rs b/src/test/compile-fail/trait-impl-method-mismatch.rs index 6676cde3c96..7f4c227d2d0 100644 --- a/src/test/compile-fail/trait-impl-method-mismatch.rs +++ b/src/test/compile-fail/trait-impl-method-mismatch.rs @@ -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() {} diff --git a/src/test/compile-fail/trait-impl-subtype.rs b/src/test/compile-fail/trait-impl-subtype.rs deleted file mode 100644 index eb34ebbdfb0..00000000000 --- a/src/test/compile-fail/trait-impl-subtype.rs +++ /dev/null @@ -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 or the MIT license -// , 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); -} - - -