Skip to content

Commit e2c821d

Browse files
committed
syntax: Make static/super/self/Self keywords + special ident cleanup
1 parent 546c052 commit e2c821d

File tree

28 files changed

+138
-188
lines changed

28 files changed

+138
-188
lines changed

src/librustc/hir/fold.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ pub fn noop_fold_crate<T: Folder>(Crate { module, attrs, config, span,
867867
let config = folder.fold_meta_items(config);
868868

869869
let crate_mod = folder.fold_item(hir::Item {
870-
name: token::special_idents::invalid.name,
870+
name: token::special_idents::Invalid.name,
871871
attrs: attrs,
872872
id: DUMMY_NODE_ID,
873873
vis: hir::Public,

src/librustc/hir/print.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2211,7 +2211,7 @@ impl<'a> State<'a> {
22112211
match input.pat.node {
22122212
PatKind::Ident(_, ref path1, _) if
22132213
path1.node.name ==
2214-
parse::token::special_idents::invalid.name => {
2214+
parse::token::special_idents::Invalid.name => {
22152215
// Do nothing.
22162216
}
22172217
_ => {

src/librustc/middle/liveness.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ use std::io;
125125
use std::rc::Rc;
126126
use syntax::ast::{self, NodeId};
127127
use syntax::codemap::{BytePos, original_sp, Span};
128-
use syntax::parse::token::special_idents;
128+
use syntax::parse::token::keywords;
129129
use syntax::ptr::P;
130130

131131
use hir::Expr;
@@ -1578,7 +1578,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
15781578
let var = self.variable(p_id, sp);
15791579
// Ignore unused self.
15801580
let name = path1.node;
1581-
if name != special_idents::self_.name {
1581+
if name != keywords::SelfValue.ident.name {
15821582
if !self.warn_about_unused(sp, p_id, entry_ln, var) {
15831583
if self.live_on_entry(entry_ln, var).is_none() {
15841584
self.report_dead_assign(p_id, sp, var, true);

src/librustc/middle/resolve_lifetime.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
245245
}
246246

247247
fn visit_lifetime(&mut self, lifetime_ref: &hir::Lifetime) {
248-
if lifetime_ref.name == special_idents::static_lifetime.name {
248+
if lifetime_ref.name == special_idents::StaticLifetime.name {
249249
self.insert_lifetime(lifetime_ref, DefStaticRegion);
250250
return;
251251
}
@@ -672,9 +672,8 @@ impl<'a> LifetimeContext<'a> {
672672
for i in 0..lifetimes.len() {
673673
let lifetime_i = &lifetimes[i];
674674

675-
let special_idents = [special_idents::static_lifetime];
676675
for lifetime in lifetimes {
677-
if special_idents.iter().any(|&i| i.name == lifetime.lifetime.name) {
676+
if lifetime.lifetime.name == special_idents::StaticLifetime.name {
678677
span_err!(self.sess, lifetime.lifetime.span, E0262,
679678
"invalid lifetime parameter name: `{}`", lifetime.lifetime.name);
680679
}

src/librustc/ty/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use std::hash::{Hash, Hasher};
4444
use std::rc::Rc;
4545
use syntax::ast::{self, Name, NodeId};
4646
use syntax::attr;
47-
use syntax::parse::token::{self, special_idents};
47+
use syntax::parse::token::{self, keywords};
4848

4949
use hir;
5050

@@ -1069,7 +1069,7 @@ impl<'tcx> TyCtxt<'tcx> {
10691069
}
10701070

10711071
pub fn mk_self_type(&self) -> Ty<'tcx> {
1072-
self.mk_param(subst::SelfSpace, 0, special_idents::type_self.name)
1072+
self.mk_param(subst::SelfSpace, 0, keywords::SelfType.ident.name)
10731073
}
10741074

10751075
pub fn mk_param_from_def(&self, def: &ty::TypeParameterDef) -> Ty<'tcx> {

src/librustc/ty/sty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use std::ops;
2424
use std::mem;
2525
use syntax::abi;
2626
use syntax::ast::{self, Name};
27-
use syntax::parse::token::special_idents;
27+
use syntax::parse::token::keywords;
2828

2929
use serialize::{Decodable, Decoder};
3030

@@ -533,7 +533,7 @@ impl ParamTy {
533533
}
534534

535535
pub fn for_self() -> ParamTy {
536-
ParamTy::new(subst::SelfSpace, 0, special_idents::type_self.name)
536+
ParamTy::new(subst::SelfSpace, 0, keywords::SelfType.ident.name)
537537
}
538538

539539
pub fn for_def(def: &ty::TypeParameterDef) -> ParamTy {

src/librustc_resolve/lib.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ use syntax::ast::{CRATE_NODE_ID, Name, NodeId, CrateNum, IntTy, UintTy};
6262
use syntax::attr::AttrMetaMethods;
6363
use syntax::codemap::{self, Span, Pos};
6464
use syntax::errors::DiagnosticBuilder;
65-
use syntax::parse::token::{self, special_names, special_idents};
65+
use syntax::parse::token::{self, keywords, special_idents};
6666
use syntax::util::lev_distance::find_best_match_for_name;
6767

6868
use rustc::hir::intravisit::{self, FnKind, Visitor};
@@ -1954,8 +1954,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
19541954
let mut self_type_rib = Rib::new(NormalRibKind);
19551955

19561956
// plain insert (no renaming, types are not currently hygienic....)
1957-
let name = special_names::type_self;
1958-
self_type_rib.bindings.insert(name, self_def);
1957+
self_type_rib.bindings.insert(keywords::SelfType.ident.name, self_def);
19591958
self.type_ribs.push(self_type_rib);
19601959
f(self);
19611960
if !self.resolved {
@@ -2195,11 +2194,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
21952194
"type name"
21962195
};
21972196

2198-
let self_type_name = special_idents::type_self.name;
21992197
let is_invalid_self_type_name = path.segments.len() > 0 &&
22002198
maybe_qself.is_none() &&
22012199
path.segments[0].identifier.name ==
2202-
self_type_name;
2200+
keywords::SelfType.ident.name;
22032201
if is_invalid_self_type_name {
22042202
resolve_error(self,
22052203
ty.span,
@@ -2643,7 +2641,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
26432641
namespace: Namespace,
26442642
record_used: bool)
26452643
-> Option<LocalDef> {
2646-
if identifier.name == special_idents::invalid.name {
2644+
if identifier.name == special_idents::Invalid.name {
26472645
return Some(LocalDef::from_def(Def::Err));
26482646
}
26492647

@@ -3074,7 +3072,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
30743072
false // Stop advancing
30753073
});
30763074

3077-
if method_scope && special_names::self_.as_str() == &path_name[..] {
3075+
if method_scope &&
3076+
&path_name[..] == keywords::SelfValue.ident.name.as_str() {
30783077
resolve_error(self,
30793078
expr.span,
30803079
ResolutionError::SelfNotAvailableInStaticMethod);
@@ -3612,7 +3611,7 @@ fn module_to_string(module: Module) -> String {
36123611
}
36133612
BlockParentLink(ref module, _) => {
36143613
// danger, shouldn't be ident?
3615-
names.push(special_idents::opaque.name);
3614+
names.push(token::intern("<opaque>"));
36163615
collect_mod(names, module);
36173616
}
36183617
}

src/librustc_save_analysis/dump_visitor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ impl<'v, 'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor<'v> for DumpVisitor<'l, 'tcx,
10111011
span: sub_span.expect("No span found for use"),
10121012
id: item.id,
10131013
mod_id: mod_id,
1014-
name: ident.name.to_string(),
1014+
name: ident.to_string(),
10151015
scope: self.cur_scope
10161016
}.normalize(&self.tcx));
10171017
}
@@ -1075,7 +1075,7 @@ impl<'v, 'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor<'v> for DumpVisitor<'l, 'tcx,
10751075
if !self.span.filter_generated(alias_span, item.span) {
10761076
self.dumper.extern_crate(item.span, ExternCrateData {
10771077
id: item.id,
1078-
name: item.ident.name.to_string(),
1078+
name: item.ident.to_string(),
10791079
crate_num: cnum,
10801080
location: location,
10811081
span: alias_span.expect("No span found for extern crate"),

src/librustc_trans/mir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ fn arg_value_refs<'bcx, 'tcx>(bcx: &BlockAndBuilder<'bcx, 'tcx>,
286286
alloca: lltemp,
287287
address_operations: &ops
288288
};
289-
declare_local(bcx, token::special_idents::invalid.name,
289+
declare_local(bcx, token::special_idents::Invalid.name,
290290
tupled_arg_ty, scope, variable_access,
291291
VariableKind::ArgumentVariable(arg_index + i + 1),
292292
bcx.fcx().span.unwrap_or(DUMMY_SP));

src/librustc_typeck/astconv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,7 @@ fn associated_path_def_to_ty<'tcx>(this: &AstConv<'tcx>,
13131313
let trait_node_id = tcx.map.as_local_node_id(trait_did).unwrap();
13141314
match find_bound_for_assoc_item(this,
13151315
trait_node_id,
1316-
token::special_idents::type_self.name,
1316+
token::keywords::SelfType.ident.name,
13171317
assoc_name,
13181318
span) {
13191319
Ok(bound) => bound,

src/librustc_typeck/check/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2851,7 +2851,7 @@ fn check_expr_with_expectation_and_lvalue_pref<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
28512851
method_ty
28522852
}
28532853
Err(error) => {
2854-
if method_name.node != special_idents::invalid.name {
2854+
if method_name.node != special_idents::Invalid.name {
28552855
method::report_error(fcx, method_name.span, expr_t,
28562856
method_name.node, Some(rcvr), error);
28572857
}
@@ -2990,7 +2990,7 @@ fn check_expr_with_expectation_and_lvalue_pref<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
29902990
let msg = format!("field `{}` of struct `{}` is private", field.node, struct_path);
29912991
fcx.tcx().sess.span_err(expr.span, &msg);
29922992
fcx.write_ty(expr.id, field_ty);
2993-
} else if field.node == special_idents::invalid.name {
2993+
} else if field.node == special_idents::Invalid.name {
29942994
fcx.write_error(expr.id);
29952995
} else if method::exists(fcx, field.span, field.node, expr_t, expr.id) {
29962996
fcx.type_error_struct(field.span,
@@ -3780,7 +3780,7 @@ pub fn resolve_ty_and_def_ufcs<'a, 'b, 'tcx>(fcx: &FnCtxt<'b, 'tcx>,
37803780
method::MethodError::PrivateMatch(def) => Some(def),
37813781
_ => None,
37823782
};
3783-
if item_name != special_idents::invalid.name {
3783+
if item_name != special_idents::Invalid.name {
37843784
method::report_error(fcx, span, ty, item_name, None, error);
37853785
}
37863786
def

src/librustc_typeck/check/wfcheck.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use std::collections::HashSet;
2424
use syntax::ast;
2525
use syntax::codemap::{Span};
2626
use syntax::errors::DiagnosticBuilder;
27-
use syntax::parse::token::{special_idents};
27+
use syntax::parse::token::keywords;
2828
use rustc::hir::intravisit::{self, Visitor};
2929
use rustc::hir;
3030

@@ -472,7 +472,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
472472
{
473473
let name = match space {
474474
TypeSpace => ast_generics.ty_params[index].name,
475-
SelfSpace => special_idents::type_self.name,
475+
SelfSpace => keywords::SelfType.ident.name,
476476
FnSpace => bug!("Fn space occupied?"),
477477
};
478478

src/librustc_typeck/collect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ use syntax::abi;
9393
use syntax::ast;
9494
use syntax::attr;
9595
use syntax::codemap::Span;
96-
use syntax::parse::token::special_idents;
96+
use syntax::parse::token::keywords;
9797
use syntax::ptr::P;
9898
use rustc::hir::{self, PatKind};
9999
use rustc::hir::intravisit;
@@ -1655,7 +1655,7 @@ fn ty_generics_for_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
16551655
let def = ty::TypeParameterDef {
16561656
space: SelfSpace,
16571657
index: 0,
1658-
name: special_idents::type_self.name,
1658+
name: keywords::SelfType.ident.name,
16591659
def_id: ccx.tcx.map.local_def_id(param_id),
16601660
default_def_id: ccx.tcx.map.local_def_id(parent),
16611661
default: None,

src/librustdoc/clean/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use syntax::attr;
3131
use syntax::attr::{AttributeMethods, AttrMetaMethods};
3232
use syntax::codemap;
3333
use syntax::codemap::{DUMMY_SP, Pos, Spanned};
34-
use syntax::parse::token::{self, InternedString, special_idents};
34+
use syntax::parse::token::{self, InternedString, keywords};
3535
use syntax::ptr::P;
3636

3737
use rustc_trans::back::link;
@@ -2666,7 +2666,7 @@ fn resolve_type(cx: &DocContext,
26662666
hir::TyFloat(ast::FloatTy::F64) => return Primitive(F64),
26672667
},
26682668
Def::SelfTy(..) if path.segments.len() == 1 => {
2669-
return Generic(special_idents::type_self.name.to_string());
2669+
return Generic(keywords::SelfType.ident.to_string());
26702670
}
26712671
Def::SelfTy(..) | Def::TyParam(..) => true,
26722672
_ => false,

src/libsyntax/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl Ident {
9393
pub fn new(name: Name, ctxt: SyntaxContext) -> Ident {
9494
Ident {name: name, ctxt: ctxt}
9595
}
96-
pub fn with_empty_ctxt(name: Name) -> Ident {
96+
pub const fn with_empty_ctxt(name: Name) -> Ident {
9797
Ident {name: name, ctxt: EMPTY_CTXT}
9898
}
9999
}

src/libsyntax/ext/build.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use ast::{self, Ident, Generics, Expr, BlockCheckMode, UnOp, PatKind};
1313
use attr;
1414
use codemap::{Span, respan, Spanned, DUMMY_SP, Pos};
1515
use ext::base::ExtCtxt;
16-
use parse::token::special_idents;
16+
use parse::token::{keywords, special_idents};
1717
use parse::token::InternedString;
1818
use parse::token;
1919
use ptr::P;
@@ -602,7 +602,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
602602
self.expr_path(self.path_ident(span, id))
603603
}
604604
fn expr_self(&self, span: Span) -> P<ast::Expr> {
605-
self.expr_ident(span, special_idents::self_)
605+
self.expr_ident(span, keywords::SelfValue.ident)
606606
}
607607

608608
fn expr_binary(&self, sp: Span, op: ast::BinOpKind,
@@ -1132,7 +1132,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
11321132
vis: ast::Visibility, vp: P<ast::ViewPath>) -> P<ast::Item> {
11331133
P(ast::Item {
11341134
id: ast::DUMMY_NODE_ID,
1135-
ident: special_idents::invalid,
1135+
ident: special_idents::Invalid,
11361136
attrs: vec![],
11371137
node: ast::ItemKind::Use(vp),
11381138
vis: vis,

src/libsyntax/ext/expand.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ pub fn expand_item_mac(it: P<ast::Item>,
380380

381381
Some(rc) => match *rc {
382382
NormalTT(ref expander, tt_span, allow_internal_unstable) => {
383-
if ident.name != parse::token::special_idents::invalid.name {
383+
if ident.name != parse::token::special_idents::Invalid.name {
384384
fld.cx
385385
.span_err(path_span,
386386
&format!("macro {}! expects no ident argument, given '{}'",
@@ -401,7 +401,7 @@ pub fn expand_item_mac(it: P<ast::Item>,
401401
expander.expand(fld.cx, span, &marked_before[..])
402402
}
403403
IdentTT(ref expander, tt_span, allow_internal_unstable) => {
404-
if ident.name == parse::token::special_idents::invalid.name {
404+
if ident.name == parse::token::special_idents::Invalid.name {
405405
fld.cx.span_err(path_span,
406406
&format!("macro {}! expects an ident argument",
407407
extname));
@@ -420,7 +420,7 @@ pub fn expand_item_mac(it: P<ast::Item>,
420420
expander.expand(fld.cx, span, ident, marked_tts)
421421
}
422422
MacroRulesTT => {
423-
if ident.name == parse::token::special_idents::invalid.name {
423+
if ident.name == parse::token::special_idents::Invalid.name {
424424
fld.cx.span_err(path_span, "macro_rules! expects an ident argument");
425425
return SmallVector::zero();
426426
}
@@ -893,7 +893,7 @@ fn expand_annotatable(a: Annotatable,
893893
}
894894
ast::ItemKind::Mod(_) | ast::ItemKind::ForeignMod(_) => {
895895
let valid_ident =
896-
it.ident.name != parse::token::special_idents::invalid.name;
896+
it.ident.name != parse::token::special_idents::Invalid.name;
897897

898898
if valid_ident {
899899
fld.cx.mod_push(it.ident);
@@ -1807,7 +1807,7 @@ mod tests {
18071807

18081808
// run one of the renaming tests
18091809
fn run_renaming_test(t: &RenamingTest, test_idx: usize) {
1810-
let invalid_name = token::special_idents::invalid.name;
1810+
let invalid_name = token::special_idents::Invalid.name;
18111811
let (teststr, bound_connections, bound_ident_check) = match *t {
18121812
(ref str,ref conns, bic) => (str.to_string(), conns.clone(), bic)
18131813
};

src/libsyntax/ext/tt/macro_rules.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use ext::tt::macro_parser::{MatchedSeq, MatchedNonterminal};
1717
use ext::tt::macro_parser::parse;
1818
use parse::lexer::new_tt_reader;
1919
use parse::parser::{Parser, Restrictions};
20-
use parse::token::{self, special_idents, gensym_ident, NtTT, Token};
20+
use parse::token::{self, gensym_ident, NtTT, Token};
2121
use parse::token::Token::*;
2222
use print;
2323
use ptr::P;
@@ -244,8 +244,8 @@ pub fn compile<'cx>(cx: &'cx mut ExtCtxt,
244244
// $( $lhs:tt => $rhs:tt );+
245245
// ...quasiquoting this would be nice.
246246
// These spans won't matter, anyways
247-
let match_lhs_tok = MatchNt(lhs_nm, special_idents::tt);
248-
let match_rhs_tok = MatchNt(rhs_nm, special_idents::tt);
247+
let match_lhs_tok = MatchNt(lhs_nm, token::str_to_ident("tt"));
248+
let match_rhs_tok = MatchNt(rhs_nm, token::str_to_ident("tt"));
249249
let argument_gram = vec!(
250250
TokenTree::Sequence(DUMMY_SP,
251251
Rc::new(ast::SequenceRepetition {

src/libsyntax/fold.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ pub fn noop_fold_crate<T: Folder>(Crate {module, attrs, config, mut exported_mac
10151015
let config = folder.fold_meta_items(config);
10161016

10171017
let mut items = folder.fold_item(P(ast::Item {
1018-
ident: token::special_idents::invalid,
1018+
ident: token::special_idents::Invalid,
10191019
attrs: attrs,
10201020
id: ast::DUMMY_NODE_ID,
10211021
vis: ast::Visibility::Public,

src/libsyntax/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#![cfg_attr(not(stage0), deny(warnings))]
2626

2727
#![feature(associated_consts)]
28+
#![feature(const_fn)]
2829
#![feature(filling_drop)]
2930
#![feature(libc)]
3031
#![feature(rustc_private)]

0 commit comments

Comments
 (0)