Skip to content

Commit 6e5c5a6

Browse files
committed
auto merge of #10675 : LeoTestard/rust/lifetimes-no-keywords, r=brson
Fixes #10565. `'self` is still allowed for the moment, as it is used everywhere in the codebase. And I'm not sure if it still has a special meaning currently or not.
2 parents 6708c29 + 74757af commit 6e5c5a6

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/libsyntax/parse/lexer.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,17 @@ fn next_token_inner(rdr: @mut StringReader) -> token::Token {
774774
bump(rdr);
775775
}
776776
return with_str_from(rdr, start, |lifetime_name| {
777-
token::LIFETIME(str_to_ident(lifetime_name))
777+
let ident = str_to_ident(lifetime_name);
778+
let tok = &token::IDENT(ident, false);
779+
780+
if token::is_any_keyword(tok)
781+
&& !token::is_keyword(token::keywords::Static, tok)
782+
&& !token::is_keyword(token::keywords::Self, tok) {
783+
fatal_span(rdr, start, rdr.last_pos,
784+
~"invalid lifetime name");
785+
}
786+
787+
token::LIFETIME(ident)
778788
})
779789
}
780790

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
3+
// file at the top-level directory of this distribution and at
4+
// http://rust-lang.org/COPYRIGHT.
5+
//
6+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
7+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
8+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
9+
// option. This file may not be copied, modified, or distributed
10+
// except according to those terms.
11+
12+
fn foo(a: &'let int) { } //~ ERROR invalid lifetime name
13+
fn bar(a: &'static int) { }
14+
fn baz<'self>(a: &'self int) { }
15+
16+
fn main() { }

0 commit comments

Comments
 (0)