From 04a691a511d0203b1f521960f845e623cc45d261 Mon Sep 17 00:00:00 2001 From: John Clements Date: Mon, 3 Jun 2013 23:00:49 -0700 Subject: [PATCH] token_to_ident takes argument by reference --- src/librustc/driver/session.rs | 2 +- src/librustc/metadata/creader.rs | 8 ++++---- src/librustc/metadata/decoder.rs | 2 +- src/librustc/metadata/encoder.rs | 2 +- src/librustc/metadata/loader.rs | 2 +- src/librustc/middle/borrowck/mod.rs | 4 ++-- src/librustc/middle/privacy.rs | 14 +++++++------- src/librustc/middle/resolve.rs | 6 +++--- src/librustc/middle/trans/base.rs | 2 +- src/librustc/middle/trans/foreign.rs | 2 +- src/librustc/util/ppaux.rs | 2 +- src/librustdoc/extract.rs | 4 +++- src/libsyntax/ext/base.rs | 2 +- src/libsyntax/ext/expand.rs | 8 ++++---- src/libsyntax/ext/quote.rs | 2 +- src/libsyntax/ext/tt/macro_parser.rs | 8 ++++---- src/libsyntax/ext/tt/macro_rules.rs | 2 +- src/libsyntax/ext/tt/transcribe.rs | 6 +++--- src/libsyntax/parse/parser.rs | 4 ++-- src/libsyntax/parse/token.rs | 10 +++++----- src/libsyntax/print/pprust.rs | 2 +- 21 files changed, 48 insertions(+), 46 deletions(-) diff --git a/src/librustc/driver/session.rs b/src/librustc/driver/session.rs index 749c065de32f..211665942a88 100644 --- a/src/librustc/driver/session.rs +++ b/src/librustc/driver/session.rs @@ -296,7 +296,7 @@ impl Session_ { // pointless function, now... pub fn str_of(@self, id: ast::ident) -> @~str { - token::ident_to_str(id) + token::ident_to_str(&id) } // pointless function, now... diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs index 642df89da6ea..546c516c287c 100644 --- a/src/librustc/metadata/creader.rs +++ b/src/librustc/metadata/creader.rs @@ -177,7 +177,7 @@ fn visit_item(e: @mut Env, i: @ast::item) { } nn } - None => token::ident_to_str(i.ident) + None => token::ident_to_str(&i.ident) }; if attr::find_attrs_by_name(i.attrs, "nolink").is_empty() { already_added = @@ -236,7 +236,7 @@ fn resolve_crate(e: @mut Env, hash: @~str, span: span) -> ast::crate_num { - let metas = metas_with_ident(token::ident_to_str(ident), metas); + let metas = metas_with_ident(token::ident_to_str(&ident), metas); match existing_match(e, metas, hash) { None => { @@ -277,7 +277,7 @@ fn resolve_crate(e: @mut Env, match attr::last_meta_item_value_str_by_name(load_ctxt.metas, "name") { Some(v) => v, - None => token::ident_to_str(ident), + None => token::ident_to_str(&ident), }; let cmeta = @cstore::crate_metadata { name: cname, @@ -306,7 +306,7 @@ fn resolve_crate_deps(e: @mut Env, cdata: @~[u8]) -> cstore::cnum_map { for decoder::get_crate_deps(e.intr, cdata).each |dep| { let extrn_cnum = dep.cnum; let cname = dep.name; - let cname_str = token::ident_to_str(dep.name); + let cname_str = token::ident_to_str(&dep.name); let cmetas = metas_with(dep.vers, @~"vers", ~[]); debug!("resolving dep crate %s ver: %s hash: %s", *cname_str, *dep.vers, *dep.hash); diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index 93136aca18a2..baf93416379a 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -1110,7 +1110,7 @@ fn list_crate_deps(intr: @ident_interner, data: @~[u8], out: @io::Writer) { for get_crate_deps(intr, data).each |dep| { out.write_str( fmt!("%d %s-%s-%s\n", - dep.cnum, *token::ident_to_str(dep.name), *dep.hash, *dep.vers)); + dep.cnum, *token::ident_to_str(&dep.name), *dep.hash, *dep.vers)); } out.write_str("\n"); diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index 427ec80740d8..a703f20e05c3 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -1055,7 +1055,7 @@ fn encode_info_for_item(ecx: @EncodeContext, tcx.sess.span_unimpl( item.span, fmt!("Method %s is both provided and static", - *token::ident_to_str(method_ty.ident))); + *token::ident_to_str(&method_ty.ident))); } encode_type_param_bounds(ebml_w, ecx, &m.generics.ty_params); diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs index 08155d675fef..1ebf8f2e9f47 100644 --- a/src/librustc/metadata/loader.rs +++ b/src/librustc/metadata/loader.rs @@ -60,7 +60,7 @@ pub fn load_library_crate(cx: &Context) -> (~str, @~[u8]) { None => { cx.diag.span_fatal( cx.span, fmt!("can't find crate for `%s`", - *token::ident_to_str(cx.ident))); + *token::ident_to_str(&cx.ident))); } } } diff --git a/src/librustc/middle/borrowck/mod.rs b/src/librustc/middle/borrowck/mod.rs index e3fc0bde72a3..fa3bae3f5ac9 100644 --- a/src/librustc/middle/borrowck/mod.rs +++ b/src/librustc/middle/borrowck/mod.rs @@ -711,7 +711,7 @@ impl BorrowckCtxt { match *loan_path { LpVar(id) => { match self.tcx.items.find(&id) { - Some(&ast_map::node_local(ident)) => { + Some(&ast_map::node_local(ref ident)) => { str::push_str(out, *token::ident_to_str(ident)); } r => { @@ -725,7 +725,7 @@ impl BorrowckCtxt { LpExtend(lp_base, _, LpInterior(mc::InteriorField(fname))) => { self.append_loan_path_to_str_from_interior(lp_base, out); match fname { - mc::NamedField(fname) => { + mc::NamedField(ref fname) => { str::push_char(out, '.'); str::push_str(out, *token::ident_to_str(fname)); } diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index d2f3f8752751..fe30b9c4fd72 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -235,7 +235,7 @@ pub fn check_crate(tcx: ty::ctxt, if field.ident != ident { loop; } if field.vis == private { tcx.sess.span_err(span, fmt!("field `%s` is private", - *token::ident_to_str(ident))); + *token::ident_to_str(&ident))); } break; } @@ -244,7 +244,7 @@ pub fn check_crate(tcx: ty::ctxt, // Given the ID of a method, checks to ensure it's in scope. let check_method_common: @fn(span: span, method_id: def_id, - name: ident) = + name: &ident) = |span, method_id, name| { if method_id.crate == local_crate { let is_private = method_is_private(span, method_id.node); @@ -275,7 +275,7 @@ pub fn check_crate(tcx: ty::ctxt, match def { def_static_method(method_id, _, _) => { debug!("found static method def, checking it"); - check_method_common(span, method_id, *path.idents.last()) + check_method_common(span, method_id, path.idents.last()) } def_fn(def_id, _) => { if def_id.crate == local_crate { @@ -283,13 +283,13 @@ pub fn check_crate(tcx: ty::ctxt, !privileged_items.contains(&def_id.node) { tcx.sess.span_err(span, fmt!("function `%s` is private", - *token::ident_to_str(*path.idents.last()))); + *token::ident_to_str(path.idents.last()))); } } else if csearch::get_item_visibility(tcx.sess.cstore, def_id) != public { tcx.sess.span_err(span, fmt!("function `%s` is private", - *token::ident_to_str(*path.idents.last()))); + *token::ident_to_str(path.idents.last()))); } } _ => {} @@ -303,7 +303,7 @@ pub fn check_crate(tcx: ty::ctxt, |span, origin, ident| { match *origin { method_static(method_id) => { - check_method_common(span, method_id, ident) + check_method_common(span, method_id, &ident) } method_param(method_param { trait_id: trait_id, @@ -328,7 +328,7 @@ pub fn check_crate(tcx: ty::ctxt, .contains(&(trait_id.node)) => { tcx.sess.span_err(span, fmt!("method `%s` is private", - *token::ident_to_str(method + *token::ident_to_str(&method .ident))); } provided(_) | required(_) => { diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 6b3061864442..c23932b14b51 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -2948,11 +2948,11 @@ impl Resolver { // top of the crate otherwise. let mut containing_module; let mut i; - if *token::ident_to_str(module_path[0]) == ~"self" { + if *token::ident_to_str(&module_path[0]) == ~"self" { containing_module = self.get_nearest_normal_module_parent_or_self(module_); i = 1; - } else if *token::ident_to_str(module_path[0]) == ~"super" { + } else if *token::ident_to_str(&module_path[0]) == ~"super" { containing_module = self.get_nearest_normal_module_parent_or_self(module_); i = 0; // We'll handle `super` below. @@ -2962,7 +2962,7 @@ impl Resolver { // Now loop through all the `super`s we find. while i < module_path.len() && - *token::ident_to_str(module_path[i]) == ~"super" { + *token::ident_to_str(&module_path[i]) == ~"super" { debug!("(resolving module prefix) resolving `super` at %s", self.module_to_str(containing_module)); match self.get_nearest_normal_module_parent(containing_module) { diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 846d3cd26108..ba88fe09e70a 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -2505,7 +2505,7 @@ pub fn get_item_val(ccx: @CrateContext, id: ast::node_id) -> ValueRef { } ast::foreign_item_const(*) => { let typ = ty::node_id_to_type(tcx, ni.id); - let ident = token::ident_to_str(ni.ident); + let ident = token::ident_to_str(&ni.ident); let g = do str::as_c_str(*ident) |buf| { unsafe { llvm::LLVMAddGlobal(ccx.llmod, diff --git a/src/librustc/middle/trans/foreign.rs b/src/librustc/middle/trans/foreign.rs index e494d5f0db9e..dfcf364233be 100644 --- a/src/librustc/middle/trans/foreign.rs +++ b/src/librustc/middle/trans/foreign.rs @@ -344,7 +344,7 @@ pub fn trans_foreign_mod(ccx: @CrateContext, } } ast::foreign_item_const(*) => { - let ident = token::ident_to_str(foreign_item.ident); + let ident = token::ident_to_str(&foreign_item.ident); ccx.item_symbols.insert(foreign_item.id, copy *ident); } } diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 1764db8ba6d7..2ec4cc65528f 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -655,7 +655,7 @@ impl Repr for ty::Method { impl Repr for ast::ident { fn repr(&self, tcx: ctxt) -> ~str { - copy *token::ident_to_str(*self) + copy *token::ident_to_str(self) } } diff --git a/src/librustdoc/extract.rs b/src/librustdoc/extract.rs index 54722fae2d76..bf0d5032b1f6 100644 --- a/src/librustdoc/extract.rs +++ b/src/librustdoc/extract.rs @@ -24,10 +24,12 @@ use syntax::parse::token; // Hack; rather than thread an interner through everywhere, rely on // thread-local data +// Hack-Becomes-Feature: using thread-local-state everywhere... pub fn to_str(id: ast::ident) -> ~str { - return copy *ident_to_str(id); + return copy *ident_to_str(&id); } +// get rid of this pointless function: pub fn interner() -> @ident_interner { return token::get_ident_interner(); } diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 97df2c6554e2..6906a64da116 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -310,7 +310,7 @@ impl ExtCtxt { *self.trace_mac = x } pub fn str_of(&self, id: ast::ident) -> ~str { - copy *ident_to_str(id) + copy *ident_to_str(&id) } pub fn ident_of(&self, st: &str) -> ast::ident { str_to_ident(st) diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 1e95f62e3e83..8090bc613d64 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -49,7 +49,7 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv, fmt!("expected macro name without module \ separators")); } - let extname = pth.idents[0]; + let extname = &pth.idents[0]; let extnamestr = ident_to_str(extname); // leaving explicit deref here to highlight unbox op: match (*extsbox).find(&extname.name) { @@ -216,7 +216,7 @@ pub fn expand_item_mac(extsbox: @mut SyntaxEnv, _ => cx.span_bug(it.span, "invalid item macro invocation") }; - let extname = pth.idents[0]; + let extname = &pth.idents[0]; let interner = get_ident_interner(); let extnamestr = ident_to_str(extname); let expanded = match (*extsbox).find(&extname.name) { @@ -228,7 +228,7 @@ pub fn expand_item_mac(extsbox: @mut SyntaxEnv, cx.span_fatal(pth.span, fmt!("macro %s! expects no ident argument, \ given '%s'", *extnamestr, - *ident_to_str(it.ident))); + *ident_to_str(&it.ident))); } cx.bt_push(ExpandedFrom(CallInfo { call_site: it.span, @@ -315,7 +315,7 @@ pub fn expand_stmt(extsbox: @mut SyntaxEnv, fmt!("expected macro name without module \ separators")); } - let extname = pth.idents[0]; + let extname = &pth.idents[0]; let extnamestr = ident_to_str(extname); let (fully_expanded, sp) = match (*extsbox).find(&extname.name) { None => diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index f8835b51aa50..04309ea21dc6 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -80,7 +80,7 @@ pub mod rt { impl ToSource for ast::ident { fn to_source(&self, cx: @ExtCtxt) -> ~str { - copy *interner_get(self.name) + copy *ident_to_str(self) } } diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index 86077a5c0b30..9fb9def84e9c 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -205,7 +205,7 @@ pub fn nameize(p_s: @mut ParseSess, ms: &[matcher], res: &[@named_match]) } => { if ret_val.contains_key(bind_name) { p_s.span_diagnostic.span_fatal(sp, ~"Duplicated bind name: "+ - *ident_to_str(*bind_name)) + *ident_to_str(bind_name)) } ret_val.insert(*bind_name, res[idx]); } @@ -373,8 +373,8 @@ pub fn parse( let nts = str::connect(vec::map(bb_eis, |ei| { match ei.elts[ei.idx].node { match_nonterminal(ref bind,ref name,_) => { - fmt!("%s ('%s')", *ident_to_str(*name), - *ident_to_str(*bind)) + fmt!("%s ('%s')", *ident_to_str(name), + *ident_to_str(bind)) } _ => fail!() } }), " or "); @@ -398,7 +398,7 @@ pub fn parse( match ei.elts[ei.idx].node { match_nonterminal(_, ref name, idx) => { ei.matches[idx].push(@matched_nonterminal( - parse_nt(&rust_parser, *ident_to_str(*name)))); + parse_nt(&rust_parser, *ident_to_str(name)))); ei.idx += 1u; } _ => fail!() diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index be2c50d223d9..140c89807f4e 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -151,7 +151,7 @@ pub fn add_new_extension(cx: @ExtCtxt, |cx, sp, arg| generic_extension(cx, sp, name, arg, *lhses, *rhses); return MRDef(MacroDef{ - name: copy *ident_to_str(name), + name: copy *ident_to_str(&name), ext: NormalTT(base::SyntaxExpanderTT{expander: exp, span: Some(sp)}) }); } diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index 8ff66dc62e3f..fcd440420a18 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -145,8 +145,8 @@ fn lockstep_iter_size(t: &token_tree, r: &mut TtReader) -> lis { lis_contradiction(_) => copy rhs, lis_constraint(r_len, _) if l_len == r_len => copy lhs, lis_constraint(r_len, ref r_id) => { - let l_n = copy *ident_to_str(*l_id); - let r_n = copy *ident_to_str(*r_id); + let l_n = copy *ident_to_str(l_id); + let r_n = copy *ident_to_str(r_id); lis_contradiction(fmt!("Inconsistent lockstep iteration: \ '%s' has %u items, but '%s' has %u", l_n, l_len, r_n, r_len)) @@ -296,7 +296,7 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan { r.sp_diag.span_fatal( copy r.cur_span, /* blame the macro writer */ fmt!("variable '%s' is still repeating at this depth", - *ident_to_str(ident))); + *ident_to_str(&ident))); } } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 54845849ebbb..2fd0a7e33fff 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3980,7 +3980,7 @@ impl Parser { match *self.token { token::LIT_STR(s) => { self.bump(); - let the_string = ident_to_str(s); + let the_string = ident_to_str(&s); let mut words = ~[]; for str::each_word(*the_string) |s| { words.push(s) } let mut abis = AbiSet::empty(); @@ -4542,7 +4542,7 @@ impl Parser { match *self.token { token::LIT_STR(s) => { self.bump(); - ident_to_str(s) + ident_to_str(&s) } _ => self.fatal("expected string literal") } diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 400d52d5a524..ef889d5e4bcb 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -178,20 +178,20 @@ pub fn to_str(in: @ident_interner, t: &Token) -> ~str { } LIT_INT_UNSUFFIXED(i) => { i.to_str() } LIT_FLOAT(ref s, t) => { - let mut body = copy *ident_to_str(*s); + let mut body = copy *ident_to_str(s); if body.ends_with(".") { body += "0"; // `10.f` is not a float literal } body + ast_util::float_ty_to_str(t) } LIT_FLOAT_UNSUFFIXED(ref s) => { - let mut body = copy *ident_to_str(*s); + let mut body = copy *ident_to_str(s); if body.ends_with(".") { body += "0"; // `10.f` is not a float literal } body } - LIT_STR(ref s) => { ~"\"" + str::escape_default(*ident_to_str(*s)) + "\"" } + LIT_STR(ref s) => { ~"\"" + str::escape_default(*ident_to_str(s)) + "\"" } /* Name components */ IDENT(s, _) => copy *in.get(s.name), @@ -199,7 +199,7 @@ pub fn to_str(in: @ident_interner, t: &Token) -> ~str { UNDERSCORE => ~"_", /* Other */ - DOC_COMMENT(ref s) => copy *ident_to_str(*s), + DOC_COMMENT(ref s) => copy *ident_to_str(s), EOF => ~"", INTERPOLATED(ref nt) => { match nt { @@ -545,7 +545,7 @@ pub fn interner_get(name : Name) -> @~str { } // maps an identifier to the string that it corresponds to -pub fn ident_to_str(id : ast::ident) -> @~str { +pub fn ident_to_str(id : &ast::ident) -> @~str { interner_get(id.name) } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 0e8612cbffbe..58ab227a4cee 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1475,7 +1475,7 @@ pub fn print_decl(s: @ps, decl: @ast::decl) { } pub fn print_ident(s: @ps, ident: ast::ident) { - word(s.s, *ident_to_str(ident)); + word(s.s, *ident_to_str(&ident)); } pub fn print_for_decl(s: @ps, loc: @ast::local, coll: @ast::expr) {