Skip to content

Commit

Permalink
libsyntax: Stop parsing old lifetimes, except for the ones on data ty…
Browse files Browse the repository at this point in the history
…pe declarations.
  • Loading branch information
pcwalton committed Mar 18, 2013
1 parent 299995c commit fc8c808
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/libcore/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ pub struct BytesReader {
mut pos: uint
}
impl Reader for BytesReader/&self {
impl Reader for BytesReader<'self> {
fn read(&self, bytes: &mut [u8], len: uint) -> uint {
let count = uint::min(len, self.bytes.len() - self.pos);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ pub impl<T> ResolveResult<T> {
}
}

pub enum TypeParameters/& {
pub enum TypeParameters<'self> {
NoTypeParameters, //< No type parameters.
HasTypeParameters(&'self Generics, //< Type parameters.
node_id, //< ID of the enclosing item
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
* as it does not already appear in scope.
*
* Case (b) says that if you have a type:
* type foo/& = ...;
* type foo<'self> = ...;
* type bar = fn(&foo, &a.foo)
* The fully expanded version of type bar is:
* type bar = fn(&'foo &, &a.foo/&a)
* type bar = fn(&'foo &, &a.foo<'a>)
* Note that the self region for the `foo` defaulted to `&` in the first
* case but `&a` in the second. Basically, defaults that appear inside
* an rptr (`&r.T`) use the region `r` that appears in the rptr.
Expand Down
43 changes: 21 additions & 22 deletions src/librustc/util/ppaux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,21 +132,21 @@ pub fn explain_region_and_span(cx: ctxt, region: ty::Region)
}

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

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

match br {
br_named(id) => fmt!("%s%s%s", prefix, *cx.sess.str_of(id),
sep),
br_self => fmt!("%sself%s", prefix, sep),
br_named(id) => fmt!("%s'%s ", prefix, *cx.sess.str_of(id)),
br_self => fmt!("%s'self ", prefix),
br_anon(_) => prefix.to_str(),
br_fresh(_) => prefix.to_str(),
br_cap_avoid(_, br) => bound_region_to_str_adorned(cx, prefix,
*br, sep)
br_cap_avoid(_, br) => bound_region_to_str_space(cx, prefix, *br)
}
}

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

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

// These printouts are concise. They do not contain all the information
Expand All @@ -209,13 +208,13 @@ pub fn region_to_str_adorned(cx: ctxt, prefix: &str,
// `explain_region()` or `note_and_explain_region()`.
match region {
re_scope(_) => prefix.to_str(),
re_bound(br) => bound_region_to_str_adorned(cx, prefix, br, sep),
re_free(_, br) => bound_region_to_str_adorned(cx, prefix, br, sep),
re_bound(br) => bound_region_to_str_space(cx, prefix, br),
re_free(_, br) => bound_region_to_str_space(cx, prefix, br),
re_infer(ReSkolemized(_, br)) => {
bound_region_to_str_adorned(cx, prefix, br, sep)
bound_region_to_str_space(cx, prefix, br)
}
re_infer(ReVar(_)) => prefix.to_str(),
re_static => fmt!("%sstatic%s", prefix, sep)
re_static => fmt!("%s'static ", prefix)
}
}

Expand All @@ -233,7 +232,7 @@ pub fn vstore_to_str(cx: ctxt, vs: ty::vstore) -> ~str {
ty::vstore_fixed(n) => fmt!("%u", n),
ty::vstore_uniq => ~"~",
ty::vstore_box => ~"@",
ty::vstore_slice(r) => region_to_str_adorned(cx, "&", r, "/")
ty::vstore_slice(r) => region_to_str_space(cx, "&", r)
}
}

Expand All @@ -242,7 +241,7 @@ pub fn trait_store_to_str(cx: ctxt, s: ty::TraitStore) -> ~str {
ty::BareTraitStore => ~"",
ty::UniqTraitStore => ~"~",
ty::BoxTraitStore => ~"@",
ty::RegionTraitStore(r) => region_to_str_adorned(cx, "&", r, "")
ty::RegionTraitStore(r) => region_to_str_space(cx, "&", r)
}
}

Expand All @@ -252,7 +251,7 @@ pub fn vstore_ty_to_str(cx: ctxt, ty: ~str, vs: ty::vstore) -> ~str {
fmt!("[%s * %s]", ty, vstore_to_str(cx, vs))
}
ty::vstore_slice(_) => {
fmt!("%s/%s", vstore_to_str(cx, vs), ty)
fmt!("%s %s", vstore_to_str(cx, vs), ty)
}
_ => fmt!("%s[%s]", vstore_to_str(cx, vs), ty)
}
Expand Down Expand Up @@ -344,7 +343,7 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str {
(ast::OwnedSigil, ty::re_static) => {}

(_, region) => {
s.push_str(region_to_str_adorned(cx, "", region, "/"));
s.push_str(region_to_str_space(cx, "", region));
}
}

