diff options
| author | bors <bors@rust-lang.org> | 2013-03-19 12:43:14 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-03-19 12:43:14 -0700 |
| commit | e1888948c640f8b8396091b336c2677cb82fdcce (patch) | |
| tree | ff3d02994510a741e117adf3d0f57d39b3623a1f /src/libsyntax/parse/parser.rs | |
| parent | a14ec73cd2d15a2454113011835557ccf447f14d (diff) | |
| parent | a6187c62e93ba96dce8f19849fb7016f4f941f8c (diff) | |
| download | rust-e1888948c640f8b8396091b336c2677cb82fdcce.tar.gz rust-e1888948c640f8b8396091b336c2677cb82fdcce.zip | |
auto merge of #5426 : nikomatsakis/rust/issue-4846-lifetimes-in-expl-self, r=pcwalton
(this will be needed for snapshotting at some point) r? @pcwalton
Diffstat (limited to 'src/libsyntax/parse/parser.rs')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index c7e93635d4c..6f4d9332df8 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -966,6 +966,13 @@ pub impl Parser { } } + fn token_is_lifetime(&self, tok: &token::Token) -> bool { + match *tok { + token::LIFETIME(_) => true, + _ => false + } + } + fn parse_lifetime(&self) -> ast::Lifetime { /*! * @@ -1033,6 +1040,11 @@ pub impl Parser { } } + fn token_is_mutability(&self, tok: &token::Token) -> bool { + self.token_is_keyword(&~"mut", tok) || + self.token_is_keyword(&~"const", tok) + } + fn parse_mutability(&self) -> mutability { if self.eat_keyword(&~"mut") { m_mutbl @@ -2837,6 +2849,55 @@ pub impl Parser { } } + fn maybe_parse_borrowed_self_ty( + self: &Parser + ) -> ast::self_ty_ { + // The following things are possible to see here: + // + // fn(&self) + // fn(&mut self) + // fn(&'lt self) + // fn(&'lt mut self) + // + // We already know that the current token is `&`. + + if ( + self.token_is_keyword(&~"self", &self.look_ahead(1))) + { + self.bump(); + self.expect_self_ident(); + sty_region(None, m_imm) + } else if ( + self.token_is_mutability(&self.look_ahead(1)) && + self.token_is_keyword(&~"self", &self.look_ahead(2))) + { + self.bump(); + let mutability = self.parse_mutability(); + self.expect_self_ident(); + sty_region(None, mutability) + } else if ( + self.token_is_lifetime(&self.look_ahead(1)) && + self.token_is_keyword(&~"self", &self.look_ahead(2))) + { + self.bump(); + let lifetime = @self.parse_lifetime(); + self.expect_self_ident(); + sty_region(Some(lifetime), m_imm) + } else if ( + self.token_is_lifetime(&self.look_ahead(1)) && + self.token_is_mutability(&self.look_ahead(2)) && + self.token_is_keyword(&~"self", &self.look_ahead(3))) + { + self.bump(); + let lifetime = @self.parse_lifetime(); + let mutability = self.parse_mutability(); + self.expect_self_ident(); + sty_region(Some(lifetime), mutability) + } else { + sty_by_ref + } + } + self.expect(&token::LPAREN); // A bit of complexity and lookahead is needed here in order to to be @@ -2844,7 +2905,7 @@ pub impl Parser { let lo = self.span.lo; let self_ty = match *self.token { token::BINOP(token::AND) => { - maybe_parse_self_ty(sty_region, self) + maybe_parse_borrowed_self_ty(self) } token::AT => { maybe_parse_self_ty(sty_box, self) |
