Skip to content

libsyntax: Remove uses of ~str from libsyntax, and fix fallout #14032

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ pub fn crate_id_hash(crate_id: &CrateId) -> ~str {
// the crate id in the hash because lookups are only done by (name/vers),
// not by path.
let mut s = Sha256::new();
s.input_str(crate_id.short_name_with_version());
s.input_str(crate_id.short_name_with_version().as_slice());
truncated_hash_result(&mut s).slice_to(8).to_owned()
}

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

symbol_hasher.reset();
symbol_hasher.input_str(link_meta.crateid.name);
symbol_hasher.input_str(link_meta.crateid.name.as_slice());
symbol_hasher.input_str("-");
symbol_hasher.input_str(link_meta.crate_hash.as_str());
symbol_hasher.input_str("-");
Expand Down
24 changes: 12 additions & 12 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ pub fn build_configuration(sess: &Session) -> ast::CrateConfig {
fn parse_cfgspecs(cfgspecs: Vec<~str> )
-> ast::CrateConfig {
cfgspecs.move_iter().map(|s| {
parse::parse_meta_from_source_str("cfgspec".to_str(),
s,
parse::parse_meta_from_source_str("cfgspec".to_strbuf(),
s.to_strbuf(),
Vec::new(),
&parse::new_parse_sess())
}).collect::<ast::CrateConfig>()
Expand Down Expand Up @@ -175,8 +175,8 @@ pub fn phase_1_parse_input(sess: &Session, cfg: ast::CrateConfig, input: &Input)
parse::parse_crate_from_file(&(*file), cfg.clone(), &sess.parse_sess)
}
StrInput(ref src) => {
parse::parse_crate_from_source_str(anon_src(),
(*src).clone(),
parse::parse_crate_from_source_str(anon_src().to_strbuf(),
src.to_strbuf(),
cfg.clone(),
&sess.parse_sess)
}
Expand Down Expand Up @@ -528,7 +528,7 @@ fn write_out_deps(sess: &Session,
// write Makefile-compatible dependency rules
let files: Vec<~str> = sess.codemap().files.borrow()
.iter().filter(|fmap| fmap.is_real_file())
.map(|fmap| fmap.name.clone())
.map(|fmap| fmap.name.to_owned())
.collect();
let mut file = try!(io::File::create(&deps_filename));
for path in out_filenames.iter() {
Expand Down Expand Up @@ -604,20 +604,20 @@ impl pprust::PpAnn for IdentifiedAnnotation {
match node {
pprust::NodeItem(item) => {
try!(pp::space(&mut s.s));
s.synth_comment(item.id.to_str())
s.synth_comment(item.id.to_str().to_strbuf())
}
pprust::NodeBlock(blk) => {
try!(pp::space(&mut s.s));
s.synth_comment("block ".to_owned() + blk.id.to_str())
s.synth_comment((format!("block {}", blk.id)).to_strbuf())
}
pprust::NodeExpr(expr) => {
try!(pp::space(&mut s.s));
try!(s.synth_comment(expr.id.to_str()));
try!(s.synth_comment(expr.id.to_str().to_strbuf()));
s.pclose()
}
pprust::NodePat(pat) => {
try!(pp::space(&mut s.s));
s.synth_comment("pat ".to_owned() + pat.id.to_str())
s.synth_comment((format!("pat {}", pat.id)).to_strbuf())
}
}
}
Expand Down Expand Up @@ -692,7 +692,7 @@ pub fn pretty_print_input(sess: Session,
pprust::print_crate(sess.codemap(),
sess.diagnostic(),
&krate,
src_name,
src_name.to_strbuf(),
&mut rdr,
out,
&IdentifiedAnnotation,
Expand All @@ -707,7 +707,7 @@ pub fn pretty_print_input(sess: Session,
pprust::print_crate(annotation.analysis.ty_cx.sess.codemap(),
annotation.analysis.ty_cx.sess.diagnostic(),
&krate,
src_name,
src_name.to_strbuf(),
&mut rdr,
out,
&annotation,
Expand All @@ -717,7 +717,7 @@ pub fn pretty_print_input(sess: Session,
pprust::print_crate(sess.codemap(),
sess.diagnostic(),
&krate,
src_name,
src_name.to_strbuf(),
&mut rdr,
out,
&pprust::NoAnn,
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/driver/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,8 @@ cgoptions!(
)

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

Expand Down
6 changes: 3 additions & 3 deletions src/librustc/front/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ fn generate_test_harness(sess: &Session, krate: ast::Crate)
cx.ext_cx.bt_push(ExpnInfo {
call_site: DUMMY_SP,
callee: NameAndSpan {
name: "test".to_owned(),
name: "test".to_strbuf(),
format: MacroAttribute,
span: None
}
Expand Down Expand Up @@ -398,7 +398,7 @@ fn mk_tests(cx: &TestCtxt) -> @ast::Item {

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

let name_lit: ast::Lit =
nospan(ast::LitStr(token::intern_and_get_ident(
ast_util::path_name_i(path.as_slice())),
ast_util::path_name_i(path.as_slice()).as_slice()),
ast::CookedStr));

let name_expr = @ast::Expr {
Expand Down
9 changes: 5 additions & 4 deletions src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,11 @@ fn parse_crate_attrs(sess: &session::Session, input: &d::Input) ->
&sess.parse_sess)
}
d::StrInput(ref src) => {
parse::parse_crate_attrs_from_source_str(d::anon_src(),
(*src).clone(),
Vec::new(),
&sess.parse_sess)
parse::parse_crate_attrs_from_source_str(
d::anon_src().to_strbuf(),
src.to_strbuf(),
Vec::new(),
&sess.parse_sess)
}
};
result.move_iter().collect()
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,11 +428,11 @@ impl<'a> CrateLoader for Loader<'a> {
};
let macros = decoder::get_exported_macros(library.metadata.as_slice());
let registrar = decoder::get_macro_registrar_fn(library.metadata.as_slice()).map(|id| {
decoder::get_symbol(library.metadata.as_slice(), id)
decoder::get_symbol(library.metadata.as_slice(), id).to_strbuf()
});
let mc = MacroCrate {
lib: library.dylib.clone(),
macros: macros.move_iter().collect(),
macros: macros.move_iter().map(|x| x.to_strbuf()).collect(),
registrar_symbol: registrar,
};
if should_link {
Expand Down
13 changes: 9 additions & 4 deletions src/librustc/metadata/csearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,17 @@ pub fn get_field_type(tcx: &ty::ctxt, class_id: ast::DefId,
let all_items = reader::get_doc(reader::Doc(cdata.data()), tag_items);
let class_doc = expect(tcx.sess.diagnostic(),
decoder::maybe_find_item(class_id.node, all_items),
|| format!("get_field_type: class ID {:?} not found",
class_id) );
|| {
(format!("get_field_type: class ID {:?} not found",
class_id)).to_strbuf()
});
let the_field = expect(tcx.sess.diagnostic(),
decoder::maybe_find_item(def.node, class_doc),
|| format!("get_field_type: in class {:?}, field ID {:?} not found",
class_id, def) );
|| {
(format!("get_field_type: in class {:?}, field ID {:?} not found",
class_id,
def)).to_strbuf()
});
let ty = decoder::item_type(def, the_field, tcx, &*cdata);
ty::ty_param_bounds_and_ty {
generics: ty::Generics {type_param_defs: Rc::new(Vec::new()),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1563,7 +1563,7 @@ impl<'a, 'b, 'c> Visitor<()> for MacroDefVisitor<'a, 'b, 'c> {
let def = self.ecx.tcx.sess.codemap().span_to_snippet(item.span)
.expect("Unable to find source for macro");
self.ebml_w.start_tag(tag_macro_def);
self.ebml_w.wr_str(def);
self.ebml_w.wr_str(def.as_slice());
self.ebml_w.end_tag();
}
_ => {}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ impl<'a, O:DataFlowOperator> pprust::PpAnn for DataFlowContext<'a, O> {
"".to_owned()
};

try!(ps.synth_comment(format!("id {}: {}{}{}", id, entry_str,
gens_str, kills_str)));
try!(ps.synth_comment((format!("id {}: {}{}{}", id, entry_str,
gens_str, kills_str)).to_strbuf()));
try!(pp::space(&mut ps.s));
}
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ fn check_sized(tcx: &ty::ctxt, ty: ty::t, name: ~str, sp: Span) {
fn check_pat(cx: &mut Context, pat: &Pat) {
let var_name = match pat.node {
PatWild => Some("_".to_owned()),
PatIdent(_, ref path, _) => Some(path_to_str(path)),
PatIdent(_, ref path, _) => Some(path_to_str(path).to_owned()),
_ => None
};

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/privacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ enum FieldName {
impl<'a> PrivacyVisitor<'a> {
// used when debugging
fn nodestr(&self, id: ast::NodeId) -> ~str {
self.tcx.map.node_to_str(id)
self.tcx.map.node_to_str(id).to_owned()
}

// Determines whether the given definition is public from the point of view
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3167,12 +3167,12 @@ impl<'a> Resolver<'a> {
.codemap()
.span_to_snippet(imports.get(index).span)
.unwrap();
if sn.contains("::") {
if sn.as_slice().contains("::") {
self.resolve_error(imports.get(index).span,
"unresolved import");
} else {
let err = format!("unresolved import (maybe you meant `{}::*`?)",
sn.slice(0, sn.len()));
sn.as_slice().slice(0, sn.len()));
self.resolve_error(imports.get(index).span, err);
}
}
Expand Down
13 changes: 9 additions & 4 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,11 @@ pub fn new_fn_ctxt<'a>(ccx: &'a CrateContext,
for p in param_substs.iter() { p.validate(); }

debug!("new_fn_ctxt(path={}, id={}, param_substs={})",
if id == -1 { "".to_owned() } else { ccx.tcx.map.path_to_str(id) },
if id == -1 {
"".to_owned()
} else {
ccx.tcx.map.path_to_str(id).to_owned()
},
id, param_substs.map(|s| s.repr(ccx.tcx())));

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

let ccx = CrateContext::new(llmod_id, tcx, exp_map2,
let ccx = CrateContext::new(llmod_id.as_slice(), tcx, exp_map2,
Sha256::new(), link_meta, reachable);
{
let _icx = push_ctxt("text");
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ pub fn trans_fn_ref_with_vtables(
let map_node = session::expect(
ccx.sess(),
tcx.map.find(def_id.node),
|| format!("local item should be in ast map"));
|| "local item should be in ast map".to_strbuf());

match map_node {
ast_map::NodeForeignItem(_) => {
Expand Down
7 changes: 5 additions & 2 deletions src/librustc/middle/trans/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ impl<'a> Block<'a> {
}

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

pub fn expr_to_str(&self, e: &ast::Expr) -> ~str {
Expand Down Expand Up @@ -839,7 +839,10 @@ pub fn filename_and_line_num_from_span(bcx: &Block, span: Span)
-> (ValueRef, ValueRef) {
let loc = bcx.sess().codemap().lookup_char_pos(span.lo);
let filename_cstr = C_cstr(bcx.ccx(),
token::intern_and_get_ident(loc.file.name), true);
token::intern_and_get_ident(loc.file
.name
.as_slice()),
true);
let filename = build::PointerCast(bcx, filename_cstr, Type::i8p(bcx.ccx()));
let line = C_int(bcx.ccx(), loc.line as int);
(filename, line)
Expand Down
6 changes: 5 additions & 1 deletion src/librustc/middle/trans/controlflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,11 @@ pub fn trans_fail<'a>(
let v_fail_str = C_cstr(ccx, fail_str, true);
let _icx = push_ctxt("trans_fail_value");
let loc = bcx.sess().codemap().lookup_char_pos(sp.lo);
let v_filename = C_cstr(ccx, token::intern_and_get_ident(loc.file.name), true);
let v_filename = C_cstr(ccx,
token::intern_and_get_ident(loc.file
.name
.as_slice()),
true);
let v_line = loc.line as int;
let v_str = PointerCast(bcx, v_fail_str, Type::i8p(ccx));
let v_filename = PointerCast(bcx, v_filename, Type::i8p(ccx));
Expand Down
Loading