From dfe1f6260e7e076114b95b42053cf6dc4cbaca68 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 3 Aug 2012 11:22:35 -0700 Subject: [PATCH] rustc: Remove all fixed-length strings from our codebase --- src/libstd/bitv.rs | 2 +- src/libstd/map.rs | 10 +++++----- src/libsyntax/ext/pipes/pipec.rs | 10 +++++----- src/libsyntax/parse/parser.rs | 2 +- src/libsyntax/parse/token.rs | 4 ++-- src/libsyntax/print/pprust.rs | 4 ++-- src/rustc/middle/trans/base.rs | 2 +- src/rustc/middle/typeck/check.rs | 5 ++++- src/rustdoc/markdown_pass.rs | 2 +- 9 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/libstd/bitv.rs b/src/libstd/bitv.rs index edc35ff7a87f..94a4f1ba9779 100644 --- a/src/libstd/bitv.rs +++ b/src/libstd/bitv.rs @@ -402,7 +402,7 @@ class bitv { */ fn to_str() -> ~str { let mut rs = ~""; - for self.each() |i| { if i { rs += "1"; } else { rs += "0"; } }; + for self.each() |i| { if i { rs += ~"1"; } else { rs += ~"0"; } }; rs } diff --git a/src/libstd/map.rs b/src/libstd/map.rs index dd99c9945e12..e4d1471017fe 100644 --- a/src/libstd/map.rs +++ b/src/libstd/map.rs @@ -331,22 +331,22 @@ mod chained { impl hashmap of to_str for t { fn to_writer(wr: io::writer) { if self.count == 0u { - wr.write_str("{}"); + wr.write_str(~"{}"); return; } - wr.write_str("{ "); + wr.write_str(~"{ "); let mut first = true; for self.each_entry |entry| { if !first { - wr.write_str(", "); + wr.write_str(~", "); } first = false; wr.write_str(entry.key.to_str()); - wr.write_str(": "); + wr.write_str(~": "); wr.write_str((copy entry.value).to_str()); }; - wr.write_str(" }"); + wr.write_str(~" }"); } fn to_str() -> ~str { diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index 00fd5d41f936..81c8ba9da502 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -71,13 +71,13 @@ impl compile of gen_send for message { if this.proto.is_bounded() { let (sp, rp) = alt (this.dir, next.dir) { - (send, send) { ("c", "s") } - (send, recv) { ("s", "c") } - (recv, send) { ("s", "c") } - (recv, recv) { ("c", "s") } + (send, send) { (~"c", ~"s") } + (send, recv) { (~"s", ~"c") } + (recv, send) { (~"s", ~"c") } + (recv, recv) { (~"c", ~"s") } }; - body += "let b = pipe.reuse_buffer();\n"; + body += ~"let b = pipe.reuse_buffer();\n"; body += fmt!{"let %s = pipes::send_packet_buffered(\ ptr::addr_of(b.buffer.data.%s));\n", sp, *next.name}; diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index f697685796f3..026466144353 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2164,7 +2164,7 @@ class parser { } _ => { self.fatal(~"expected `,` or `)`, found `" + - token_to_str(self.reader, self.token) + "`"); + token_to_str(self.reader, self.token) + ~"`"); } } } else { diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 9d3bbef2cd41..3dbcef66732a 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -167,8 +167,8 @@ fn to_str(in: interner<@~str>, t: token) -> ~str { } LIT_FLOAT(s, t) { let mut body = *in.get(s); - if body.ends_with(".") { - body = body + "0"; // `10.f` is not a float literal + if body.ends_with(~".") { + body = body + ~"0"; // `10.f` is not a float literal } body + ast_util::float_ty_to_str(t) } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 800800504fdc..feea800b44cf 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -600,7 +600,7 @@ fn print_item(s: ps, &&item: @ast::item) { bclose(s, item.span); } ast::item_mac({node: ast::mac_invoc_tt(pth, tts), _}) { - head(s, path_to_str(pth) + "! " + *item.ident); + head(s, path_to_str(pth) + ~"! " + *item.ident); bopen(s); for tts.each |tt| { print_tt(s, tt); } bclose(s, item.span); @@ -873,7 +873,7 @@ fn print_mac(s: ps, m: ast::mac) { // FIXME: extension 'body' (#2339) } ast::mac_invoc_tt(pth, tts) { - head(s, path_to_str(pth) + "!"); + head(s, path_to_str(pth) + ~"!"); bopen(s); for tts.each() |tt| { print_tt(s, tt); } bclose(s, m.span); diff --git a/src/rustc/middle/trans/base.rs b/src/rustc/middle/trans/base.rs index 629f85c1a3c9..d8518303804d 100644 --- a/src/rustc/middle/trans/base.rs +++ b/src/rustc/middle/trans/base.rs @@ -5292,7 +5292,7 @@ fn gather_external_rtcalls(ccx: @crate_ctxt) { // like gather_local_rtcalls, but we'll need to // export attributes in metadata/encoder before we can do // that. - let sentinel = "rt::rt_"; + let sentinel = ~"rt::rt_"; let slen = str::len(sentinel); if str::starts_with(pathname, sentinel) { let name = str::substr(pathname, diff --git a/src/rustc/middle/typeck/check.rs b/src/rustc/middle/typeck/check.rs index cf25eaf06075..05f53018f41c 100644 --- a/src/rustc/middle/typeck/check.rs +++ b/src/rustc/middle/typeck/check.rs @@ -701,7 +701,10 @@ fn check_lit(fcx: @fn_ctxt, lit: @ast::lit) -> ty::t { let tcx = fcx.ccx.tcx; alt lit.node { - ast::lit_str(s) { ty::mk_estr(tcx, ty::vstore_fixed(s.len())) } + ast::lit_str(s) { + tcx.sess.span_warn(lit.span, ~"fixed length string"); + ty::mk_estr(tcx, ty::vstore_fixed(s.len())) + } ast::lit_int(_, t) { ty::mk_mach_int(tcx, t) } ast::lit_uint(_, t) { ty::mk_mach_uint(tcx, t) } ast::lit_int_unsuffixed(_) { diff --git a/src/rustdoc/markdown_pass.rs b/src/rustdoc/markdown_pass.rs index ada77af3cc20..c8f767bf7164 100644 --- a/src/rustdoc/markdown_pass.rs +++ b/src/rustdoc/markdown_pass.rs @@ -229,7 +229,7 @@ fn header_name(doc: doc::itemtag) -> ~str { if i == 0 { trait_part += ~" of "; } else { - trait_part += ", "; + trait_part += ~", "; } trait_part += trait_type; }