Skip to content

Commit ebe9ec8

Browse files
committed
rollup merge of #17379 : pcwalton/keywords-followed-by-double-colon
2 parents 0e18c06 + 5aa264a commit ebe9ec8

File tree

2 files changed

+63
-35
lines changed

2 files changed

+63
-35
lines changed

src/libsyntax/parse/token.rs

+48-35
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,11 @@ macro_rules! declare_special_idents_and_keywords {(
431431
// If the special idents get renumbered, remember to modify these two as appropriate
432432
pub static SELF_KEYWORD_NAME: Name = Name(SELF_KEYWORD_NAME_NUM);
433433
static STATIC_KEYWORD_NAME: Name = Name(STATIC_KEYWORD_NAME_NUM);
434+
static SUPER_KEYWORD_NAME: Name = Name(SUPER_KEYWORD_NAME_NUM);
434435

435436
pub static SELF_KEYWORD_NAME_NUM: u32 = 1;
436437
static STATIC_KEYWORD_NAME_NUM: u32 = 2;
438+
static SUPER_KEYWORD_NAME_NUM: u32 = 3;
437439

438440
// NB: leaving holes in the ident table is bad! a different ident will get
439441
// interned with the id from the hole, but it will be between the min and max
@@ -443,52 +445,53 @@ declare_special_idents_and_keywords! {
443445
pub mod special_idents {
444446
// These ones are statics
445447
(0, invalid, "");
446-
(super::SELF_KEYWORD_NAME_NUM, self_, "self");
447-
(super::STATIC_KEYWORD_NAME_NUM, statik, "static");
448-
(3, static_lifetime, "'static");
448+
(super::SELF_KEYWORD_NAME_NUM, self_, "self");
449+
(super::STATIC_KEYWORD_NAME_NUM, statik, "static");
450+
(super::SUPER_KEYWORD_NAME_NUM, super_, "super");
451+
(4, static_lifetime, "'static");
449452

450453
// for matcher NTs
451-
(4, tt, "tt");
452-
(5, matchers, "matchers");
454+
(5, tt, "tt");
455+
(6, matchers, "matchers");
453456

454457
// outside of libsyntax
455-
(6, clownshoe_abi, "__rust_abi");
456-
(7, opaque, "<opaque>");
457-
(8, unnamed_field, "<unnamed_field>");
458-
(9, type_self, "Self");
459-
(10, prelude_import, "prelude_import");
458+
(7, clownshoe_abi, "__rust_abi");
459+
(8, opaque, "<opaque>");
460+
(9, unnamed_field, "<unnamed_field>");
461+
(10, type_self, "Self");
462+
(11, prelude_import, "prelude_import");
460463
}
461464

462465
pub mod keywords {
463466
// These ones are variants of the Keyword enum
464467

465468
'strict:
466-
(11, As, "as");
467-
(12, Break, "break");
468-
(13, Crate, "crate");
469-
(14, Else, "else");
470-
(15, Enum, "enum");
471-
(16, Extern, "extern");
472-
(17, False, "false");
473-
(18, Fn, "fn");
474-
(19, For, "for");
475-
(20, If, "if");
476-
(21, Impl, "impl");
477-
(22, In, "in");
478-
(23, Let, "let");
479-
(24, Loop, "loop");
480-
(25, Match, "match");
481-
(26, Mod, "mod");
482-
(27, Mut, "mut");
483-
(28, Once, "once");
484-
(29, Pub, "pub");
485-
(30, Ref, "ref");
486-
(31, Return, "return");
469+
(12, As, "as");
470+
(13, Break, "break");
471+
(14, Crate, "crate");
472+
(15, Else, "else");
473+
(16, Enum, "enum");
474+
(17, Extern, "extern");
475+
(18, False, "false");
476+
(19, Fn, "fn");
477+
(20, For, "for");
478+
(21, If, "if");
479+
(22, Impl, "impl");
480+
(23, In, "in");
481+
(24, Let, "let");
482+
(25, Loop, "loop");
483+
(26, Match, "match");
484+
(27, Mod, "mod");
485+
(28, Mut, "mut");
486+
(29, Once, "once");
487+
(30, Pub, "pub");
488+
(31, Ref, "ref");
489+
(32, Return, "return");
487490
// Static and Self are also special idents (prefill de-dupes)
488-
(super::STATIC_KEYWORD_NAME_NUM, Static, "static");
489-
(super::SELF_KEYWORD_NAME_NUM, Self, "self");
490-
(32, Struct, "struct");
491-
(33, Super, "super");
491+
(super::STATIC_KEYWORD_NAME_NUM, Static, "static");
492+
(super::SELF_KEYWORD_NAME_NUM, Self, "self");
493+
(33, Struct, "struct");
494+
(super::SUPER_KEYWORD_NAME_NUM, Super, "super");
492495
(34, True, "true");
493496
(35, Trait, "trait");
494497
(36, Type, "type");
@@ -713,6 +716,7 @@ pub fn is_any_keyword(tok: &Token) -> bool {
713716

714717
n == SELF_KEYWORD_NAME
715718
|| n == STATIC_KEYWORD_NAME
719+
|| n == SUPER_KEYWORD_NAME
716720
|| STRICT_KEYWORD_START <= n
717721
&& n <= RESERVED_KEYWORD_FINAL
718722
},
@@ -727,9 +731,18 @@ pub fn is_strict_keyword(tok: &Token) -> bool {
727731

728732
n == SELF_KEYWORD_NAME
729733
|| n == STATIC_KEYWORD_NAME
734+
|| n == SUPER_KEYWORD_NAME
730735
|| STRICT_KEYWORD_START <= n
731736
&& n <= STRICT_KEYWORD_FINAL
732737
},
738+
token::IDENT(sid, true) => {
739+
let n = sid.name;
740+
741+
n != SELF_KEYWORD_NAME
742+
&& n != SUPER_KEYWORD_NAME
743+
&& STRICT_KEYWORD_START <= n
744+
&& n <= STRICT_KEYWORD_FINAL
745+
}
733746
_ => false,
734747
}
735748
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
struct::foo(); //~ ERROR expected identifier
13+
mut::baz(); //~ ERROR expected identifier
14+
}
15+

0 commit comments

Comments
 (0)