Skip to content

Commit

Permalink
Replace several common macros of the form #m[...] with m!(...)
Browse files Browse the repository at this point in the history
This commit replaces nearly all remaining uses of #fmt, #debug, #error,
and #info, and fixes some error messages...
  • Loading branch information
killerswan committed Oct 12, 2012
1 parent 45d1cd8 commit 1bede1f
Show file tree
Hide file tree
Showing 40 changed files with 85 additions and 86 deletions.
16 changes: 8 additions & 8 deletions src/libstd/net_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ fn encode_inner(s: &str, full_url: bool) -> ~str {
str::push_char(&mut out, ch);
}

_ => out += #fmt("%%%X", ch as uint)
_ => out += fmt!("%%%X", ch as uint)
}
} else {
out += #fmt("%%%X", ch as uint);
out += fmt!("%%%X", ch as uint);
}
}
}
Expand Down Expand Up @@ -164,7 +164,7 @@ fn encode_plus(s: &str) -> ~str {
str::push_char(&mut out, ch);
}
' ' => str::push_char(&mut out, '+'),
_ => out += #fmt("%%%X", ch as uint)
_ => out += fmt!("%%%X", ch as uint)
}
}

Expand All @@ -190,7 +190,7 @@ pub fn encode_form_urlencoded(m: HashMap<~str, @DVec<@~str>>) -> ~str {
first = false;
}

out += #fmt("%s=%s", key, encode_plus(**value));
out += fmt!("%s=%s", key, encode_plus(**value));
}
}

