Skip to content

Commit

Permalink
Forbid keywords as lifetime parameters names.
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoTestard committed Dec 5, 2013
1 parent 617ce85 commit 74757af
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/libsyntax/parse/lexer.rs
Expand Up @@ -774,7 +774,17 @@ fn next_token_inner(rdr: @mut StringReader) -> token::Token {
bump(rdr);
}
return with_str_from(rdr, start, |lifetime_name| {
token::LIFETIME(str_to_ident(lifetime_name))
let ident = str_to_ident(lifetime_name);
let tok = &token::IDENT(ident, false);

if token::is_any_keyword(tok)
&& !token::is_keyword(token::keywords::Static, tok)
&& !token::is_keyword(token::keywords::Self, tok) {
fatal_span(rdr, start, rdr.last_pos,
~"invalid lifetime name");
}

token::LIFETIME(ident)
})
}

Expand Down
16 changes: 16 additions & 0 deletions src/test/compile-fail/lifetime-no-keyword.rs
@@ -0,0 +1,16 @@

// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn foo(a: &'let int) { } //~ ERROR invalid lifetime name
fn bar(a: &'static int) { }
fn baz<'self>(a: &'self int) { }

fn main() { }

5 comments on commit 74757af

@bors
Copy link
Contributor

@bors bors commented on 74757af Dec 6, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from brson
at LeoTestard@74757af

@bors
Copy link
Contributor

@bors bors commented on 74757af Dec 6, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging LeoTestard/rust/lifetimes-no-keywords = 74757af into auto

@bors
Copy link
Contributor

@bors bors commented on 74757af Dec 6, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LeoTestard/rust/lifetimes-no-keywords = 74757af merged ok, testing candidate = 6e5c5a6

@bors
Copy link
Contributor

@bors bors commented on 74757af Dec 6, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 74757af Dec 6, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 6e5c5a6

Please sign in to comment.