Skip to content

Commit fc8c808

Browse files
committed
libsyntax: Stop parsing old lifetimes, except for the ones on data type declarations.
1 parent 299995c commit fc8c808

File tree

9 files changed

+51
-38
lines changed

9 files changed

+51
-38
lines changed

src/libcore/io.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ pub struct BytesReader {
593593
mut pos: uint
594594
}
595595
596-
impl Reader for BytesReader/&self {
596+
impl Reader for BytesReader<'self> {
597597
fn read(&self, bytes: &mut [u8], len: uint) -> uint {
598598
let count = uint::min(len, self.bytes.len() - self.pos);
599599

src/librustc/middle/resolve.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ pub impl<T> ResolveResult<T> {
210210
}
211211
}
212212

213-
pub enum TypeParameters/& {
213+
pub enum TypeParameters<'self> {
214214
NoTypeParameters, //< No type parameters.
215215
HasTypeParameters(&'self Generics, //< Type parameters.
216216
node_id, //< ID of the enclosing item

src/librustc/middle/typeck/astconv.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@
4343
* as it does not already appear in scope.
4444
*
4545
* Case (b) says that if you have a type:
46-
* type foo/& = ...;
46+
* type foo<'self> = ...;
4747
* type bar = fn(&foo, &a.foo)
4848
* The fully expanded version of type bar is:
49-
* type bar = fn(&'foo &, &a.foo/&a)
49+
* type bar = fn(&'foo &, &a.foo<'a>)
5050
* Note that the self region for the `foo` defaulted to `&` in the first
5151
* case but `&a` in the second. Basically, defaults that appear inside
5252
* an rptr (`&r.T`) use the region `r` that appears in the rptr.

src/librustc/util/ppaux.rs

+21-22
Original file line numberDiff line numberDiff line change
@@ -132,21 +132,21 @@ pub fn explain_region_and_span(cx: ctxt, region: ty::Region)
132132
}
133133

134134
pub fn bound_region_to_str(cx: ctxt, br: bound_region) -> ~str {
135-
bound_region_to_str_adorned(cx, "&", br, "")
135+
bound_region_to_str_space(cx, "&", br)
136136
}
137137

138-
pub fn bound_region_to_str_adorned(cx: ctxt, prefix: &str,
139-
br: bound_region, sep: &str) -> ~str {
140-
if cx.sess.verbose() { return fmt!("%s%?%s", prefix, br, sep); }
138+
pub fn bound_region_to_str_space(cx: ctxt,
139+
prefix: &str,
140+
br: bound_region)
141+
-> ~str {
142+
if cx.sess.verbose() { return fmt!("%s%? ", prefix, br); }
141143

142144
match br {
143-
br_named(id) => fmt!("%s%s%s", prefix, *cx.sess.str_of(id),
144-
sep),
145-
br_self => fmt!("%sself%s", prefix, sep),
145+
br_named(id) => fmt!("%s'%s ", prefix, *cx.sess.str_of(id)),
146+
br_self => fmt!("%s'self ", prefix),
146147
br_anon(_) => prefix.to_str(),
147148
br_fresh(_) => prefix.to_str(),
148-
br_cap_avoid(_, br) => bound_region_to_str_adorned(cx, prefix,
149-
*br, sep)
149+
br_cap_avoid(_, br) => bound_region_to_str_space(cx, prefix, *br)
150150
}
151151
}
152152

@@ -194,13 +194,12 @@ pub fn re_scope_id_to_str(cx: ctxt, node_id: ast::node_id) -> ~str {
194194
// you should use `explain_region()` or, better yet,
195195
// `note_and_explain_region()`
196196
pub fn region_to_str(cx: ctxt, region: Region) -> ~str {
197-
region_to_str_adorned(cx, "&", region, "")
197+
region_to_str_space(cx, "&", region)
198198
}
199199

200-
pub fn region_to_str_adorned(cx: ctxt, prefix: &str,
201-
region: Region, sep: &str) -> ~str {
200+
pub fn region_to_str_space(cx: ctxt, prefix: &str, region: Region) -> ~str {
202201
if cx.sess.verbose() {
203-
return fmt!("%s%?%s", prefix, region, sep);
202+
return fmt!("%s%? ", prefix, region);
204203
}
205204

206205
// These printouts are concise. They do not contain all the information
@@ -209,13 +208,13 @@ pub fn region_to_str_adorned(cx: ctxt, prefix: &str,
209208
// `explain_region()` or `note_and_explain_region()`.
210209
match region {
211210
re_scope(_) => prefix.to_str(),
212-
re_bound(br) => bound_region_to_str_adorned(cx, prefix, br, sep),
213-
re_free(_, br) => bound_region_to_str_adorned(cx, prefix, br, sep),
211+
re_bound(br) => bound_region_to_str_space(cx, prefix, br),
212+
re_free(_, br) => bound_region_to_str_space(cx, prefix, br),
214213
re_infer(ReSkolemized(_, br)) => {
215-
bound_region_to_str_adorned(cx, prefix, br, sep)
214+
bound_region_to_str_space(cx, prefix, br)
216215
}
217216
re_infer(ReVar(_)) => prefix.to_str(),
218-
re_static => fmt!("%sstatic%s", prefix, sep)
217+
re_static => fmt!("%s'static ", prefix)
219218
}
220219
}
221220

@@ -233,7 +232,7 @@ pub fn vstore_to_str(cx: ctxt, vs: ty::vstore) -> ~str {
233232
ty::vstore_fixed(n) => fmt!("%u", n),
234233
ty::vstore_uniq => ~"~",
235234
ty::vstore_box => ~"@",
236-
ty::vstore_slice(r) => region_to_str_adorned(cx, "&", r, "/")
235+
ty::vstore_slice(r) => region_to_str_space(cx, "&", r)
237236
}
238237
}
239238

@@ -242,7 +241,7 @@ pub fn trait_store_to_str(cx: ctxt, s: ty::TraitStore) -> ~str {
242241
ty::BareTraitStore => ~"",
243242
ty::UniqTraitStore => ~"~",
244243
ty::BoxTraitStore => ~"@",
245-
ty::RegionTraitStore(r) => region_to_str_adorned(cx, "&", r, "")
244+
ty::RegionTraitStore(r) => region_to_str_space(cx, "&", r)
246245
}
247246
}
248247

@@ -252,7 +251,7 @@ pub fn vstore_ty_to_str(cx: ctxt, ty: ~str, vs: ty::vstore) -> ~str {
252251
fmt!("[%s * %s]", ty, vstore_to_str(cx, vs))
253252
}
254253
ty::vstore_slice(_) => {
255-
fmt!("%s/%s", vstore_to_str(cx, vs), ty)
254+
fmt!("%s %s", vstore_to_str(cx, vs), ty)
256255
}
257256
_ => fmt!("%s[%s]", vstore_to_str(cx, vs), ty)
258257
}
@@ -344,7 +343,7 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str {
344343
(ast::OwnedSigil, ty::re_static) => {}
345344

346345
(_, region) => {
347-
s.push_str(region_to_str_adorned(cx, "", region, "/"));
346+
s.push_str(region_to_str_space(cx, "", region));
348347
}
349348
}
350349

@@ -418,7 +417,7 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str {
418417
ty_uniq(tm) => ~"~" + mt_to_str(cx, tm),
419418
ty_ptr(tm) => ~"*" + mt_to_str(cx, tm),
420419
ty_rptr(r, tm) => {
421-
region_to_str_adorned(cx, ~"&", r, ~"/") + mt_to_str(cx, tm)
420+
region_to_str_space(cx, ~"&", r) + mt_to_str(cx, tm)
422421
}
423422
ty_unboxed_vec(tm) => { ~"unboxed_vec<" + mt_to_str(cx, tm) + ~">" }
424423
ty_type => ~"type",

src/libstd/sync.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ pub impl Sem<~[Waitqueue]> {
163163

164164
// FIXME(#3588) should go inside of access()
165165
#[doc(hidden)]
166-
type SemRelease = SemReleaseGeneric/&self<()>;
167-
type SemAndSignalRelease = SemReleaseGeneric/&self<~[Waitqueue]>;
166+
type SemRelease = SemReleaseGeneric<'self, ()>;
167+
type SemAndSignalRelease = SemReleaseGeneric<'self, ~[Waitqueue]>;
168168
struct SemReleaseGeneric<Q> { sem: &'self Sem<Q> }
169169

170170
impl<Q:Owned> Drop for SemReleaseGeneric/&self<Q> {

src/libsyntax/parse/obsolete.rs

+6
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub enum ObsoleteSyntax {
5757
ObsoleteNewtypeEnum,
5858
ObsoleteMode,
5959
ObsoleteImplicitSelf,
60+
ObsoleteLifetimeNotation,
6061
}
6162

6263
impl to_bytes::IterBytes for ObsoleteSyntax {
@@ -187,6 +188,11 @@ pub impl Parser {
187188
"use an explicit `self` declaration or declare the method as \
188189
static"
189190
),
191+
ObsoleteLifetimeNotation => (
192+
"`/` lifetime notation",
193+
"instead of `&foo/bar`, write `&'foo bar`; instead of \
194+
`bar/&foo`, write `&bar<'foo>"
195+
),
190196
};
191197

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

src/libsyntax/parse/parser.rs

+5
Original file line numberDiff line numberDiff line change
@@ -79,6 +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};
8283
use parse::prec::{as_prec, token_to_binop};
8384
use parse::token::{can_begin_expr, is_ident, is_ident_or_path};
8485
use parse::token::{is_plain_ident, INTERPOLATED, special_idents};
@@ -686,6 +687,7 @@ pub impl Parser {
686687
self.token_is_closure_keyword(&self.look_ahead(2u))
687688
{
688689
let lifetime = @self.parse_lifetime();
690+
self.obsolete(*self.last_span, ObsoleteLifetimeNotation);
689691
return self.parse_ty_closure(sigil, Some(lifetime));
690692
} else if self.token_is_closure_keyword(&copy *self.token) {
691693
return self.parse_ty_closure(sigil, None);
@@ -963,6 +965,7 @@ pub impl Parser {
963965
// Also accept the (obsolete) syntax `foo/`
964966
token::IDENT(*) => {
965967
if self.look_ahead(1u) == token::BINOP(token::SLASH) {
968+
self.obsolete(*self.last_span, ObsoleteLifetimeNotation);
966969
Some(@self.parse_lifetime())
967970
} else {
968971
None
@@ -997,6 +1000,7 @@ pub impl Parser {
9971000
let span = copy self.span;
9981001
self.bump();
9991002
self.expect(&token::BINOP(token::SLASH));
1003+
self.obsolete(*self.last_span, ObsoleteLifetimeNotation);
10001004
return ast::Lifetime {
10011005
id: self.get_id(),
10021006
span: *span,
@@ -3653,6 +3657,7 @@ pub impl Parser {
36533657

36543658
fn parse_region_param(&self) {
36553659
if self.eat(&token::BINOP(token::SLASH)) {
3660+
self.obsolete(*self.last_span, ObsoleteLifetimeNotation);
36563661
self.expect(&token::BINOP(token::AND));
36573662
}
36583663
}

src/test/compile-fail/regions-bounds.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ struct an_enum(&'self int);
1616
struct a_class { x:&'self int }
1717

1818
fn a_fn1(e: an_enum<'a>) -> an_enum<'b> {
19-
return e; //~ ERROR mismatched types: expected `an_enum/&b` but found `an_enum/&a`
19+
return e; //~ ERROR mismatched types: expected `an_enum/&'b ` but found `an_enum/&'a `
2020
}
2121

2222
fn a_fn3(e: a_class<'a>) -> a_class<'b> {
23-
return e; //~ ERROR mismatched types: expected `a_class/&b` but found `a_class/&a`
23+
return e; //~ ERROR mismatched types: expected `a_class/&'b ` but found `a_class/&'a `
2424
}
2525

2626
fn a_fn4(e: int<'a>) -> int<'b> {
+11-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// xfail-test
2+
// xfail'd because the first error does not show up.
3+
14
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
25
// file at the top-level directory of this distribution and at
36
// http://rust-lang.org/COPYRIGHT.
@@ -8,8 +11,8 @@
811
// option. This file may not be copied, modified, or distributed
912
// except according to those terms.
1013

11-
fn of<T>() -> @fn(T) { fail!(); }
12-
fn subtype<T>(x: @fn(T)) { fail!(); }
14+
fn of<T>() -> &fn(T) { fail!(); }
15+
fn subtype<T>(x: &fn(T)) { fail!(); }
1316

1417
fn test_fn<T>(_x: &'x T, _y: &'y T, _z: &'z T) {
1518
// Here, x, y, and z are free. Other letters
@@ -18,14 +21,14 @@ fn test_fn<T>(_x: &'x T, _y: &'y T, _z: &'z T) {
1821
// iff T1 <: T2.
1922

2023
// should be the default:
21-
subtype::<@static/fn()>(of::<@fn()>());
22-
subtype::<@fn()>(of::<@static/fn()>());
24+
subtype::<&'static fn()>(of::<&fn()>());
25+
subtype::<&fn()>(of::<&'static fn()>());
2326

2427
//
25-
subtype::<@x/fn()>(of::<@fn()>()); //~ ERROR mismatched types
26-
subtype::<@x/fn()>(of::<@y/fn()>()); //~ ERROR mismatched types
28+
subtype::<&'x fn()>(of::<&fn()>()); //~ ERROR mismatched types
29+
subtype::<&'x fn()>(of::<&'y fn()>()); //~ ERROR mismatched types
2730

28-
subtype::<@x/fn()>(of::<@static/fn()>()); //~ ERROR mismatched types
29-
subtype::<@static/fn()>(of::<@x/fn()>());
31+
subtype::<&'x fn()>(of::<&'static fn()>()); //~ ERROR mismatched types
32+
subtype::<&'static fn()>(of::<&'x fn()>());
3033

3134
}

0 commit comments

Comments
 (0)