More consistent use of backticks and "expected" in error messages.

Got some of the debug messages, here, too.  I figure it doesn't hurt
to get used to doing this even in places where users won't ever see
it.
This commit is contained in:
Lindsey Kuper 2012-07-13 13:20:49 -07:00
parent 07a81ad12e
commit 5a63b2100e
29 changed files with 102 additions and 98 deletions

View File

@ -405,7 +405,7 @@ impl parser for parser {
alt self.ch {
',' { self.bump(); }
']' { self.bump(); ret ok(list(@values)); }
_ { ret self.error("expecting ',' or ']'"); }
_ { ret self.error("expected `,` or `]`"); }
}
};
}
@ -437,7 +437,7 @@ impl parser for parser {
if self.ch != ':' {
if self.eof() { break; }
ret self.error("expecting ':'");
ret self.error("expected `:`");
}
self.bump();
@ -452,7 +452,7 @@ impl parser for parser {
'}' { self.bump(); ret ok(dict(values)); }
_ {
if self.eof() { break; }
ret self.error("expecting ',' or '}'");
ret self.error("expected `,` or `}`");
}
}
}
@ -797,7 +797,7 @@ mod tests {
assert from_str("[1,]") ==
err({line: 1u, col: 4u, msg: @"invalid syntax"});
assert from_str("[6 7]") ==
err({line: 1u, col: 4u, msg: @"expecting ',' or ']'"});
err({line: 1u, col: 4u, msg: @"expected `,` or `]`"});
assert from_str("[]") == ok(list(@~[]));
assert from_str("[ ]") == ok(list(@~[]));
@ -826,13 +826,13 @@ mod tests {
err({line: 1u, col: 6u, msg: @"EOF while parsing object"});
assert from_str("{\"a\" 1") ==
err({line: 1u, col: 6u, msg: @"expecting ':'"});
err({line: 1u, col: 6u, msg: @"expected `:`"});
assert from_str("{\"a\":") ==
err({line: 1u, col: 6u, msg: @"EOF while parsing value"});
assert from_str("{\"a\":1") ==
err({line: 1u, col: 7u, msg: @"EOF while parsing object"});
assert from_str("{\"a\":1 1") ==
err({line: 1u, col: 8u, msg: @"expecting ',' or '}'"});
err({line: 1u, col: 8u, msg: @"expected `,` or `}`"});
assert from_str("{\"a\":1,") ==
err({line: 1u, col: 8u, msg: @"EOF while parsing object"});

View File

@ -28,23 +28,23 @@ impl parser_common for parser {
fn unexpected_last(t: token::token) -> ! {
self.span_fatal(
copy self.last_span,
"unexpected token: '" + token_to_str(self.reader, t) + "'");
"unexpected token: `" + token_to_str(self.reader, t) + "`");
}
fn unexpected() -> ! {
self.fatal("unexpected token: '"
+ token_to_str(self.reader, self.token) + "'");
self.fatal("unexpected token: `"
+ token_to_str(self.reader, self.token) + "`");
}
fn expect(t: token::token) {
if self.token == t {
self.bump();
} else {
let mut s: str = "expecting '";
let mut s: str = "expected `";
s += token_to_str(self.reader, t);
s += "' but found '";
s += "` but found `";
s += token_to_str(self.reader, self.token);
self.fatal(s + "'");
self.fatal(s + "`");
}
}
@ -53,8 +53,9 @@ impl parser_common for parser {
token::IDENT(i, _) { self.bump(); ret self.get_str(i); }
token::ACTUALLY(token::w_ident(*)) { self.bug(
"ident interpolation not converted to real token"); }
_ { self.fatal("expecting ident, found "
+ token_to_str(self.reader, self.token)); }
_ { self.fatal("expected ident, found `"
+ token_to_str(self.reader, self.token)
+ "`"); }
}
}
@ -121,8 +122,9 @@ impl parser_common for parser {
fn expect_keyword(word: str) {
self.require_keyword(word);
if !self.eat_keyword(word) {
self.fatal("expecting " + word + ", found " +
token_to_str(self.reader, self.token));
self.fatal("expected `" + word + "`, found `" +
token_to_str(self.reader, self.token) +
"`");
}
}
@ -152,10 +154,11 @@ impl parser_common for parser {
} else if self.token == token::BINOP(token::SHR) {
self.swap(token::GT, self.span.lo + 1u, self.span.hi);
} else {
let mut s: str = "expecting ";
let mut s: str = "expected `";
s += token_to_str(self.reader, token::GT);
s += ", found ";
s += "`, found `";
s += token_to_str(self.reader, self.token);
s += "`";
self.fatal(s);
}
}

View File

@ -311,7 +311,7 @@ class parser {
vis: public})
}
_ { self.fatal("expected ';' or '}` \
_ { self.fatal("expected `;` or `}` \
but found `"
+ token_to_str(self.reader, self.token) + "`");
}
@ -545,7 +545,7 @@ class parser {
} else if self.token == token::MOD_SEP || is_ident(self.token) {
let path = self.parse_path_with_tps(colons_before_params);
ty_path(path, self.get_id())
} else { self.fatal("expecting type"); };
} else { self.fatal("expected type"); };
let sp = mk_sp(lo, self.last_span.hi);
ret @{id: self.get_id(),
@ -1176,7 +1176,7 @@ class parser {
self.bump();
ret (some(sep), zerok);
} else {
self.fatal("expected '*' or '+'");
self.fatal("expected `*` or `+`");
}
}
}
@ -1709,8 +1709,9 @@ class parser {
if self.token == token::UNDERSCORE {
self.bump();
if self.token != token::RBRACE {
self.fatal("expecting }, found " +
token_to_str(self.reader, self.token));
self.fatal("expected `}`, found `" +
token_to_str(self.reader, self.token) +
"`");
}
etc = true;
break;
@ -1855,7 +1856,7 @@ class parser {
is_mutbl = class_mutable;
}
if !is_plain_ident(self.token) {
self.fatal("expecting ident");
self.fatal("expected ident");
}
let name = self.parse_ident();
self.expect(token::COLON);
@ -2000,9 +2001,9 @@ class parser {
}
t {
if classify::stmt_ends_with_semi(*stmt) {
self.fatal("expected ';' or '}' after expression \
but found '"
+ token_to_str(self.reader, t) + "'");
self.fatal("expected `;` or `}` after expression \
but found `"
+ token_to_str(self.reader, t) + "`");
}
vec::push(stmts, stmt);
}
@ -2363,8 +2364,8 @@ class parser {
alt self.parse_item(attrs, vis) {
some(i) { vec::push(items, i); }
_ {
self.fatal("expected item but found '" +
token_to_str(self.reader, self.token) + "'");
self.fatal("expected item but found `" +
token_to_str(self.reader, self.token) + "`");
}
}
#debug["parse_mod_items: attrs=%?", attrs];

View File

@ -357,7 +357,7 @@ fn build_link_meta(sess: session, c: ast::crate, output: str,
fn warn_missing(sess: session, name: str, default: str) {
if !sess.building_library { ret; }
sess.warn(#fmt["missing crate link meta '%s', using '%s' as default",
sess.warn(#fmt["missing crate link meta `%s`, using `%s` as default",
name, default]);
}
@ -371,7 +371,7 @@ fn build_link_meta(sess: session, c: ast::crate, output: str,
let mut os =
str::split_char(path::basename(output), '.');
if (vec::len(os) < 2u) {
sess.fatal(#fmt("output file name %s doesn't\
sess.fatal(#fmt("output file name `%s` doesn't\
appear to have an extension", output));
}
vec::pop(os);
@ -680,7 +680,7 @@ fn link_binary(sess: session,
// We run 'cc' here
let prog = run::program_output(cc_prog, cc_args);
if 0 != prog.status {
sess.err(#fmt["linking with %s failed with code %d",
sess.err(#fmt["linking with `%s` failed with code %d",
cc_prog, prog.status]);
sess.note(#fmt["%s arguments: %s",
cc_prog, str::connect(cc_args, " ")]);
@ -696,7 +696,7 @@ fn link_binary(sess: session,
// Remove the temporary object file if we aren't saving temps
if !sess.opts.save_temps {
if ! os::remove_file(obj_filename) {
sess.warn(#fmt["failed to delete object file '%s'",
sess.warn(#fmt["failed to delete object file `%s`",
obj_filename]);
}
}

View File

@ -41,7 +41,7 @@ fn load_library_crate(cx: ctxt) -> {ident: str, data: @~[u8]} {
some(t) { ret t; }
none {
cx.diag.span_fatal(
cx.span, #fmt["can't find crate for '%s'", *cx.ident]);
cx.span, #fmt["can't find crate for `%s`", *cx.ident]);
}
}
}

View File

@ -43,7 +43,7 @@ fn check_capture_clause(tcx: ty::ctxt,
if !vec::any(*freevars, |fv| fv.def == cap_def ) {
tcx.sess.span_warn(
cap_item.span,
#fmt("captured variable '%s' not used in closure",
#fmt("captured variable `%s` not used in closure",
*cap_item.name));
}
@ -51,7 +51,7 @@ fn check_capture_clause(tcx: ty::ctxt,
if !seen_defs.insert(cap_def_id, ()) {
tcx.sess.span_err(
cap_item.span,
#fmt("variable '%s' captured more than once",
#fmt("variable `%s` captured more than once",
*cap_item.name));
}
}

View File

@ -127,7 +127,7 @@ fn get_lint_dict() -> lint_dict {
("vecs_not_implicitly_copyable",
@{lint: vecs_not_implicitly_copyable,
desc: "make vecs and strs not implicitly copyable\
('err' is ignored; only checked at top level",
(`err` is ignored; only checked at top level",
default: warn}),
("implicit_copies",
@ -223,7 +223,7 @@ impl methods for ctxt {
self.span_lint(
self.get_level(unrecognized_warning),
meta.span,
#fmt("unknown warning: '%s'", name));
#fmt("unknown warning: `%s`", name));
}
(_, some((lint, new_level))) {
// we do multiple unneeded copies of the map

View File

@ -1309,7 +1309,7 @@ class Resolver {
def_self(*) | def_arg(*) | def_local(*) |
def_prim_ty(*) | def_ty_param(*) | def_binding(*) |
def_use(*) | def_upvar(*) | def_region(*) {
fail #fmt("didn't expect %?", def);
fail #fmt("didn't expect `%?`", def);
}
}
}
@ -1360,14 +1360,14 @@ class Resolver {
// skip them.
#debug("(building reduced graph for impls in external crate) looking \
for impls in '%s' (%?)",
for impls in `%s` (%?)",
self.module_to_str(module),
copy module.def_id);
alt module.def_id {
none {
#debug("(building reduced graph for impls in external \
module) no def ID for '%s', skipping",
module) no def ID for `%s`, skipping",
self.module_to_str(module));
ret;
}
@ -1390,7 +1390,7 @@ class Resolver {
def_ids.insert(implementation.did, ());
#debug("(building reduced graph for impls in external module) \
added impl '%s' (%?) to '%s'",
added impl `%s` (%?) to `%s`",
*implementation.ident,
implementation.did,
self.module_to_str(module));
@ -1549,8 +1549,8 @@ class Resolver {
let mut resolution_result;
let module_path = import_directive.module_path;
#debug("(resolving import for module) resolving import '%s::...' in \
'%s'",
#debug("(resolving import for module) resolving import `%s::...` in \
`%s`",
*(*self.atom_table).atoms_to_str((*module_path).get()),
self.module_to_str(module));
@ -1633,15 +1633,15 @@ class Resolver {
target: Atom, source: Atom)
-> ResolveResult<()> {
#debug("(resolving single import) resolving '%s' = '%s::%s' from \
'%s'",
#debug("(resolving single import) resolving `%s` = `%s::%s` from \
`%s`",
*(*self.atom_table).atom_to_str(target),
self.module_to_str(containing_module),
*(*self.atom_table).atom_to_str(source),
self.module_to_str(module));
if !self.name_is_exported(containing_module, source) {
#debug("(resolving single import) name '%s' is unexported",
#debug("(resolving single import) name `%s` is unexported",
*(*self.atom_table).atom_to_str(source));
ret Failed;
}
@ -1875,13 +1875,13 @@ class Resolver {
|atom, target_import_resolution| {
if !self.name_is_exported(containing_module, atom) {
#debug("(resolving glob import) name '%s' is unexported",
#debug("(resolving glob import) name `%s` is unexported",
*(*self.atom_table).atom_to_str(atom));
again;
}
#debug("(resolving glob import) writing module resolution \
%? into '%s'",
%? into `%s`",
is_none(target_import_resolution.module_target),
self.module_to_str(module));
@ -1952,7 +1952,7 @@ class Resolver {
// Add all children from the containing module.
for containing_module.children.each |atom, name_bindings| {
if !self.name_is_exported(containing_module, atom) {
#debug("(resolving glob import) name '%s' is unexported",
#debug("(resolving glob import) name `%s` is unexported",
*(*self.atom_table).atom_to_str(atom));
again;
}
@ -1971,8 +1971,8 @@ class Resolver {
}
#debug("(resolving glob import) writing resolution '%s' in '%s' \
to '%s'",
#debug("(resolving glob import) writing resolution `%s` in `%s` \
to `%s`",
*(*self.atom_table).atom_to_str(atom),
self.module_to_str(containing_module),
self.module_to_str(module));
@ -2070,8 +2070,8 @@ class Resolver {
let module_path_len = (*module_path).len();
assert module_path_len > 0u;
#debug("(resolving module path for import) processing '%s' rooted at \
'%s'",
#debug("(resolving module path for import) processing `%s` rooted at \
`%s`",
*(*self.atom_table).atoms_to_str((*module_path).get()),
self.module_to_str(module));
@ -2107,8 +2107,8 @@ class Resolver {
namespace: Namespace)
-> ResolveResult<Target> {
#debug("(resolving item in lexical scope) resolving '%s' in \
namespace %? in '%s'",
#debug("(resolving item in lexical scope) resolving `%s` in \
namespace %? in `%s`",
*(*self.atom_table).atom_to_str(name),
namespace,
self.module_to_str(module));
@ -2234,12 +2234,12 @@ class Resolver {
xray: XrayFlag)
-> ResolveResult<Target> {
#debug("(resolving name in module) resolving '%s' in '%s'",
#debug("(resolving name in module) resolving `%s` in `%s`",
*(*self.atom_table).atom_to_str(name),
self.module_to_str(module));
if xray == NoXray && !self.name_is_exported(module, name) {
#debug("(resolving name in module) name '%s' is unexported",
#debug("(resolving name in module) name `%s` is unexported",
*(*self.atom_table).atom_to_str(name));
ret Failed;
}
@ -2320,8 +2320,8 @@ class Resolver {
}
}
#debug("(resolving one-level naming result) resolving import '%s' = \
'%s' in '%s'",
#debug("(resolving one-level naming result) resolving import `%s` = \
`%s` in `%s`",
*(*self.atom_table).atom_to_str(target_name),
*(*self.atom_table).atom_to_str(source_name),
self.module_to_str(module));
@ -2456,7 +2456,7 @@ class Resolver {
}
some(import_resolution) {
#debug("(resolving one-level renaming import) writing module \
result %? for '%s' into '%s'",
result %? for `%s` into `%s`",
is_none(module_result),
*(*self.atom_table).atom_to_str(target_name),
self.module_to_str(module));
@ -2536,7 +2536,7 @@ class Resolver {
some(_) {
// Bail out.
#debug("(recording exports for module subtree) not recording \
exports for '%s'",
exports for `%s`",
self.module_to_str(module));
ret;
}
@ -2622,7 +2622,7 @@ class Resolver {
some(_) {
// Bail out.
#debug("(building impl scopes for module subtree) not \
resolving implementations for '%s'",
resolving implementations for `%s`",
self.module_to_str(module));
ret;
}
@ -2724,7 +2724,7 @@ class Resolver {
some(name) {
alt orig_module.children.find(name) {
none {
#debug("!!! (with scope) didn't find '%s' in '%s'",
#debug("!!! (with scope) didn't find `%s` in `%s`",
*(*self.atom_table).atom_to_str(name),
self.module_to_str(orig_module));
}
@ -2732,7 +2732,7 @@ class Resolver {
alt (*name_bindings).get_module_if_available() {
none {
#debug("!!! (with scope) didn't find module \
for '%s' in '%s'",
for `%s` in `%s`",
*(*self.atom_table).atom_to_str(name),
self.module_to_str(orig_module));
}
@ -3155,7 +3155,7 @@ class Resolver {
self.resolve_type(argument.ty, visitor);
#debug("(resolving function) recorded argument '%s'",
#debug("(resolving function) recorded argument `%s`",
*(*self.atom_table).atom_to_str(name));
}
@ -3504,7 +3504,7 @@ class Resolver {
let mut result_def;
alt self.resolve_path(path, TypeNS, true, visitor) {
some(def) {
#debug("(resolving type) resolved '%s' to type",
#debug("(resolving type) resolved `%s` to type",
*path.idents.last());
result_def = some(def);
}
@ -3542,7 +3542,7 @@ class Resolver {
alt copy result_def {
some(def) {
// Write the result into the def map.
#debug("(resolving type) writing resolution for '%s' \
#debug("(resolving type) writing resolution for `%s` \
(id %d)",
connect(path.idents.map(|x| *x), "::"),
path_id);
@ -3550,7 +3550,7 @@ class Resolver {
}
none {
self.session.span_err
(ty.span, #fmt("use of undeclared type name '%s'",
(ty.span, #fmt("use of undeclared type name `%s`",
connect(path.idents.map(|x| *x),
"::")));
}
@ -3606,7 +3606,7 @@ class Resolver {
alt self.resolve_enum_variant_or_const(atom) {
FoundEnumVariant(def) if mode == RefutableMode {
#debug("(resolving pattern) resolving '%s' to \
#debug("(resolving pattern) resolving `%s` to \
enum variant",
*path.idents[0]);
@ -3628,7 +3628,7 @@ class Resolver {
in scope");
}
EnumVariantOrConstNotFound {
#debug("(resolving pattern) binding '%s'",
#debug("(resolving pattern) binding `%s`",
*path.idents[0]);
let is_mutable = mutability == Mutable;
@ -3822,7 +3822,7 @@ class Resolver {
-> NameDefinition {
if xray == NoXray && !self.name_is_exported(containing_module, name) {
#debug("(resolving definition of name in module) name '%s' is \
#debug("(resolving definition of name in module) name `%s` is \
unexported",
*(*self.atom_table).atom_to_str(name));
ret NoNameDefinition;
@ -4018,7 +4018,7 @@ class Resolver {
alt copy search_result {
some(dl_def(def)) {
#debug("(resolving path in local ribs) resolved '%s' to \
#debug("(resolving path in local ribs) resolved `%s` to \
local: %?",
*(*self.atom_table).atom_to_str(name),
def);
@ -4049,7 +4049,7 @@ class Resolver {
}
some(def) {
#debug("(resolving item path in lexical scope) \
resolved '%s' to item",
resolved `%s` to item",
*(*self.atom_table).atom_to_str(name));
ret some(def);
}
@ -4082,7 +4082,7 @@ class Resolver {
alt self.resolve_path(path, ValueNS, true, visitor) {
some(def) {
// Write the result into the def map.
#debug("(resolving expr) resolved '%s'",
#debug("(resolving expr) resolved `%s`",
connect(path.idents.map(|x| *x), "::"));
self.record_def(expr.id, def);
}
@ -4166,7 +4166,7 @@ class Resolver {
some(_) {
// Bail out.
#debug("(checking for unused imports in module subtree) not \
checking for unused imports for '%s'",
checking for unused imports for `%s`",
self.module_to_str(module));
ret;
}
@ -4262,7 +4262,7 @@ class Resolver {
}
fn dump_module(module: @Module) {
#debug("Dump of module '%s':", self.module_to_str(module));
#debug("Dump of module `%s`:", self.module_to_str(module));
#debug("Children:");
for module.children.each |name, _child| {

View File

@ -262,7 +262,7 @@ fn check_main_fn_ty(ccx: @crate_ctxt,
if !ok {
tcx.sess.span_err(main_span,
#fmt("Wrong type in main function: found `%s`, \
expecting `extern fn(~[str]) -> ()` \
expected `extern fn(~[str]) -> ()` \
or `extern fn() -> ()`",
ty_to_str(tcx, main_t)));
}

View File

@ -1,4 +1,4 @@
// error-pattern: expecting mod
// error-pattern: expected `mod`
#[attr = "val"];
#[attr = "val"] // Unterminated

View File

@ -1,4 +1,4 @@
// error-pattern:expecting ']'
// error-pattern:expected `]`
// asterisk is bogus
#[attr*]

View File

@ -1,4 +1,4 @@
// error-pattern: expecting
// error-pattern: expected
fn main() {
let int x = 5;

View File

@ -1,3 +1,3 @@
// error-pattern:expecting `extern fn(~[str])
// error-pattern:expected `extern fn(~[str])
fn main(x: int) { }

View File

@ -1,4 +1,4 @@
// error-pattern: expecting
// error-pattern: expected
fn main() {
let x.y::<int>.z foo;

View File

@ -1,4 +1,4 @@
// error-pattern:variable 'x' captured more than once
// error-pattern:variable `x` captured more than once
fn main() {
let x = 5;
let y = fn~(move x, copy x) -> int { x };

View File

@ -1,4 +1,4 @@
// error-pattern:variable 'x' captured more than once
// error-pattern:variable `x` captured more than once
fn main() {
let x = 5;
let y = fn~(copy x, copy x) -> int { x };

View File

@ -1,4 +1,4 @@
// error-pattern:variable 'x' captured more than once
// error-pattern:variable `x` captured more than once
fn main() {
let x = 5;
let y = fn~(move x, move x) -> int { x };

View File

@ -1,5 +1,5 @@
fn main() {
do something
|x| do somethingelse //~ ERROR: expecting '{' but found 'do'
|x| do somethingelse //~ ERROR: expected `{` but found `do`
|y| say(x, y)
}

View File

@ -1,3 +1,3 @@
fn main() {
let x = do y; //~ ERROR: expecting '{' but found
let x = do y; //~ ERROR: expected `{` but found
}

View File

@ -1,4 +1,4 @@
// error-pattern:unexpected token: '}'
// error-pattern:unexpected token: `}`
// Issue #1200
type t = {};

View File

@ -1,3 +1,3 @@
fn main() {
let v = ~[,]; //~ ERROR unexpected token: ','
let v = ~[,]; //~ ERROR unexpected token: `,`
}

View File

@ -1,4 +1,4 @@
// error-pattern:expected item but found '#'
// error-pattern:expected item but found `#`
// Don't know how to deal with a syntax extension appearing after an
// item attribute. Probably could use a better error message.

View File

@ -1,2 +1,2 @@
// error-pattern:expecting
// error-pattern:expected
import foo::{bar}::baz

View File

@ -1,4 +1,4 @@
// error-pattern:expecting
// error-pattern:expected
import baz = foo::{bar};

View File

@ -1,2 +1,2 @@
// error-pattern:expecting
// error-pattern:expected
import foo::*::bar

View File

@ -1,4 +1,4 @@
// error-pattern:expecting
// error-pattern:expected
import baz = foo::*;

View File

@ -1,4 +1,4 @@
// xfail-test
fn foo(x) { //~ ERROR expecting ':' but found ')'
fn foo(x) { //~ ERROR expected `:` but found `)`
}

View File

@ -1,4 +1,4 @@
// error-pattern:can't find crate for 'std'
// error-pattern:can't find crate for `std`
use std(complex(meta(item)));

View File

@ -1,4 +1,4 @@
// error-pattern:can't find crate for 'std'
// error-pattern:can't find crate for `std`
use std (name = "std",
vers = "bogus");