Skip to content

Commit

Permalink
Adjust the error messages to match the pattern "expected foo, found bar"
Browse files Browse the repository at this point in the history
  • Loading branch information
treeman committed Aug 24, 2014
1 parent 2e5aea6 commit 9968ae2
Show file tree
Hide file tree
Showing 118 changed files with 266 additions and 266 deletions.
2 changes: 1 addition & 1 deletion src/libfmt_macros/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl<'a> Parser<'a> {
self.cur.next();
}
Some((_, other)) => {
self.err(format!("expected `{}` but found `{}`",
self.err(format!("expected `{}`, found `{}`",
c,
other).as_slice());
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/metadata/tydecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,12 +575,12 @@ pub fn parse_def_id(buf: &[u8]) -> ast::DefId {

let crate_num = match uint::parse_bytes(crate_part, 10u) {
Some(cn) => cn as ast::CrateNum,
None => fail!("internal error: parse_def_id: crate number expected, but found {:?}",
None => fail!("internal error: parse_def_id: crate number expected, found {:?}",
crate_part)
};
let def_num = match uint::parse_bytes(def_part, 10u) {
Some(dn) => dn as ast::NodeId,
None => fail!("internal error: parse_def_id: id expected, but found {:?}",
None => fail!("internal error: parse_def_id: id expected, found {:?}",
def_part)
};
ast::DefId { krate: crate_num, node: def_num }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl<'a> Visitor<()> for EffectCheckVisitor<'a> {
// we need to create a new context, when we're
// - outside `unsafe` and found a `unsafe` block
// (normal case)
// - inside `unsafe` but found an `unsafe` block
// - inside `unsafe`, found an `unsafe` block
// created internally to the compiler
//
// The second case is necessary to ensure that the
Expand Down
60 changes: 30 additions & 30 deletions src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3603,17 +3603,17 @@ pub fn type_err_to_str(cx: &ctxt, err: &type_err) -> String {
match *err {
terr_mismatch => "types differ".to_string(),
terr_fn_style_mismatch(values) => {
format!("expected {} fn but found {} fn",
format!("expected {} fn, found {} fn",
values.expected.to_string(),
values.found.to_string())
}
terr_abi_mismatch(values) => {
format!("expected {} fn but found {} fn",
format!("expected {} fn, found {} fn",
values.expected.to_string(),
values.found.to_string())
}
terr_onceness_mismatch(values) => {
format!("expected {} fn but found {} fn",
format!("expected {} fn, found {} fn",
values.expected.to_string(),
values.found.to_string())
}
Expand All @@ -3630,28 +3630,28 @@ pub fn type_err_to_str(cx: &ctxt, err: &type_err) -> String {
terr_ptr_mutability => "pointers differ in mutability".to_string(),
terr_ref_mutability => "references differ in mutability".to_string(),
terr_ty_param_size(values) => {
format!("expected a type with {} type params \
but found one with {} type params",
format!("expected a type with {} type params, \
found one with {} type params",
values.expected,
values.found)
}
terr_tuple_size(values) => {
format!("expected a tuple with {} elements \
but found one with {} elements",
format!("expected a tuple with {} elements, \
found one with {} elements",
values.expected,
values.found)
}
terr_record_size(values) => {
format!("expected a record with {} fields \
but found one with {} fields",
format!("expected a record with {} fields, \
found one with {} fields",
values.expected,
values.found)
}
terr_record_mutability => {
"record elements differ in mutability".to_string()
}
terr_record_fields(values) => {
format!("expected a record with field `{}` but found one \
format!("expected a record with field `{}`, found one \
with field `{}`",
token::get_ident(values.expected),
token::get_ident(values.found))
Expand All @@ -3670,57 +3670,57 @@ pub fn type_err_to_str(cx: &ctxt, err: &type_err) -> String {
}
terr_regions_insufficiently_polymorphic(br, _) => {
format!("expected bound lifetime parameter {}, \
but found concrete lifetime",
found concrete lifetime",
bound_region_ptr_to_string(cx, br))
}
terr_regions_overly_polymorphic(br, _) => {
format!("expected concrete lifetime, \
but found bound lifetime parameter {}",
found bound lifetime parameter {}",
bound_region_ptr_to_string(cx, br))
}
terr_trait_stores_differ(_, ref values) => {
format!("trait storage differs: expected `{}` but found `{}`",
format!("trait storage differs: expected `{}`, found `{}`",
trait_store_to_string(cx, (*values).expected),
trait_store_to_string(cx, (*values).found))
}
terr_sorts(values) => {
format!("expected {} but found {}",
format!("expected {}, found {}",
ty_sort_string(cx, values.expected),
ty_sort_string(cx, values.found))
}
terr_traits(values) => {
format!("expected trait `{}` but found trait `{}`",
format!("expected trait `{}`, found trait `{}`",
item_path_str(cx, values.expected),
item_path_str(cx, values.found))
}
terr_builtin_bounds(values) => {
if values.expected.is_empty() {
format!("expected no bounds but found `{}`",
format!("expected no bounds, found `{}`",
values.found.user_string(cx))
} else if values.found.is_empty() {
format!("expected bounds `{}` but found no bounds",
format!("expected bounds `{}`, found no bounds",
values.expected.user_string(cx))
} else {
format!("expected bounds `{}` but found bounds `{}`",
format!("expected bounds `{}`, found bounds `{}`",
values.expected.user_string(cx),
values.found.user_string(cx))
}
}
terr_integer_as_char => {
"expected an integral type but found `char`".to_string()
"expected an integral type, found `char`".to_string()
}
terr_int_mismatch(ref values) => {
format!("expected `{}` but found `{}`",
format!("expected `{}`, found `{}`",
values.expected.to_string(),
values.found.to_string())
}
terr_float_mismatch(ref values) => {
format!("expected `{}` but found `{}`",
format!("expected `{}`, found `{}`",
values.expected.to_string(),
values.found.to_string())
}
terr_variadic_mismatch(ref values) => {
format!("expected {} fn but found {} function",
format!("expected {} fn, found {} function",
if values.expected { "variadic" } else { "non-variadic" },
if values.found { "variadic" } else { "non-variadic" })
}
Expand Down Expand Up @@ -4548,7 +4548,7 @@ pub fn eval_repeat_count<T: ExprTyProvider>(tcx: &T, count_expr: &ast::Expr) ->
const_eval::const_int(count) => if count < 0 {
tcx.ty_ctxt().sess.span_err(count_expr.span,
"expected positive integer for \
repeat count but found negative integer");
repeat count, found negative integer");
return 0;
} else {
return count as uint
Expand All @@ -4557,38 +4557,38 @@ pub fn eval_repeat_count<T: ExprTyProvider>(tcx: &T, count_expr: &ast::Expr) ->
const_eval::const_float(count) => {
tcx.ty_ctxt().sess.span_err(count_expr.span,
"expected positive integer for \
repeat count but found float");
repeat count, found float");
return count as uint;
}
const_eval::const_str(_) => {
tcx.ty_ctxt().sess.span_err(count_expr.span,
"expected positive integer for \
repeat count but found string");
repeat count, found string");
return 0;
}
const_eval::const_bool(_) => {
tcx.ty_ctxt().sess.span_err(count_expr.span,
"expected positive integer for \
repeat count but found boolean");
repeat count, found boolean");
return 0;
}
const_eval::const_binary(_) => {
tcx.ty_ctxt().sess.span_err(count_expr.span,
"expected positive integer for \
repeat count but found binary array");
repeat count, found binary array");
return 0;
}
const_eval::const_nil => {
tcx.ty_ctxt().sess.span_err(count_expr.span,
"expected positive integer for \
repeat count but found ()");
repeat count, found ()");
return 0;
}
},
Err(..) => {
tcx.ty_ctxt().sess.span_err(count_expr.span,
"expected constant integer for repeat count \
but found variable");
"expected constant integer for repeat count, \
found variable");
return 0;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ fn ast_path_substs<AC:AstConv,RS:RegionScope>(

if supplied_num_region_params != 0 || anon_regions.is_err() {
span_err!(tcx.sess, path.span, E0107,
"wrong number of lifetime parameters: expected {} but found {}",
"wrong number of lifetime parameters: expected {}, found {}",
expected_num_region_params, supplied_num_region_params);
}

Expand All @@ -216,7 +216,7 @@ fn ast_path_substs<AC:AstConv,RS:RegionScope>(
"expected"
};
this.tcx().sess.span_fatal(path.span,
format!("wrong number of type arguments: {} {} but found {}",
format!("wrong number of type arguments: {} {}, found {}",
expected,
required_ty_param_count,
supplied_ty_param_count).as_slice());
Expand All @@ -227,7 +227,7 @@ fn ast_path_substs<AC:AstConv,RS:RegionScope>(
"expected"
};
this.tcx().sess.span_fatal(path.span,
format!("wrong number of type arguments: {} {} but found {}",
format!("wrong number of type arguments: {} {}, found {}",
expected,
formal_ty_param_count,
supplied_ty_param_count).as_slice());
Expand Down
16 changes: 8 additions & 8 deletions src/librustc/middle/typeck/check/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ pub fn check_pat_variant(pcx: &pat_ctxt, pat: &ast::Pat, path: &ast::Path,
fcx.infcx().type_error_message_str_with_expected(pat.span,
|expected, actual| {
expected.map_or("".to_string(), |e| {
format!("mismatched types: expected `{}` but found {}",
format!("mismatched types: expected `{}`, found {}",
e, actual)
})},
Some(expected),
Expand Down Expand Up @@ -223,7 +223,7 @@ pub fn check_pat_variant(pcx: &pat_ctxt, pat: &ast::Pat, path: &ast::Path,
|expected, actual| {
expected.map_or("".to_string(),
|e| {
format!("mismatched types: expected `{}` but found {}",
format!("mismatched types: expected `{}`, found {}",
e, actual)
})
},
Expand Down Expand Up @@ -395,7 +395,7 @@ pub fn check_struct_like_enum_variant_pat(pcx: &pat_ctxt,
Some(&def::DefTy(..)) => {
let name = pprust::path_to_string(path);
span_err!(tcx.sess, span, E0028,
"mismatched types: expected `{}` but found `{}`",
"mismatched types: expected `{}`, found `{}`",
fcx.infcx().ty_to_string(expected), name);
}
_ => {
Expand Down Expand Up @@ -548,7 +548,7 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) {
expected.map_or("".to_string(),
|e| {
format!("mismatched types: expected \
`{}` but found {}", e, actual)
`{}`, found {}", e, actual)
})},
Some(expected),
"a structure pattern".to_string(),
Expand Down Expand Up @@ -607,8 +607,8 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) {
|expected,
actual| {
expected.map_or("".to_string(), |e| {
format!("mismatched types: expected `{}` \
but found {}", e, actual)
format!("mismatched types: expected `{}`, \
found {}", e, actual)
}
)},
Some(expected),
Expand Down Expand Up @@ -645,7 +645,7 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) {
|expected, actual| {
expected.map_or("".to_string(),
|e| {
format!("mismatched types: expected `{}` but found {}",
format!("mismatched types: expected `{}`, found {}",
e, actual)
})
},
Expand Down Expand Up @@ -763,7 +763,7 @@ fn check_pointer_pat(pcx: &pat_ctxt,
span,
|expected, actual| {
expected.map_or("".to_string(), |e| {
format!("mismatched types: expected `{}` but found {}",
format!("mismatched types: expected `{}`, found {}",
e, actual)
})
},
Expand Down
Loading

0 comments on commit 9968ae2

Please sign in to comment.