Skip to content

Commit 02c49b3

Browse files
committed
libsyntax: Remove @const from the language
1 parent d4fee24 commit 02c49b3

15 files changed

+41
-248
lines changed

src/libcore/managed.rs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,43 @@ pub pure fn mut_ptr_eq<T>(a: @mut T, b: @mut T) -> bool {
4949
}
5050

5151
#[cfg(notest)]
52-
impl<T:Eq> Eq for @const T {
52+
impl<T:Eq> Eq for @T {
5353
#[inline(always)]
54-
pure fn eq(&self, other: &@const T) -> bool { *(*self) == *(*other) }
54+
pure fn eq(&self, other: &@T) -> bool { *(*self) == *(*other) }
5555
#[inline(always)]
56-
pure fn ne(&self, other: &@const T) -> bool { *(*self) != *(*other) }
56+
pure fn ne(&self, other: &@T) -> bool { *(*self) != *(*other) }
5757
}
5858

5959
#[cfg(notest)]
60-
impl<T:Ord> Ord for @const T {
60+
impl<T:Eq> Eq for @mut T {
6161
#[inline(always)]
62-
pure fn lt(&self, other: &@const T) -> bool { *(*self) < *(*other) }
62+
pure fn eq(&self, other: &@mut T) -> bool { *(*self) == *(*other) }
6363
#[inline(always)]
64-
pure fn le(&self, other: &@const T) -> bool { *(*self) <= *(*other) }
64+
pure fn ne(&self, other: &@mut T) -> bool { *(*self) != *(*other) }
65+
}
66+
67+
#[cfg(notest)]
68+
impl<T:Ord> Ord for @T {
69+
#[inline(always)]
70+
pure fn lt(&self, other: &@T) -> bool { *(*self) < *(*other) }
71+
#[inline(always)]
72+
pure fn le(&self, other: &@T) -> bool { *(*self) <= *(*other) }
73+
#[inline(always)]
74+
pure fn ge(&self, other: &@T) -> bool { *(*self) >= *(*other) }
75+
#[inline(always)]
76+
pure fn gt(&self, other: &@T) -> bool { *(*self) > *(*other) }
77+
}
78+
79+
#[cfg(notest)]
80+
impl<T:Ord> Ord for @mut T {
81+
#[inline(always)]
82+
pure fn lt(&self, other: &@mut T) -> bool { *(*self) < *(*other) }
83+
#[inline(always)]
84+
pure fn le(&self, other: &@mut T) -> bool { *(*self) <= *(*other) }
6585
#[inline(always)]
66-
pure fn ge(&self, other: &@const T) -> bool { *(*self) >= *(*other) }
86+
pure fn ge(&self, other: &@mut T) -> bool { *(*self) >= *(*other) }
6787
#[inline(always)]
68-
pure fn gt(&self, other: &@const T) -> bool { *(*self) > *(*other) }
88+
pure fn gt(&self, other: &@mut T) -> bool { *(*self) > *(*other) }
6989
}
7090

7191
#[test]

src/libsyntax/parse/obsolete.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ pub enum ObsoleteSyntax {
5858
ObsoleteMode,
5959
ObsoleteImplicitSelf,
6060
ObsoleteLifetimeNotation,
61+
ObsoleteConstManagedPointer,
6162
}
6263

6364
impl to_bytes::IterBytes for ObsoleteSyntax {
@@ -193,6 +194,10 @@ pub impl Parser {
193194
"instead of `&foo/bar`, write `&'foo bar`; instead of \
194195
`bar/&foo`, write `&bar<'foo>"
195196
),
197+
ObsoleteConstManagedPointer => (
198+
"const `@` pointer",
199+
"instead of `@const Foo`, write `@Foo`"
200+
),
196201
};
197202

198203
self.report(sp, kind, kind_str, desc);

src/libsyntax/parse/parser.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ use parse::obsolete::{ObsoleteRecordType, ObsoleteRecordPattern};
7979
use parse::obsolete::{ObsoleteAssertion, ObsoletePostFnTySigil};
8080
use parse::obsolete::{ObsoleteBareFnType, ObsoleteNewtypeEnum};
8181
use parse::obsolete::{ObsoleteMode, ObsoleteImplicitSelf};
82-
use parse::obsolete::{ObsoleteLifetimeNotation};
82+
use parse::obsolete::{ObsoleteLifetimeNotation, ObsoleteConstManagedPointer};
8383
use parse::prec::{as_prec, token_to_binop};
8484
use parse::token::{can_begin_expr, is_ident, is_ident_or_path};
8585
use parse::token::{is_plain_ident, INTERPOLATED, special_idents};
@@ -710,6 +710,9 @@ pub impl Parser {
710710
if mt.mutbl != m_imm && sigil == OwnedSigil {
711711
self.obsolete(*self.last_span, ObsoleteMutOwnedPointer);
712712
}
713+
if mt.mutbl == m_const && sigil == ManagedSigil {
714+
self.obsolete(*self.last_span, ObsoleteConstManagedPointer);
715+
}
713716

714717
ctor(mt)
715718
}
@@ -1636,6 +1639,10 @@ pub impl Parser {
16361639
token::AT => {
16371640
self.bump();
16381641
let m = self.parse_mutability();
1642+
if m == m_const {
1643+
self.obsolete(*self.last_span, ObsoleteConstManagedPointer);
1644+
}
1645+
16391646
let e = self.parse_prefix_expr();
16401647
hi = e.span.hi;
16411648
// HACK: turn @[...] into a @-evec

src/test/compile-fail/borrowck-assign-to-subfield.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ fn main() {
1313
a: int,
1414
w: B,
1515
x: @B,
16-
y: @const B,
1716
z: @mut B
1817
}
1918
struct B {
@@ -23,7 +22,6 @@ fn main() {
2322
a: 1,
2423
w: B {a: 1},
2524
x: @B {a: 1},
26-
y: @const B {a: 1},
2725
z: @mut B {a: 1}
2826
};
2927

@@ -37,6 +35,5 @@ fn main() {
3735
// in these cases we pass through a box, so the mut
3836
// of the box is dominant
3937
p.x.a = 2; //~ ERROR assigning to immutable field
40-
p.y.a = 2; //~ ERROR assigning to const field
4138
p.z.a = 2;
4239
}

src/test/compile-fail/borrowck-pat-enum-in-box.rs

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/test/compile-fail/borrowck-uniq-via-box.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,6 @@ fn box_imm_recs(v: @Outer) {
5050
borrow(v.f.g.h); // OK
5151
}
5252

53-
fn box_const(v: @const ~int) {
54-
borrow(*v); //~ ERROR illegal borrow unless pure
55-
}
56-
57-
fn box_const_rec(v: @const Rec) {
58-
borrow(v.f); //~ ERROR illegal borrow unless pure
59-
}
60-
61-
fn box_const_recs(v: @const Outer) {
62-
borrow(v.f.g.h); //~ ERROR illegal borrow unless pure
63-
}
64-
6553
fn main() {
6654
}
6755

src/test/compile-fail/coerce-bad-variance.rs

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/test/compile-fail/fn-variance-1.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#[legacy_modes];
1212

1313
fn takes_mut(&&x: @mut int) { }
14-
fn takes_const(&&x: @const int) { }
1514
fn takes_imm(&&x: @int) { }
1615

1716
fn apply<T>(t: T, f: &fn(T)) {
@@ -20,10 +19,8 @@ fn apply<T>(t: T, f: &fn(T)) {
2019

2120
fn main() {
2221
apply(@3, takes_mut); //~ ERROR (values differ in mutability)
23-
apply(@3, takes_const);
2422
apply(@3, takes_imm);
2523

2624
apply(@mut 3, takes_mut);
27-
apply(@mut 3, takes_const);
2825
apply(@mut 3, takes_imm); //~ ERROR (values differ in mutability)
2926
}

src/test/compile-fail/fn-variance-2.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ fn main() {
2525
// @mut int.
2626
let f: @mut int = r();
2727

28-
// OK.
29-
let g: @const int = r();
30-
3128
// Bad.
3229
let h: @int = r(); //~ ERROR (values differ in mutability)
3330
}

src/test/compile-fail/mutable-huh-box-assign.rs

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/test/compile-fail/tps-invariant-class.rs

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/test/compile-fail/tps-invariant-enum.rs

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/test/compile-fail/tps-invariant-trait.rs

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/test/compile-fail/trait-impl-method-mismatch.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,12 @@
1010

1111
trait Mumbo {
1212
fn jumbo(&self, x: @uint) -> uint;
13-
fn jambo(&self, x: @const uint) -> uint;
14-
fn jbmbo(&self) -> @uint;
1513
}
1614

1715
impl Mumbo for uint {
1816
// Cannot have a larger effect than the trait:
1917
unsafe fn jumbo(&self, x: @uint) { *self + *x; }
2018
//~^ ERROR expected impure fn but found unsafe fn
21-
22-
// Cannot accept a narrower range of parameters:
23-
fn jambo(&self, x: @uint) { *self + *x; }
24-
//~^ ERROR values differ in mutability
25-
26-
// Cannot return a wider range of values:
27-
fn jbmbo(&self) -> @const uint { @const 0 }
28-
//~^ ERROR values differ in mutability
2919
}
3020

3121
fn main() {}

0 commit comments

Comments
 (0)