Skip to content

Commit

Permalink
Fix build on 0.11pre: Change ~"foo" to "foo".to_owned()
Browse files Browse the repository at this point in the history
[~"string" and &"string" literals are gone](rust-lang/rust#13877), and were
replaced by "string".to_owned() and just "string", respectively. This commit was made by a simple
`sed` to convert the existing instances of ~"string" on the codebase.

For reference, the command used was this:

    sed -e 's/~\("[^"]*"\)/\1.to_owned()/g' -i *.rs

That wouldn't work if for strings that contain the `\"` escape in them, but this codebase had none.

Similar work is likely to be necessary after [~T is substituted by
Box<T>](rust-lang/rust#13885).
  • Loading branch information
renato-zannon committed May 2, 2014
1 parent 02cc483 commit 6b4a11c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 38 deletions.
50 changes: 25 additions & 25 deletions gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn empty_generics() -> ast::Generics {
fn rust_id(ctx: &mut GenCtx, name: ~str) -> (~str, bool) {
let token = parse::token::IDENT(ctx.ext_cx.ident_of(name), false);
if parse::token::is_any_keyword(&token) || "bool" == name {
(~"_" + name, true)
("_".to_owned() + name, true)
} else {
(name, false)
}
Expand All @@ -77,7 +77,7 @@ fn rust_type_id(ctx: &mut GenCtx, name: ~str) -> ~str {
"i64" == name ||
"Self" == name ||
"str" == name {
~"_" + name
"_".to_owned() + name
} else {
let (n, _) = rust_id(ctx, name);
n
Expand Down Expand Up @@ -134,7 +134,7 @@ pub fn gen_rs(out: ~io::Writer, abi: ~str, link: &Option<~str>, globs: Vec<Globa
};
ctx.ext_cx.bt_push(ExpnInfo {
call_site: DUMMY_SP,
callee: NameAndSpan { name: ~"", format: MacroBang, span: None }
callee: NameAndSpan { name: "".to_owned(), format: MacroBang, span: None }
});
let uniq_globs = tag_dup_decl(globs);

Expand Down Expand Up @@ -214,7 +214,7 @@ pub fn gen_rs(out: ~io::Writer, abi: ~str, link: &Option<~str>, globs: Vec<Globa
let v = vi.borrow();
cvar_to_rs(&mut ctx, v.name.clone(), &v.ty, v.is_const)
},
_ => { fail!(~"generate global variables") }
_ => { fail!("generate global variables".to_owned()) }
}
}).collect();

Expand All @@ -225,14 +225,14 @@ pub fn gen_rs(out: ~io::Writer, abi: ~str, link: &Option<~str>, globs: Vec<Globa
match v.ty {
TFunc(ref rty, ref aty, var) => cfunc_to_rs(&mut ctx, v.name.clone(),
*rty, *aty, var),
_ => { fail!(~"generate functions") }
_ => { fail!("generate functions".to_owned()) }
}
},
_ => { fail!(~"generate functions") }
_ => { fail!("generate functions".to_owned()) }
}
}).collect();

let views = Vec::from_elem(1, mk_import(&mut ctx, &[~"libc"]));
let views = Vec::from_elem(1, mk_import(&mut ctx, &["libc".to_owned()]));
defs.push(mk_extern(&mut ctx, link, vars, funcs));

