libsyntax/librustc: Allow specifying mut on by-value self.

This commit is contained in:
Luqman Aden 2013-10-20 01:55:23 -04:00
parent 22a5ebdc6b
commit 5754848f8c
20 changed files with 53 additions and 43 deletions

View file

@ -3438,15 +3438,11 @@ impl Parser {
// parse the argument list and result type of a function
// that may have a self type.
fn parse_fn_decl_with_self(
&self,
parse_arg_fn:
&fn(&Parser) -> arg
) -> (explicit_self, fn_decl) {
fn maybe_parse_explicit_self(
cnstr: &fn(v: Mutability) -> ast::explicit_self_,
p: &Parser
) -> ast::explicit_self_ {
fn parse_fn_decl_with_self(&self, parse_arg_fn: &fn(&Parser) -> arg)
-> (explicit_self, fn_decl) {
fn maybe_parse_explicit_self(cnstr: &fn(v: Mutability) -> ast::explicit_self_,
p: &Parser) -> ast::explicit_self_ {
// We need to make sure it isn't a type
if p.look_ahead(1, |t| token::is_keyword(keywords::Self, t)) ||
((p.look_ahead(1, |t| token::is_keyword(keywords::Const, t)) ||
@ -3529,20 +3525,26 @@ impl Parser {
}
token::IDENT(*) if self.is_self_ident() => {
self.bump();
sty_value
sty_value(MutImmutable)
}
token::BINOP(token::STAR) => {
// Possibly "*self" or "*mut self" -- not supported. Try to avoid
// emitting cryptic "unexpected token" errors.
self.bump();
if self.token_is_mutability(self.token) {
self.bump();
}
let mutability = if self.token_is_mutability(self.token) {
self.parse_mutability()
} else { MutImmutable };
if self.is_self_ident() {
self.span_err(*self.span, "cannot pass self by unsafe pointer");
self.bump();
}
sty_value
sty_value(mutability)
}
_ if self.token_is_mutability(self.token) &&
self.look_ahead(1, |t| token::is_keyword(keywords::Self, t)) => {
let mutability = self.parse_mutability();
self.expect_self_ident();
sty_value(mutability)
}
_ => {
sty_static