Expand Down Expand Up @@ -332,7 +332,7 @@ pub pure fn query_to_str(query: Query) -> ~str {
let (k, v) = copy *kv;
// This is really safe...
unsafe {
strvec += ~[#fmt("%s=%s",
strvec += ~[fmt!("%s=%s",
encode_component(k), encode_component(v))];
}
};
Expand Down Expand Up @@ -850,7 +850,7 @@ mod tests {
fn test_url_parse_host_slash() {
let urlstr = ~"http://0.42.42.42/";
let url = from_str(urlstr).get();
#debug("url: %?", url);
debug!("url: %?", url);
assert url.host == ~"0.42.42.42";
assert url.path == ~"/";
}
Expand All @@ -859,15 +859,15 @@ mod tests {
fn test_url_with_underscores() {
let urlstr = ~"http://dotcom.com/file_name.html";
let url = from_str(urlstr).get();
#debug("url: %?", url);
debug!("url: %?", url);
assert url.path == ~"/file_name.html";
}

#[test]
fn test_url_with_dashes() {
let urlstr = ~"http://dotcom.com/file-name.html";
let url = from_str(urlstr).get();
#debug("url: %?", url);
debug!("url: %?", url);
assert url.path == ~"/file-name.html";
}

Expand Down
2 changes: 1 addition & 1 deletion src/libstd/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ pub impl<T: Deserializable> Option<T>: Deserializable {
match i {
0 => None,
1 => Some(d.read_enum_variant_arg(0u, || deserialize(d))),
_ => fail(#fmt("Bad variant for option: %u", i))
_ => fail(fmt!("Bad variant for option: %u", i))
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/libstd/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,7 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, ~str> {
fn strftime(format: &str, tm: Tm) -> ~str {
fn parse_type(ch: char, tm: &Tm) -> ~str {
//FIXME (#2350): Implement missing types.
let die = || #fmt("strftime: can't understand this format %c ",
ch);
let die = || fmt!("strftime: can't understand this format %c ", ch);
match ch {
'A' => match tm.tm_wday as int {
0 => ~"Sunday",
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ fn print_macro_backtrace(cm: codemap::codemap, sp: span) {
let ss = option::map_default(&ei.callie.span, @~"",
|span| @codemap::span_to_str(*span, cm));
print_diagnostic(*ss, note,
fmt!("in expansion of #%s", ei.callie.name));
fmt!("in expansion of %s!", ei.callie.name));
let ss = codemap::span_to_str(ei.call_site, cm);
print_diagnostic(ss, note, ~"expansion site");
print_macro_backtrace(cm, ei.call_site);
Expand Down
8 changes: 4 additions & 4 deletions src/libsyntax/ext/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,21 +269,21 @@ fn get_mac_args(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
match max {
Some(max) if ! (min <= elts_len && elts_len <= max) => {
cx.span_fatal(sp,
fmt!("#%s takes between %u and %u arguments.",
fmt!("%s! takes between %u and %u arguments.",
name, min, max));
}
None if ! (min <= elts_len) => {
cx.span_fatal(sp, fmt!("#%s needs at least %u arguments.",
cx.span_fatal(sp, fmt!("%s! needs at least %u arguments.",
name, min));
}
_ => return elts /* we are good */
}
}
_ => {
cx.span_fatal(sp, fmt!("#%s: malformed invocation", name))
cx.span_fatal(sp, fmt!("%s!: malformed invocation", name))
}
},
None => cx.span_fatal(sp, fmt!("#%s: missing arguments", name))
None => cx.span_fatal(sp, fmt!("%s!: missing arguments", name))
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ext/env.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

/*
* The compiler code necessary to support the #env extension. Eventually this
* The compiler code necessary to support the env! extension. Eventually this
* should all get sucked into either the compiler syntax extension plugin
* interface.
*/
Expand All @@ -15,7 +15,7 @@ fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
// FIXME (#2248): if this was more thorough it would manufacture an
// Option<str> rather than just an maybe-empty string.

let var = expr_to_str(cx, args[0], ~"#env requires a string");
let var = expr_to_str(cx, args[0], ~"env! requires a string");
match os::getenv(var) {
option::None => return mk_uniq_str(cx, sp, ~""),
option::Some(s) => return mk_uniq_str(cx, sp, s)
Expand Down
16 changes: 8 additions & 8 deletions src/libsyntax/ext/fmt.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


/*
* The compiler code necessary to support the #fmt extension. Eventually this
* The compiler code necessary to support the fmt! extension. Eventually this
* should all get sucked into either the standard library extfmt module or the
* compiler syntax extension plugin interface.
*/
Expand All @@ -16,7 +16,7 @@ fn expand_syntax_ext(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
let args = get_mac_args_no_max(cx, sp, arg, 1u, ~"fmt");
let fmt =
expr_to_str(cx, args[0],
~"first argument to #fmt must be a string literal.");
~"first argument to fmt! must be a string literal.");
let fmtspan = args[0].span;
debug!("Format string:");
log(debug, fmt);
Expand Down Expand Up @@ -76,7 +76,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
let count_is_args = ~[count_lit];
return mk_call(cx, sp, count_is_path, count_is_args);
}
_ => cx.span_unimpl(sp, ~"unimplemented #fmt conversion")
_ => cx.span_unimpl(sp, ~"unimplemented fmt! conversion")
}
}
fn make_ty(cx: ext_ctxt, sp: span, t: Ty) -> @ast::expr {
Expand Down Expand Up @@ -133,7 +133,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
_ => return false
}
}
let unsupported = ~"conversion not supported in #fmt string";
let unsupported = ~"conversion not supported in fmt! string";
match cnv.param {
option::None => (),
_ => cx.span_unimpl(sp, unsupported)
Expand All @@ -145,14 +145,14 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
if !is_signed_type(cnv) {
cx.span_fatal(sp,
~"+ flag only valid in " +
~"signed #fmt conversion");
~"signed fmt! conversion");
}
}
FlagSpaceForSign => {
if !is_signed_type(cnv) {
cx.span_fatal(sp,
~"space flag only valid in " +
~"signed #fmt conversions");
~"signed fmt! conversions");
}
}
FlagLeftZeroPad => (),
Expand Down Expand Up @@ -252,7 +252,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
n += 1u;
if n >= nargs {
cx.span_fatal(sp,
~"not enough arguments to #fmt " +
~"not enough arguments to fmt! " +
~"for the given format string");
}
debug!("Building conversion:");
Expand All @@ -267,7 +267,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,

if expected_nargs < nargs {
cx.span_fatal
(sp, fmt!("too many arguments to #fmt. found %u, expected %u",
(sp, fmt!("too many arguments to fmt!. found %u, expected %u",
nargs, expected_nargs));
}

Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2414,7 +2414,7 @@ impl parser {

fn expect_self_ident() {
if !self.is_self_ident() {
self.fatal(#fmt("expected `self` but found `%s`",
self.fatal(fmt!("expected `self` but found `%s`",
token_to_str(self.reader, self.token)));
}
self.bump();
Expand Down Expand Up @@ -2696,7 +2696,7 @@ impl parser {
ctor_decl(a_fn_decl, attrs, blk, s) => {
match the_ctor {
Some((_, _, _, s_first)) => {
self.span_note(s, #fmt("Duplicate constructor \
self.span_note(s, fmt!("Duplicate constructor \
declaration for class %s",
*self.interner.get(class_name)));
self.span_fatal(copy s_first, ~"First constructor \
Expand All @@ -2710,7 +2710,7 @@ impl parser {
dtor_decl(blk, attrs, s) => {
match the_dtor {
Some((_, _, s_first)) => {
self.span_note(s, #fmt("Duplicate destructor \
self.span_note(s, fmt!("Duplicate destructor \
declaration for class %s",
*self.interner.get(class_name)));
self.span_fatal(copy s_first, ~"First destructor \
Expand Down
2 changes: 1 addition & 1 deletion src/rustc/driver/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl session {
// This exists to help with refactoring to eliminate impossible
// cases later on
fn impossible_case(sp: span, msg: &str) -> ! {
self.span_bug(sp, #fmt("Impossible case reached: %s", msg));
self.span_bug(sp, fmt!("Impossible case reached: %s", msg));
}
fn verbose() -> bool { self.debugging_opt(verbose) }
fn time_passes() -> bool { self.debugging_opt(time_passes) }
Expand Down
4 changes: 2 additions & 2 deletions src/rustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ fn item_family(item: ebml::Doc) -> Family {
'g' => PublicField,
'j' => PrivateField,
'N' => InheritedField,
c => fail (#fmt("unexpected family char: %c", c))
c => fail (fmt!("unexpected family char: %c", c))
}
}

Expand Down Expand Up @@ -705,7 +705,7 @@ fn get_trait_methods(intr: @ident_interner, cdata: cmd, id: ast::node_id,
self_ty: self_ty,
vis: ast::public});
}
#debug("get_trait_methods: }");
debug!("get_trait_methods: }");
@result
}

Expand Down
4 changes: 2 additions & 2 deletions src/rustc/middle/borrowck/gather_loans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ impl gather_loan_ctxt {
_ => {
self.bccx.tcx.sess.span_bug(
cmt.span,
#fmt["loans required but scope is scope_region is %s",
region_to_str(self.tcx(), scope_r)]);
fmt!("loans required but scope is scope_region is %s",
region_to_str(self.tcx(), scope_r)));
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/rustc/middle/borrowck/preserve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,17 +314,17 @@ priv impl &preserve_ctxt {
// we can only root values if the desired region is some concrete
// scope within the fn body
ty::re_scope(scope_id) => {
#debug["Considering root map entry for %s: \
debug!("Considering root map entry for %s: \
node %d:%u -> scope_id %?, root_ub %?",
self.bccx.cmt_to_repr(cmt), base.id,
derefs, scope_id, self.root_ub];
derefs, scope_id, self.root_ub);
if self.bccx.is_subregion_of(self.scope_region, root_region) {
#debug["Elected to root"];
debug!("Elected to root");
let rk = {id: base.id, derefs: derefs};
self.bccx.root_map.insert(rk, scope_id);
return Ok(pc_ok);
} else {
#debug["Unable to root"];
debug!("Unable to root");
return Err({cmt:cmt,
code:err_out_of_root_scope(root_region,
self.scope_region)});
Expand Down
2 changes: 1 addition & 1 deletion src/rustc/middle/check_alt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn check_expr(tcx: ty::ctxt, ex: @expr, &&s: (), v: visit::vt<()>) {
if arms.is_empty() {
if !type_is_empty(tcx, pat_ty) {
// We know the type is inhabited, so this must be wrong
tcx.sess.span_err(ex.span, #fmt("non-exhaustive patterns: \
tcx.sess.span_err(ex.span, fmt!("non-exhaustive patterns: \
type %s is non-empty", ty_to_str(tcx, pat_ty)));
}
// If the type *is* empty, it's vacuously exhaustive
Expand Down
4 changes: 2 additions & 2 deletions src/rustc/middle/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -902,11 +902,11 @@ impl Liveness {
self.propagate_through_fn_block(decl, body)
});

// hack to skip the loop unless #debug is enabled:
// hack to skip the loop unless debug! is enabled:
debug!("^^ liveness computation results for body %d (entry=%s)",
{
for uint::range(0u, self.ir.num_live_nodes) |ln_idx| {
#debug["%s", self.ln_str(LiveNode(ln_idx))];
debug!("%s", self.ln_str(LiveNode(ln_idx)));
}
body.node.id
},
Expand Down
4 changes: 2 additions & 2 deletions src/rustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,12 +918,12 @@ impl Resolver {
match ns.find(|n| child.defined_in_namespace(n)) {
Some(ns) => {
self.session.span_err(sp,
#fmt("Duplicate definition of %s %s",
fmt!("Duplicate definition of %s %s",
namespace_to_str(ns),
self.session.str_of(name)));
do child.span_for_namespace(ns).iter() |sp| {
self.session.span_note(*sp,
#fmt("First definition of %s %s here:",
fmt!("First definition of %s %s here:",
namespace_to_str(ns),
self.session.str_of(name)));
}
Expand Down
2 changes: 1 addition & 1 deletion src/rustc/middle/trans/glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ fn emit_tydescs(ccx: @crate_ctxt) {
// Index tydesc by addrspace.
if ti.addrspace > gc_box_addrspace {
let llty = T_ptr(ccx.tydesc_type);
let addrspace_name = #fmt("_gc_addrspace_metadata_%u",
let addrspace_name = fmt!("_gc_addrspace_metadata_%u",
ti.addrspace as uint);
let addrspace_gvar = str::as_c_str(addrspace_name, |buf| {
llvm::LLVMAddGlobal(ccx.llmod, llty, buf)
Expand Down
4 changes: 2 additions & 2 deletions src/rustc/middle/trans/monomorphize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ fn monomorphic_fn(ccx: @crate_ctxt,
must_cast = true;
}

#debug["monomorphic_fn(fn_id=%? (%s), real_substs=%?, substs=%?, \
debug!("monomorphic_fn(fn_id=%? (%s), real_substs=%?, substs=%?, \
hash_id = %?",
fn_id, ty::item_path_str(ccx.tcx, fn_id),
real_substs.map(|s| ty_to_str(ccx.tcx, *s)),
substs.map(|s| ty_to_str(ccx.tcx, *s)), hash_id];
substs.map(|s| ty_to_str(ccx.tcx, *s)), hash_id);

match ccx.monomorphized.find(hash_id) {
Some(val) => {
Expand Down
4 changes: 2 additions & 2 deletions src/rustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3020,7 +3020,7 @@ fn get_field(tcx: ctxt, rec_ty: t, id: ast::ident) -> field {
match vec::find(get_fields(rec_ty), |f| f.ident == id) {
Some(f) => f,
// Do we only call this when we know the field is legit?
None => fail (#fmt("get_field: ty doesn't have a field %s",
None => fail (fmt!("get_field: ty doesn't have a field %s",
tcx.sess.str_of(id)))
}
}
Expand Down Expand Up @@ -3335,7 +3335,7 @@ fn provided_trait_methods(cx: ctxt, id: ast::def_id) -> ~[@ast::method] {
match ast_util::split_trait_methods(ms) {
(_, p) => p
},
_ => cx.sess.bug(#fmt("provided_trait_methods: %? is not a trait",
_ => cx.sess.bug(fmt!("provided_trait_methods: %? is not a trait",
id))
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/rustc/middle/typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ fn compare_impl_method(tcx: ty::ctxt, sp: span,
}

if impl_m.tps.len() != trait_m.tps.len() {
tcx.sess.span_err(sp, #fmt("method `%s` \
tcx.sess.span_err(sp, fmt!("method `%s` \
has %u type %s, but its trait declaration has %u type %s",
tcx.sess.str_of(trait_m.ident), impl_m.tps.len(),
pluralize(impl_m.tps.len(), ~"parameter"),
Expand All @@ -291,7 +291,7 @@ fn compare_impl_method(tcx: ty::ctxt, sp: span,
// Would be nice to use the ty param names in the error message,
// but we don't have easy access to them here
if impl_param_bounds.len() != trait_param_bounds.len() {
tcx.sess.span_err(sp, #fmt("in method `%s`, \
tcx.sess.span_err(sp, fmt!("in method `%s`, \
type parameter %u has %u %s, but the same type \
parameter in its trait declaration has %u %s",
tcx.sess.str_of(trait_m.ident),
Expand Down
Loading

0 comments on commit 1bede1f

Please sign in to comment.