let crate_ = ast::Crate {
Expand Down Expand Up @@ -292,7 +292,7 @@ fn mk_extern(ctx: &mut GenCtx, link: &Option<~str>,
None => attrs = Vec::new(),
Some(ref l) => {
let link_name = @dummy_spanned(ast::MetaNameValue(
to_intern_str(ctx, ~"name"),
to_intern_str(ctx, "name".to_owned()),
dummy_spanned(ast::LitStr(
to_intern_str(ctx, l.to_owned()),
ast::CookedStr
Expand All @@ -301,7 +301,7 @@ fn mk_extern(ctx: &mut GenCtx, link: &Option<~str>,
let link_args = dummy_spanned(ast::Attribute_ {
style: ast::AttrOuter,
value: @dummy_spanned(ast::MetaList(
to_intern_str(ctx, ~"link"),
to_intern_str(ctx, "link".to_owned()),
Vec::from_elem(1, link_name))
),
is_sugared_doc: false
Expand Down Expand Up @@ -623,7 +623,7 @@ fn cunion_to_rs(ctx: &mut GenCtx, name: ~str, layout: Layout, fields: Vec<FieldI

return vec!(
union_def,
mk_item(ctx, ~"", methods, ast::Inherited)
mk_item(ctx, "".to_owned(), methods, ast::Inherited)
);
}

Expand Down Expand Up @@ -663,7 +663,7 @@ fn mk_link_name_attr(ctx: &mut GenCtx, name: ~str) -> ast::Attribute {
ast::CookedStr
));
let attr_val = @dummy_spanned(ast::MetaNameValue(
to_intern_str(ctx, ~"link_name"), lit
to_intern_str(ctx, "link_name".to_owned()), lit
));
let attr = ast::Attribute_ {
style: ast::AttrOuter,
Expand Down Expand Up @@ -782,23 +782,23 @@ fn cfunc_to_rs(ctx: &mut GenCtx, name: ~str, rty: &Type,

fn cty_to_rs(ctx: &mut GenCtx, ty: &Type) -> ast::Ty {
return match *ty {
TVoid => mk_ty(ctx, ~"c_void"),
TVoid => mk_ty(ctx, "c_void".to_owned()),
TInt(i, _) => match i {
IBool => mk_ty(ctx, ~"c_int"),
ISChar => mk_ty(ctx, ~"c_char"),
IUChar => mk_ty(ctx, ~"c_uchar"),
IInt => mk_ty(ctx, ~"c_int"),
IUInt => mk_ty(ctx, ~"c_uint"),
IShort => mk_ty(ctx, ~"c_short"),
IUShort => mk_ty(ctx, ~"c_ushort"),
ILong => mk_ty(ctx, ~"c_long"),
IULong => mk_ty(ctx, ~"c_ulong"),
ILongLong => mk_ty(ctx, ~"c_longlong"),
IULongLong => mk_ty(ctx, ~"c_ulonglong")
IBool => mk_ty(ctx, "c_int".to_owned()),
ISChar => mk_ty(ctx, "c_char".to_owned()),
IUChar => mk_ty(ctx, "c_uchar".to_owned()),
IInt => mk_ty(ctx, "c_int".to_owned()),
IUInt => mk_ty(ctx, "c_uint".to_owned()),
IShort => mk_ty(ctx, "c_short".to_owned()),
IUShort => mk_ty(ctx, "c_ushort".to_owned()),
ILong => mk_ty(ctx, "c_long".to_owned()),
IULong => mk_ty(ctx, "c_ulong".to_owned()),
ILongLong => mk_ty(ctx, "c_longlong".to_owned()),
IULongLong => mk_ty(ctx, "c_ulonglong".to_owned())
},
TFloat(f, _) => match f {
FFloat => mk_ty(ctx, ~"c_float"),
FDouble => mk_ty(ctx, ~"c_double")
FFloat => mk_ty(ctx, "c_float".to_owned()),
FDouble => mk_ty(ctx, "c_double".to_owned())
},
TPtr(ref t, is_const, _) => {
let id = cty_to_rs(ctx, *t);
Expand Down
18 changes: 9 additions & 9 deletions main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn parse_args(args: &[~str]) -> ParseResult {
let mut out = ~io::BufferedWriter::new(io::stdout()) as ~io::Writer;
let mut pat = vec!();
let mut link = None;
let mut abi = ~"C";
let mut abi = "C".to_owned();
let mut builtins = false;
let mut emit_ast = false;
let mut fail_on_bitfield = true;
Expand All @@ -61,7 +61,7 @@ fn parse_args(args: &[~str]) -> ParseResult {
}
"-o" => {
if ix + 1u >= args_len {
return ParseErr(~"Missing output filename");
return ParseErr("Missing output filename".to_owned());
}
let path = path::Path::new(args[ix + 1].clone());
match fs::File::create(&path) {
Expand All @@ -72,14 +72,14 @@ fn parse_args(args: &[~str]) -> ParseResult {
}
"-l" => {
if ix + 1u >= args_len {
return ParseErr(~"Missing link name");
return ParseErr("Missing link name".to_owned());
}
link = Some(args[ix + 1u].clone());
ix += 2u;
}
"-match" => {
if ix + 1u >= args_len {
return ParseErr(~"Missing match pattern");
return ParseErr("Missing match pattern".to_owned());
}
pat.push(args[ix + 1u].clone());
ix += 2u;
Expand Down Expand Up @@ -122,8 +122,8 @@ fn parse_args(args: &[~str]) -> ParseResult {
fn builtin_names() -> HashSet<~str> {
let mut names = HashSet::new();
let keys = ~[
~"__va_list_tag",
~"__va_list",
"__va_list_tag".to_owned(),
"__va_list".to_owned(),
];

keys.move_iter().advance(|s| {
Expand Down Expand Up @@ -269,7 +269,7 @@ fn conv_ptr_ty(ctx: &mut BindGenCtx, ty: &cx::Type, cursor: &Cursor, layout: Lay
let decl = ty.declaration();
return if ret_ty.kind() != CXType_Invalid {
let args_lst = ty.arg_types().iter().map(|arg| {
(~"", conv_ty(ctx, arg, cursor))
("".to_owned(), conv_ty(ctx, arg, cursor))
}).collect();
let ret_ty = ~conv_ty(ctx, &ret_ty, cursor);

Expand Down Expand Up @@ -535,12 +535,12 @@ fn main() {
ParseOk(clang_args, mut ctx, out) => {
let ix = cx::Index::create(false, true);
if ix.is_null() {
fail!(~"clang failed to create index");
fail!("clang failed to create index".to_owned());
}

let unit = TranslationUnit::parse(&ix, "", clang_args, [], 0);
if unit.is_null() {
fail!(~"No input files given");
fail!("No input files given".to_owned());
}

let mut c_err = false;
Expand Down
8 changes: 4 additions & 4 deletions types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,30 @@ impl Global {
match *self {
GComp(i) => return i,
GCompDecl(i) => return i,
_ => fail!(~"global_compinfo")
_ => fail!("global_compinfo".to_owned())
}
}

pub fn enuminfo(&self) -> @RefCell<EnumInfo> {
match *self {
GEnum(i) => return i,
GEnumDecl(i) => return i,
_ => fail!(~"global_enuminfo")
_ => fail!("global_enuminfo".to_owned())
}
}

pub fn typeinfo(&self) -> @RefCell<TypeInfo> {
match *self {
GType(i) => return i,
_ => fail!(~"global_typeinfo")
_ => fail!("global_typeinfo".to_owned())
}
}

pub fn varinfo(&self) -> @RefCell<VarInfo> {
match *self {
GVar(i) => i,
GFunc(i) => i,
_ => fail!(~"global_varinfo")
_ => fail!("global_varinfo".to_owned())
}
}
}
Expand Down

0 comments on commit 6b4a11c

Please sign in to comment.