Skip to content

Commit 7f8f3dc

Browse files
committed
libsyntax: Remove uses of ~str from libsyntax, and fix fallout
1 parent e454851 commit 7f8f3dc

Some content is hidden

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

50 files changed

+773
-629
lines changed

src/librustc/back/link.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ pub fn crate_id_hash(crate_id: &CrateId) -> ~str {
536536
// the crate id in the hash because lookups are only done by (name/vers),
537537
// not by path.
538538
let mut s = Sha256::new();
539-
s.input_str(crate_id.short_name_with_version());
539+
s.input_str(crate_id.short_name_with_version().as_slice());
540540
truncated_hash_result(&mut s).slice_to(8).to_owned()
541541
}
542542

@@ -566,7 +566,7 @@ fn symbol_hash(tcx: &ty::ctxt,
566566
// to be independent of one another in the crate.
567567

568568
symbol_hasher.reset();
569-
symbol_hasher.input_str(link_meta.crateid.name);
569+
symbol_hasher.input_str(link_meta.crateid.name.as_slice());
570570
symbol_hasher.input_str("-");
571571
symbol_hasher.input_str(link_meta.crate_hash.as_str());
572572
symbol_hasher.input_str("-");

src/librustc/driver/driver.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ pub fn build_configuration(sess: &Session) -> ast::CrateConfig {
143143
fn parse_cfgspecs(cfgspecs: Vec<~str> )
144144
-> ast::CrateConfig {
145145
cfgspecs.move_iter().map(|s| {
146-
parse::parse_meta_from_source_str("cfgspec".to_str(),
147-
s,
146+
parse::parse_meta_from_source_str("cfgspec".to_strbuf(),
147+
s.to_strbuf(),
148148
Vec::new(),
149149
&parse::new_parse_sess())
150150
}).collect::<ast::CrateConfig>()
@@ -175,8 +175,8 @@ pub fn phase_1_parse_input(sess: &Session, cfg: ast::CrateConfig, input: &Input)
175175
parse::parse_crate_from_file(&(*file), cfg.clone(), &sess.parse_sess)
176176
}
177177
StrInput(ref src) => {
178-
parse::parse_crate_from_source_str(anon_src(),
179-
(*src).clone(),
178+
parse::parse_crate_from_source_str(anon_src().to_strbuf(),
179+
src.to_strbuf(),
180180
cfg.clone(),
181181
&sess.parse_sess)
182182
}
@@ -528,7 +528,7 @@ fn write_out_deps(sess: &Session,
528528
// write Makefile-compatible dependency rules
529529
let files: Vec<~str> = sess.codemap().files.borrow()
530530
.iter().filter(|fmap| fmap.is_real_file())
531-
.map(|fmap| fmap.name.clone())
531+
.map(|fmap| fmap.name.to_owned())
532532
.collect();
533533
let mut file = try!(io::File::create(&deps_filename));
534534
for path in out_filenames.iter() {
@@ -604,20 +604,20 @@ impl pprust::PpAnn for IdentifiedAnnotation {
604604
match node {
605605
pprust::NodeItem(item) => {
606606
try!(pp::space(&mut s.s));
607-
s.synth_comment(item.id.to_str())
607+
s.synth_comment(item.id.to_str().to_strbuf())
608608
}
609609
pprust::NodeBlock(blk) => {
610610
try!(pp::space(&mut s.s));
611-
s.synth_comment("block ".to_owned() + blk.id.to_str())
611+
s.synth_comment((format!("block {}", blk.id)).to_strbuf())
612612
}
613613
pprust::NodeExpr(expr) => {
614614
try!(pp::space(&mut s.s));
615-
try!(s.synth_comment(expr.id.to_str()));
615+
try!(s.synth_comment(expr.id.to_str().to_strbuf()));
616616
s.pclose()
617617
}
618618
pprust::NodePat(pat) => {
619619
try!(pp::space(&mut s.s));
620-
s.synth_comment("pat ".to_owned() + pat.id.to_str())
620+
s.synth_comment((format!("pat {}", pat.id)).to_strbuf())
621621
}
622622
}
623623
}
@@ -692,7 +692,7 @@ pub fn pretty_print_input(sess: Session,
692692
pprust::print_crate(sess.codemap(),
693693
sess.diagnostic(),
694694
&krate,
695-
src_name,
695+
src_name.to_strbuf(),
696696
&mut rdr,
697697
out,
698698
&IdentifiedAnnotation,
@@ -707,7 +707,7 @@ pub fn pretty_print_input(sess: Session,
707707
pprust::print_crate(annotation.analysis.ty_cx.sess.codemap(),
708708
annotation.analysis.ty_cx.sess.diagnostic(),
709709
&krate,
710-
src_name,
710+
src_name.to_strbuf(),
711711
&mut rdr,
712712
out,
713713
&annotation,
@@ -717,7 +717,7 @@ pub fn pretty_print_input(sess: Session,
717717
pprust::print_crate(sess.codemap(),
718718
sess.diagnostic(),
719719
&krate,
720-
src_name,
720+
src_name.to_strbuf(),
721721
&mut rdr,
722722
out,
723723
&pprust::NoAnn,

src/librustc/driver/session.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,8 @@ cgoptions!(
471471
)
472472

473473
// Seems out of place, but it uses session, so I'm putting it here
474-
pub fn expect<T:Clone>(sess: &Session, opt: Option<T>, msg: || -> ~str) -> T {
474+
pub fn expect<T:Clone>(sess: &Session, opt: Option<T>, msg: || -> StrBuf)
475+
-> T {
475476
diagnostic::expect(sess.diagnostic(), opt, msg)
476477
}
477478

src/librustc/front/test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ fn generate_test_harness(sess: &Session, krate: ast::Crate)
168168
cx.ext_cx.bt_push(ExpnInfo {
169169
call_site: DUMMY_SP,
170170
callee: NameAndSpan {
171-
name: "test".to_owned(),
171+
name: "test".to_strbuf(),
172172
format: MacroAttribute,
173173
span: None
174174
}
@@ -398,7 +398,7 @@ fn mk_tests(cx: &TestCtxt) -> @ast::Item {
398398

399399
fn is_test_crate(krate: &ast::Crate) -> bool {
400400
match attr::find_crateid(krate.attrs.as_slice()) {
401-
Some(ref s) if "test" == s.name => true,
401+
Some(ref s) if "test" == s.name.as_slice() => true,
402402
_ => false
403403
}
404404
}
@@ -427,7 +427,7 @@ fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> @ast::Expr {
427427

428428
let name_lit: ast::Lit =
429429
nospan(ast::LitStr(token::intern_and_get_ident(
430-
ast_util::path_name_i(path.as_slice())),
430+
ast_util::path_name_i(path.as_slice()).as_slice()),
431431
ast::CookedStr));
432432

433433
let name_expr = @ast::Expr {

src/librustc/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,10 +352,11 @@ fn parse_crate_attrs(sess: &session::Session, input: &d::Input) ->
352352
&sess.parse_sess)
353353
}
354354
d::StrInput(ref src) => {
355-
parse::parse_crate_attrs_from_source_str(d::anon_src(),
356-
(*src).clone(),
357-
Vec::new(),
358-
&sess.parse_sess)
355+
parse::parse_crate_attrs_from_source_str(
356+
d::anon_src().to_strbuf(),
357+
src.to_strbuf(),
358+
Vec::new(),
359+
&sess.parse_sess)
359360
}
360361
};
361362
result.move_iter().collect()

src/librustc/metadata/creader.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,11 +428,11 @@ impl<'a> CrateLoader for Loader<'a> {
428428
};
429429
let macros = decoder::get_exported_macros(library.metadata.as_slice());
430430
let registrar = decoder::get_macro_registrar_fn(library.metadata.as_slice()).map(|id| {
431-
decoder::get_symbol(library.metadata.as_slice(), id)
431+
decoder::get_symbol(library.metadata.as_slice(), id).to_strbuf()
432432
});
433433
let mc = MacroCrate {
434434
lib: library.dylib.clone(),
435-
macros: macros.move_iter().collect(),
435+
macros: macros.move_iter().map(|x| x.to_strbuf()).collect(),
436436
registrar_symbol: registrar,
437437
};
438438
if should_link {

src/librustc/metadata/csearch.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,17 @@ pub fn get_field_type(tcx: &ty::ctxt, class_id: ast::DefId,
207207
let all_items = reader::get_doc(reader::Doc(cdata.data()), tag_items);
208208
let class_doc = expect(tcx.sess.diagnostic(),
209209
decoder::maybe_find_item(class_id.node, all_items),
210-
|| format!("get_field_type: class ID {:?} not found",
211-
class_id) );
210+
|| {
211+
(format!("get_field_type: class ID {:?} not found",
212+
class_id)).to_strbuf()
213+
});
212214
let the_field = expect(tcx.sess.diagnostic(),
213215
decoder::maybe_find_item(def.node, class_doc),
214-
|| format!("get_field_type: in class {:?}, field ID {:?} not found",
215-
class_id, def) );
216+
|| {
217+
(format!("get_field_type: in class {:?}, field ID {:?} not found",
218+
class_id,
219+
def)).to_strbuf()
220+
});
216221
let ty = decoder::item_type(def, the_field, tcx, &*cdata);
217222
ty::ty_param_bounds_and_ty {
218223
generics: ty::Generics {type_param_defs: Rc::new(Vec::new()),

src/librustc/metadata/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1563,7 +1563,7 @@ impl<'a, 'b, 'c> Visitor<()> for MacroDefVisitor<'a, 'b, 'c> {
15631563
let def = self.ecx.tcx.sess.codemap().span_to_snippet(item.span)
15641564
.expect("Unable to find source for macro");
15651565
self.ebml_w.start_tag(tag_macro_def);
1566-
self.ebml_w.wr_str(def);
1566+
self.ebml_w.wr_str(def.as_slice());
15671567
self.ebml_w.end_tag();
15681568
}
15691569
_ => {}

src/librustc/middle/dataflow.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ impl<'a, O:DataFlowOperator> pprust::PpAnn for DataFlowContext<'a, O> {
112112
"".to_owned()
113113
};
114114

115-
try!(ps.synth_comment(format!("id {}: {}{}{}", id, entry_str,
116-
gens_str, kills_str)));
115+
try!(ps.synth_comment((format!("id {}: {}{}{}", id, entry_str,
116+
gens_str, kills_str)).to_strbuf()));
117117
try!(pp::space(&mut ps.s));
118118
}
119119
Ok(())

src/librustc/middle/kind.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ fn check_sized(tcx: &ty::ctxt, ty: ty::t, name: ~str, sp: Span) {
569569
fn check_pat(cx: &mut Context, pat: &Pat) {
570570
let var_name = match pat.node {
571571
PatWild => Some("_".to_owned()),
572-
PatIdent(_, ref path, _) => Some(path_to_str(path)),
572+
PatIdent(_, ref path, _) => Some(path_to_str(path).to_owned()),
573573
_ => None
574574
};
575575

src/librustc/middle/privacy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ enum FieldName {
357357
impl<'a> PrivacyVisitor<'a> {
358358
// used when debugging
359359
fn nodestr(&self, id: ast::NodeId) -> ~str {
360-
self.tcx.map.node_to_str(id)
360+
self.tcx.map.node_to_str(id).to_owned()
361361
}
362362

363363
// Determines whether the given definition is public from the point of view

src/librustc/middle/resolve.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3167,12 +3167,12 @@ impl<'a> Resolver<'a> {
31673167
.codemap()
31683168
.span_to_snippet(imports.get(index).span)
31693169
.unwrap();
3170-
if sn.contains("::") {
3170+
if sn.as_slice().contains("::") {
31713171
self.resolve_error(imports.get(index).span,
31723172
"unresolved import");
31733173
} else {
31743174
let err = format!("unresolved import (maybe you meant `{}::*`?)",
3175-
sn.slice(0, sn.len()));
3175+
sn.as_slice().slice(0, sn.len()));
31763176
self.resolve_error(imports.get(index).span, err);
31773177
}
31783178
}

src/librustc/middle/trans/base.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,11 @@ pub fn new_fn_ctxt<'a>(ccx: &'a CrateContext,
11451145
for p in param_substs.iter() { p.validate(); }
11461146

11471147
debug!("new_fn_ctxt(path={}, id={}, param_substs={})",
1148-
if id == -1 { "".to_owned() } else { ccx.tcx.map.path_to_str(id) },
1148+
if id == -1 {
1149+
"".to_owned()
1150+
} else {
1151+
ccx.tcx.map.path_to_str(id).to_owned()
1152+
},
11491153
id, param_substs.map(|s| s.repr(ccx.tcx())));
11501154

11511155
let substd_output_type = match param_substs {
@@ -1458,7 +1462,7 @@ pub fn trans_fn(ccx: &CrateContext,
14581462
param_substs: Option<&param_substs>,
14591463
id: ast::NodeId,
14601464
attrs: &[ast::Attribute]) {
1461-
let _s = StatRecorder::new(ccx, ccx.tcx.map.path_to_str(id));
1465+
let _s = StatRecorder::new(ccx, ccx.tcx.map.path_to_str(id).to_owned());
14621466
debug!("trans_fn(param_substs={})", param_substs.map(|s| s.repr(ccx.tcx())));
14631467
let _icx = push_ctxt("trans_fn");
14641468
let output_type = ty::ty_fn_ret(ty::node_id_to_type(ccx.tcx(), id));
@@ -2161,9 +2165,10 @@ pub fn trans_crate(krate: ast::Crate,
21612165
// crashes if the module identifer is same as other symbols
21622166
// such as a function name in the module.
21632167
// 1. http://llvm.org/bugs/show_bug.cgi?id=11479
2164-
let llmod_id = link_meta.crateid.name + ".rs";
2168+
let mut llmod_id = link_meta.crateid.name.clone();
2169+
llmod_id.push_str(".rs");
21652170

2166-
let ccx = CrateContext::new(llmod_id, tcx, exp_map2,
2171+
let ccx = CrateContext::new(llmod_id.as_slice(), tcx, exp_map2,
21672172
Sha256::new(), link_meta, reachable);
21682173
{
21692174
let _icx = push_ctxt("text");

src/librustc/middle/trans/callee.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ pub fn trans_fn_ref_with_vtables(
364364
let map_node = session::expect(
365365
ccx.sess(),
366366
tcx.map.find(def_id.node),
367-
|| format!("local item should be in ast map"));
367+
|| "local item should be in ast map".to_strbuf());
368368

369369
match map_node {
370370
ast_map::NodeForeignItem(_) => {

src/librustc/middle/trans/common.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ impl<'a> Block<'a> {
426426
}
427427

428428
pub fn node_id_to_str(&self, id: ast::NodeId) -> ~str {
429-
self.tcx().map.node_to_str(id)
429+
self.tcx().map.node_to_str(id).to_owned()
430430
}
431431

432432
pub fn expr_to_str(&self, e: &ast::Expr) -> ~str {
@@ -839,7 +839,10 @@ pub fn filename_and_line_num_from_span(bcx: &Block, span: Span)
839839
-> (ValueRef, ValueRef) {
840840
let loc = bcx.sess().codemap().lookup_char_pos(span.lo);
841841
let filename_cstr = C_cstr(bcx.ccx(),
842-
token::intern_and_get_ident(loc.file.name), true);
842+
token::intern_and_get_ident(loc.file
843+
.name
844+
.as_slice()),
845+
true);
843846
let filename = build::PointerCast(bcx, filename_cstr, Type::i8p(bcx.ccx()));
844847
let line = C_int(bcx.ccx(), loc.line as int);
845848
(filename, line)

src/librustc/middle/trans/controlflow.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,11 @@ pub fn trans_fail<'a>(
345345
let v_fail_str = C_cstr(ccx, fail_str, true);
346346
let _icx = push_ctxt("trans_fail_value");
347347
let loc = bcx.sess().codemap().lookup_char_pos(sp.lo);
348-
let v_filename = C_cstr(ccx, token::intern_and_get_ident(loc.file.name), true);
348+
let v_filename = C_cstr(ccx,
349+
token::intern_and_get_ident(loc.file
350+
.name
351+
.as_slice()),
352+
true);
349353
let v_line = loc.line as int;
350354
let v_str = PointerCast(bcx, v_fail_str, Type::i8p(ccx));
351355
let v_filename = PointerCast(bcx, v_filename, Type::i8p(ccx));

0 commit comments

Comments
 (0)