Skip to content

Commit 0c82c00

Browse files
committed
libsyntax: Remove the restricted keyword concept
1 parent 76f8cfb commit 0c82c00

File tree

3 files changed

+4
-58
lines changed

3 files changed

+4
-58
lines changed

src/libsyntax/parse/common.rs

-24
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ trait parser_common {
3737
fn is_any_keyword(tok: token::token) -> bool;
3838
fn eat_keyword(word: ~str) -> bool;
3939
fn expect_keyword(word: ~str);
40-
fn is_restricted_keyword(word: ~str) -> bool;
41-
fn check_restricted_keywords();
42-
fn check_restricted_keywords_(w: ~str);
4340
fn expect_gt();
4441
fn parse_seq_to_before_gt<T: Copy>(sep: Option<token::token>,
4542
f: fn(parser) -> T) -> ~[T];
@@ -104,7 +101,6 @@ impl parser: parser_common {
104101
}
105102

106103
fn parse_value_ident() -> ast::ident {
107-
self.check_restricted_keywords();
108104
return self.parse_ident();
109105
}
110106

@@ -165,26 +161,6 @@ impl parser: parser_common {
165161
}
166162
}
167163

168-
fn is_restricted_keyword(word: ~str) -> bool {
169-
self.restricted_keywords.contains_key_ref(&word)
170-
}
171-
172-
fn check_restricted_keywords() {
173-
match self.token {
174-
token::IDENT(_, false) => {
175-
let w = token_to_str(self.reader, self.token);
176-
self.check_restricted_keywords_(w);
177-
}
178-
_ => ()
179-
}
180-
}
181-
182-
fn check_restricted_keywords_(w: ~str) {
183-
if self.is_restricted_keyword(w) {
184-
self.fatal(~"found `" + w + ~"` in restricted position");
185-
}
186-
}
187-
188164
fn is_strict_keyword(word: ~str) -> bool {
189165
self.strict_keywords.contains_key_ref(&word)
190166
}

src/libsyntax/parse/parser.rs

-3
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ fn parser(sess: parse_sess, cfg: ast::crate_cfg,
217217
restriction: UNRESTRICTED,
218218
quote_depth: 0u,
219219
keywords: token::keyword_table(),
220-
restricted_keywords: token::restricted_keyword_table(),
221220
strict_keywords: token::strict_keyword_table(),
222221
reserved_keywords: token::reserved_keyword_table(),
223222
obsolete_set: std::map::HashMap(),
@@ -239,7 +238,6 @@ struct parser {
239238
reader: reader,
240239
interner: interner<@~str>,
241240
keywords: HashMap<~str, ()>,
242-
restricted_keywords: HashMap<~str, ()>,
243241
strict_keywords: HashMap<~str, ()>,
244242
reserved_keywords: HashMap<~str, ()>,
245243
/// The set of seen errors about obsolete syntax. Used to suppress
@@ -3200,7 +3198,6 @@ impl parser {
32003198
let ty_params = self.parse_ty_params();
32013199
// Newtype syntax
32023200
if self.token == token::EQ {
3203-
self.check_restricted_keywords_(*self.id_to_str(id));
32043201
self.bump();
32053202
let ty = self.parse_ty(false);
32063203
self.expect(token::SEMI);

src/libsyntax/parse/token.rs

+4-31
Original file line numberDiff line numberDiff line change
@@ -362,20 +362,17 @@ fn mk_fake_ident_interner() -> ident_interner {
362362
/**
363363
* All the valid words that have meaning in the Rust language.
364364
*
365-
* Rust keywords are either 'temporary', 'restricted', or 'strict'. Temporary
365+
* Rust keywords are either 'temporary', 'strict' or 'reserved'. Temporary
366366
* keywords are contextual and may be used as identifiers anywhere. They are
367-
* expected to disappear from the grammar soon. Restricted keywords may not
368-
* appear in positions that might otherwise contain _value identifiers_.
369-
* Strict keywords may not appear as identifiers at all.
367+
* expected to disappear from the grammar soon. Strict keywords may not
368+
* appear as identifiers at all. Reserved keywords are not used anywhere in
369+
* the language and may not appear as identifiers.
370370
*/
371371
fn keyword_table() -> HashMap<~str, ()> {
372372
let keywords = str_hash();
373373
for temporary_keyword_table().each_key |word| {
374374
keywords.insert(word, ());
375375
}
376-
for restricted_keyword_table().each_key |word| {
377-
keywords.insert(word, ());
378-
}
379376
for strict_keyword_table().each_key |word| {
380377
keywords.insert(word, ());
381378
}
@@ -397,30 +394,6 @@ fn temporary_keyword_table() -> HashMap<~str, ()> {
397394
words
398395
}
399396

400-
/**
401-
* Keywords that may not appear in any position that might otherwise contain a
402-
* _value identifier_. Restricted keywords may still be used as other types of
403-
* identifiers.
404-
*
405-
* Reasons:
406-
*
407-
* * For some (most?), if used at the start of a line, they will cause the
408-
* line to be interpreted as a specific kind of statement, which would be
409-
* confusing.
410-
*
411-
* * `true` or `false` as identifiers would always be shadowed by
412-
* the boolean constants
413-
*/
414-
fn restricted_keyword_table() -> HashMap<~str, ()> {
415-
let words = str_hash();
416-
let keys = ~[
417-
];
418-
for keys.each |word| {
419-
words.insert(word, ());
420-
}
421-
words
422-
}
423-
424397
/// Full keywords. May not appear anywhere else.
425398
fn strict_keyword_table() -> HashMap<~str, ()> {
426399
let words = str_hash();

0 commit comments

Comments
 (0)