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

File tree

42 files changed

+195
-254
lines changed

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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 1 deletion
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"));

0 commit comments

Comments
 (0)