Skip to content

Commit f284cbc

Browse files
committed
Cleanup interfaces of Name, SyntaxContext and Ident
Make sure Name, SyntaxContext and Ident are passed by value Make sure Idents don't serve as keys (or parts of keys) in maps, Ident comparison is not well defined
1 parent 40ce804 commit f284cbc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+195
-254
lines changed

src/grammar/verify.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use syntax::parse::lexer::TokenAndSpan;
3535

3636
fn parse_token_list(file: &str) -> HashMap<String, token::Token> {
3737
fn id() -> token::Token {
38-
token::Ident(ast::Ident { name: Name(0), ctxt: 0, }, token::Plain)
38+
token::Ident(ast::Ident::with_empty_ctxt(Name(0))), token::Plain)
3939
}
4040

4141
let mut res = HashMap::new();
@@ -75,7 +75,7 @@ fn parse_token_list(file: &str) -> HashMap<String, token::Token> {
7575
"RPAREN" => token::CloseDelim(token::Paren),
7676
"SLASH" => token::BinOp(token::Slash),
7777
"COMMA" => token::Comma,
78-
"LIFETIME" => token::Lifetime(ast::Ident { name: Name(0), ctxt: 0 }),
78+
"LIFETIME" => token::Lifetime(ast::Ident::with_empty_ctxt(Name(0))),
7979
"CARET" => token::BinOp(token::Caret),
8080
"TILDE" => token::Tilde,
8181
"IDENT" => id(),
@@ -208,9 +208,9 @@ fn parse_antlr_token(s: &str, tokens: &HashMap<String, token::Token>, surrogate_
208208
token::Literal(token::ByteStr(..), n) => token::Literal(token::ByteStr(nm), n),
209209
token::Literal(token::ByteStrRaw(..), n) => token::Literal(token::ByteStrRaw(fix(content),
210210
count(content)), n),
211-
token::Ident(..) => token::Ident(ast::Ident { name: nm, ctxt: 0 },
211+
token::Ident(..) => token::Ident(ast::Ident::with_empty_ctxt(nm)),
212212
token::ModName),
213-
token::Lifetime(..) => token::Lifetime(ast::Ident { name: nm, ctxt: 0 }),
213+
token::Lifetime(..) => token::Lifetime(ast::Ident::with_empty_ctxt(nm)),
214214
ref t => t.clone()
215215
};
216216

src/librustc/metadata/creader.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ impl<'a> CrateReader<'a> {
482482
let span = mk_sp(lo, p.last_span.hi);
483483
p.abort_if_errors();
484484
macros.push(ast::MacroDef {
485-
ident: name.ident(),
485+
ident: ast::Ident::with_empty_ctxt(name),
486486
attrs: attrs,
487487
id: ast::DUMMY_NODE_ID,
488488
span: span,

src/librustc/middle/entry.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn entry_point_type(item: &Item, depth: usize) -> EntryPointType {
8585
EntryPointType::Start
8686
} else if attr::contains_name(&item.attrs, "main") {
8787
EntryPointType::MainAttr
88-
} else if item.name == "main" {
88+
} else if item.name.as_str() == "main" {
8989
if depth == 1 {
9090
// This is a top-level function so can be 'main'
9191
EntryPointType::MainNamed

src/librustc/middle/intrinsicck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl<'a, 'tcx> IntrinsicCheckingVisitor<'a, 'tcx> {
5555
ty::TyBareFn(_, ref bfty) => bfty.abi == RustIntrinsic,
5656
_ => return false
5757
};
58-
intrinsic && self.tcx.item_name(def_id) == "transmute"
58+
intrinsic && self.tcx.item_name(def_id).as_str() == "transmute"
5959
}
6060

6161
fn check_transmute(&self, span: Span, from: Ty<'tcx>, to: Ty<'tcx>, id: ast::NodeId) {

src/librustc/middle/pat_util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ pub fn def_to_path(tcx: &ty::ctxt, id: DefId) -> hir::Path {
211211
tcx.with_path(id, |path| hir::Path {
212212
global: false,
213213
segments: path.last().map(|elem| hir::PathSegment {
214-
identifier: ast::Ident::new(elem.name()),
214+
identifier: ast::Ident::with_empty_ctxt(elem.name()),
215215
parameters: hir::PathParameters::none(),
216216
}).into_iter().collect(),
217217
span: DUMMY_SP,

src/librustc/middle/stability.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ impl<'a, 'v, 'tcx> Visitor<'v> for Checker<'a, 'tcx> {
336336
// When compiling with --test we don't enforce stability on the
337337
// compiler-generated test module, demarcated with `DUMMY_SP` plus the
338338
// name `__test`
339-
if item.span == DUMMY_SP && item.name == "__test" { return }
339+
if item.span == DUMMY_SP && item.name.as_str() == "__test" { return }
340340

341341
check_item(self.tcx, item, true,
342342
&mut |id, sp, stab| self.check(id, sp, stab));

src/librustc_borrowck/borrowck/gather_loans/move_error.rs

-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use rustc::middle::ty;
1515
use std::cell::RefCell;
1616
use syntax::ast;
1717
use syntax::codemap;
18-
use rustc_front::print::pprust;
1918
use rustc_front::hir;
2019

2120
pub struct MoveErrorCollector<'tcx> {
@@ -159,7 +158,6 @@ fn note_move_destination(bccx: &BorrowckCtxt,
159158
move_to_span: codemap::Span,
160159
pat_name: ast::Name,
161160
is_first_note: bool) {
162-
let pat_name = pprust::name_to_string(pat_name);
163161
if is_first_note {
164162
bccx.span_note(
165163
move_to_span,

src/librustc_driver/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ impl<'ast> pprust::PpAnn for HygieneAnnotation<'ast> {
380380
try!(pp::space(&mut s.s));
381381
// FIXME #16420: this doesn't display the connections
382382
// between syntax contexts
383-
s.synth_comment(format!("{}#{}", nm, ctxt))
383+
s.synth_comment(format!("{}#{}", nm, ctxt.0))
384384
}
385385
pprust::NodeName(&ast::Name(nm)) => {
386386
try!(pp::space(&mut s.s));

src/librustc_front/hir.rs

-2
Original file line numberDiff line numberDiff line change
@@ -631,15 +631,13 @@ pub enum Expr_ {
631631
///
632632
/// `if expr { block } else { expr }`
633633
ExprIf(P<Expr>, P<Block>, Option<P<Expr>>),
634-
// FIXME #6993: change to Option<Name> ... or not, if these are hygienic.
635634
/// A while loop, with an optional label
636635
///
637636
/// `'label: while expr { block }`
638637
ExprWhile(P<Expr>, P<Block>, Option<Ident>),
639638
/// Conditionless loop (can be exited with break, continue, or return)
640639
///
641640
/// `'label: loop { block }`
642-
// FIXME #6993: change to Option<Name> ... or not, if these are hygienic.
643641
ExprLoop(P<Block>, Option<Ident>),
644642
/// A `match` block, with a source that indicates whether or not it is
645643
/// the result of a desugaring, and if so, which kind.

src/librustc_front/print/pprust.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2171,7 +2171,6 @@ impl<'a> State<'a> {
21712171
hir::ViewPathSimple(name, ref path) => {
21722172
try!(self.print_path(path, false, 0));
21732173

2174-
// FIXME(#6993) can't compare identifiers directly here
21752174
if path.segments.last().unwrap().identifier.name != name {
21762175
try!(space(&mut self.s));
21772176
try!(self.word_space("as"));

src/librustc_lint/unused.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl UnusedMut {
5050
let name = path1.node;
5151
if let hir::BindByValue(hir::MutMutable) = mode {
5252
if !name.as_str().starts_with("_") {
53-
match mutables.entry(name.usize()) {
53+
match mutables.entry(name.0 as usize) {
5454
Vacant(entry) => { entry.insert(vec![id]); },
5555
Occupied(mut entry) => { entry.get_mut().push(id); },
5656
}

src/librustc_resolve/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3710,7 +3710,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
37103710
false // Stop advancing
37113711
});
37123712

3713-
if method_scope && special_names::self_ == path_name {
3713+
if method_scope && special_names::self_.as_str() == &path_name[..] {
37143714
resolve_error(
37153715
self,
37163716
expr.span,

src/librustc_resolve/resolve_imports.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
537537
fn get_binding(this: &mut Resolver,
538538
import_resolution: &ImportResolution,
539539
namespace: Namespace,
540-
source: &Name)
540+
source: Name)
541541
-> NamespaceResult {
542542

543543
// Import resolutions must be declared with "pub"
@@ -560,7 +560,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
560560
let id = import_resolution.id(namespace);
561561
// track used imports and extern crates as well
562562
this.used_imports.insert((id, namespace));
563-
this.record_import_use(id, *source);
563+
this.record_import_use(id, source);
564564
match target_module.def_id.get() {
565565
Some(DefId{krate: kid, ..}) => {
566566
this.used_crates.insert(kid);
@@ -578,14 +578,14 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
578578
value_result = get_binding(self.resolver,
579579
import_resolution,
580580
ValueNS,
581-
&source);
581+
source);
582582
value_used_reexport = import_resolution.is_public;
583583
}
584584
if type_result.is_unknown() {
585585
type_result = get_binding(self.resolver,
586586
import_resolution,
587587
TypeNS,
588-
&source);
588+
source);
589589
type_used_reexport = import_resolution.is_public;
590590
}
591591

src/librustc_trans/save/dump_csv.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
444444

445445
fn process_const(&mut self,
446446
id: ast::NodeId,
447-
name: &ast::Name,
447+
name: ast::Name,
448448
span: Span,
449449
typ: &ast::Ty,
450450
expr: &ast::Expr) {
@@ -988,7 +988,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
988988
fn visit_trait_item(&mut self, trait_item: &ast::TraitItem) {
989989
match trait_item.node {
990990
ast::ConstTraitItem(ref ty, Some(ref expr)) => {
991-
self.process_const(trait_item.id, &trait_item.ident.name,
991+
self.process_const(trait_item.id, trait_item.ident.name,
992992
trait_item.span, &*ty, &*expr);
993993
}
994994
ast::MethodTraitItem(ref sig, ref body) => {
@@ -1006,7 +1006,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
10061006
fn visit_impl_item(&mut self, impl_item: &ast::ImplItem) {
10071007
match impl_item.node {
10081008
ast::ConstImplItem(ref ty, ref expr) => {
1009-
self.process_const(impl_item.id, &impl_item.ident.name,
1009+
self.process_const(impl_item.id, impl_item.ident.name,
10101010
impl_item.span, &ty, &expr);
10111011
}
10121012
ast::MethodImplItem(ref sig, ref body) => {

src/librustc_trans/trans/common.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ pub fn return_type_is_void(ccx: &CrateContext, ty: Ty) -> bool {
168168
/// Generates a unique symbol based off the name given. This is used to create
169169
/// unique symbols for things like closures.
170170
pub fn gensym_name(name: &str) -> PathElem {
171-
let num = token::gensym(name).usize();
171+
let num = token::gensym(name).0;
172172
// use one colon which will get translated to a period by the mangler, and
173173
// we're guaranteed that `num` is globally unique for this crate.
174174
PathName(token::gensym(&format!("{}:{}", name, num)))
@@ -829,7 +829,7 @@ pub fn C_cstr(cx: &CrateContext, s: InternedString, null_terminated: bool) -> Va
829829
!null_terminated as Bool);
830830

831831
let gsym = token::gensym("str");
832-
let sym = format!("str{}", gsym.usize());
832+
let sym = format!("str{}", gsym.0);
833833
let g = declare::define_global(cx, &sym[..], val_ty(sc)).unwrap_or_else(||{
834834
cx.sess().bug(&format!("symbol `{}` is already defined", sym));
835835
});

src/librustc_trans/trans/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ fn addr_of_mut(ccx: &CrateContext,
116116
// FIXME: this totally needs a better name generation scheme, perhaps a simple global
117117
// counter? Also most other uses of gensym in trans.
118118
let gsym = token::gensym("_");
119-
let name = format!("{}{}", kind, gsym.usize());
119+
let name = format!("{}{}", kind, gsym.0);
120120
let gv = declare::define_global(ccx, &name[..], val_ty(cv)).unwrap_or_else(||{
121121
ccx.sess().bug(&format!("symbol `{}` is already defined", name));
122122
});

src/librustc_typeck/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ fn check_trait_on_unimplemented<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
838838
Position::ArgumentNamed(s) if s == "Self" => (),
839839
// So is `{A}` if A is a type parameter
840840
Position::ArgumentNamed(s) => match types.iter().find(|t| {
841-
t.name == s
841+
t.name.as_str() == s
842842
}) {
843843
Some(_) => (),
844844
None => {

0 commit comments

Comments
 (0)