Expand Down Expand Up @@ -418,7 +417,7 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str {
ty_uniq(tm) => ~"~" + mt_to_str(cx, tm),
ty_ptr(tm) => ~"*" + mt_to_str(cx, tm),
ty_rptr(r, tm) => {
region_to_str_adorned(cx, ~"&", r, ~"/") + mt_to_str(cx, tm)
region_to_str_space(cx, ~"&", r) + mt_to_str(cx, tm)
}
ty_unboxed_vec(tm) => { ~"unboxed_vec<" + mt_to_str(cx, tm) + ~">" }
ty_type => ~"type",
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ pub impl Sem<~[Waitqueue]> {

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

impl<Q:Owned> Drop for SemReleaseGeneric/&self<Q> {
Expand Down
6 changes: 6 additions & 0 deletions src/libsyntax/parse/obsolete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub enum ObsoleteSyntax {
ObsoleteNewtypeEnum,
ObsoleteMode,
ObsoleteImplicitSelf,
ObsoleteLifetimeNotation,
}

impl to_bytes::IterBytes for ObsoleteSyntax {
Expand Down Expand Up @@ -187,6 +188,11 @@ pub impl Parser {
"use an explicit `self` declaration or declare the method as \
static"
),
ObsoleteLifetimeNotation => (
"`/` lifetime notation",
"instead of `&foo/bar`, write `&'foo bar`; instead of \
`bar/&foo`, write `&bar<'foo>"
),
};

self.report(sp, kind, kind_str, desc);
Expand Down
5 changes: 5 additions & 0 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +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::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};
Expand Down Expand Up @@ -686,6 +687,7 @@ pub impl Parser {
self.token_is_closure_keyword(&self.look_ahead(2u))
{
let lifetime = @self.parse_lifetime();
self.obsolete(*self.last_span, ObsoleteLifetimeNotation);
return self.parse_ty_closure(sigil, Some(lifetime));
} else if self.token_is_closure_keyword(&copy *self.token) {
return self.parse_ty_closure(sigil, None);
Expand Down Expand Up @@ -963,6 +965,7 @@ pub impl Parser {
// Also accept the (obsolete) syntax `foo/`
token::IDENT(*) => {
if self.look_ahead(1u) == token::BINOP(token::SLASH) {
self.obsolete(*self.last_span, ObsoleteLifetimeNotation);
Some(@self.parse_lifetime())
} else {
None
Expand Down Expand Up @@ -997,6 +1000,7 @@ pub impl Parser {
let span = copy self.span;
self.bump();
self.expect(&token::BINOP(token::SLASH));
self.obsolete(*self.last_span, ObsoleteLifetimeNotation);
return ast::Lifetime {
id: self.get_id(),
span: *span,
Expand Down Expand Up @@ -3653,6 +3657,7 @@ pub impl Parser {

fn parse_region_param(&self) {
if self.eat(&token::BINOP(token::SLASH)) {
self.obsolete(*self.last_span, ObsoleteLifetimeNotation);
self.expect(&token::BINOP(token::AND));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/regions-bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ struct an_enum(&'self int);
struct a_class { x:&'self int }

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

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

fn a_fn4(e: int<'a>) -> int<'b> {
Expand Down
19 changes: 11 additions & 8 deletions src/test/compile-fail/regions-fn-bound.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// xfail-test
// xfail'd because the first error does not show up.

// 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.
Expand All @@ -8,8 +11,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn of<T>() -> @fn(T) { fail!(); }
fn subtype<T>(x: @fn(T)) { fail!(); }
fn of<T>() -> &fn(T) { fail!(); }
fn subtype<T>(x: &fn(T)) { fail!(); }

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

// should be the default:
subtype::<@static/fn()>(of::<@fn()>());
subtype::<@fn()>(of::<@static/fn()>());
subtype::<&'static fn()>(of::<&fn()>());
subtype::<&fn()>(of::<&'static fn()>());

//
subtype::<@x/fn()>(of::<@fn()>()); //~ ERROR mismatched types
subtype::<@x/fn()>(of::<@y/fn()>()); //~ ERROR mismatched types
subtype::<&'x fn()>(of::<&fn()>()); //~ ERROR mismatched types
subtype::<&'x fn()>(of::<&'y fn()>()); //~ ERROR mismatched types

subtype::<@x/fn()>(of::<@static/fn()>()); //~ ERROR mismatched types
subtype::<@static/fn()>(of::<@x/fn()>());
subtype::<&'x fn()>(of::<&'static fn()>()); //~ ERROR mismatched types
subtype::<&'static fn()>(of::<&'x fn()>());

}

0 comments on commit fc8c808

Please sign in to comment.