Skip to content

Commit

Permalink
Add error codes to rustc_typeck
Browse files Browse the repository at this point in the history
  • Loading branch information
brson committed Jan 20, 2015
1 parent 953d6df commit 0c5225c
Show file tree
Hide file tree
Showing 15 changed files with 179 additions and 157 deletions.
84 changes: 36 additions & 48 deletions src/librustc_typeck/astconv.rs
Expand Up @@ -100,8 +100,7 @@ pub trait AstConv<'tcx> {
-> Ty<'tcx>
{
if ty::binds_late_bound_regions(self.tcx(), &poly_trait_ref) {
self.tcx().sess.span_err(
span,
span_err!(self.tcx().sess, span, E0212,
"cannot extract an associated type from a higher-ranked trait bound \
in this context");
self.tcx().types.err
Expand All @@ -119,8 +118,7 @@ pub trait AstConv<'tcx> {
_item_name: ast::Name)
-> Ty<'tcx>
{
self.tcx().sess.span_err(
span,
span_err!(self.tcx().sess, span, E0213,
"associated types are not accepted in this context");

self.tcx().types.err
Expand Down Expand Up @@ -268,8 +266,7 @@ pub fn ast_path_substs_for_ty<'tcx>(
convert_angle_bracketed_parameters(this, rscope, data)
}
ast::ParenthesizedParameters(ref data) => {
tcx.sess.span_err(
path.span,
span_err!(tcx.sess, path.span, E0214,
"parenthesized parameters may only be used with a trait");
(Vec::new(), convert_parenthesized_parameters(this, data), Vec::new())
}
Expand Down Expand Up @@ -610,7 +607,7 @@ fn ast_path_to_trait_ref<'a,'tcx>(
if !this.tcx().sess.features.borrow().unboxed_closures &&
this.tcx().lang_items.fn_trait_kind(trait_def_id).is_some()
{
this.tcx().sess.span_err(path.span,
span_err!(this.tcx().sess, path.span, E0215,
"angle-bracket notation is not stable when \
used with the `Fn` family of traits, use parentheses");
span_help!(this.tcx().sess, path.span,
Expand All @@ -626,7 +623,7 @@ fn ast_path_to_trait_ref<'a,'tcx>(
if !this.tcx().sess.features.borrow().unboxed_closures &&
this.tcx().lang_items.fn_trait_kind(trait_def_id).is_none()
{
this.tcx().sess.span_err(path.span,
span_err!(this.tcx().sess, path.span, E0216,
"parenthetical notation is only stable when \
used with the `Fn` family of traits");
span_help!(this.tcx().sess, path.span,
Expand Down Expand Up @@ -738,32 +735,29 @@ fn ast_type_binding_to_projection_predicate<'tcx>(
}

if candidates.len() > 1 {
tcx.sess.span_err(
binding.span,
format!("ambiguous associated type: `{}` defined in multiple supertraits `{}`",
span_err!(tcx.sess, binding.span, E0217,
"ambiguous associated type: `{}` defined in multiple supertraits `{}`",
token::get_name(binding.item_name),
candidates.user_string(tcx)).as_slice());
candidates.user_string(tcx));
return Err(ErrorReported);
}

let candidate = match candidates.pop() {
Some(c) => c,
None => {
tcx.sess.span_err(
binding.span,
format!("no associated type `{}` defined in `{}`",
span_err!(tcx.sess, binding.span, E0218,
"no associated type `{}` defined in `{}`",
token::get_name(binding.item_name),
trait_ref.user_string(tcx)).as_slice());
trait_ref.user_string(tcx));
return Err(ErrorReported);
}
};

if ty::binds_late_bound_regions(tcx, &candidate) {
tcx.sess.span_err(
binding.span,
format!("associated type `{}` defined in higher-ranked supertrait `{}`",
span_err!(tcx.sess, binding.span, E0219,
"associated type `{}` defined in higher-ranked supertrait `{}`",
token::get_name(binding.item_name),
candidate.user_string(tcx)).as_slice());
candidate.user_string(tcx));
return Err(ErrorReported);
}

Expand Down Expand Up @@ -964,18 +958,18 @@ fn associated_path_def_to_ty<'tcx>(this: &AstConv<'tcx>,
}

if suitable_bounds.len() == 0 {
tcx.sess.span_err(ast_ty.span,
format!("associated type `{}` not found for type parameter `{}`",
span_err!(tcx.sess, ast_ty.span, E0220,
"associated type `{}` not found for type parameter `{}`",
token::get_name(assoc_name),
token::get_name(ty_param_name)).as_slice());
token::get_name(ty_param_name));
return this.tcx().types.err;
}

if suitable_bounds.len() > 1 {
tcx.sess.span_err(ast_ty.span,
format!("ambiguous associated type `{}` in bounds of `{}`",
span_err!(tcx.sess, ast_ty.span, E0221,
"ambiguous associated type `{}` in bounds of `{}`",
token::get_name(assoc_name),
token::get_name(ty_param_name)).as_slice());
token::get_name(ty_param_name));

for suitable_bound in suitable_bounds.iter() {
span_note!(this.tcx().sess, ast_ty.span,
Expand Down Expand Up @@ -1093,7 +1087,7 @@ pub fn ast_ty_to_ty<'tcx>(
ast::TyParen(ref typ) => ast_ty_to_ty(this, rscope, &**typ),
ast::TyBareFn(ref bf) => {
if bf.decl.variadic && bf.abi != abi::C {
tcx.sess.span_err(ast_ty.span,
span_err!(tcx.sess, ast_ty.span, E0222,
"variadic function must have C calling convention");
}
let bare_fn = ty_of_bare_fn(this, bf.unsafety, bf.abi, &*bf.decl);
Expand Down Expand Up @@ -1152,8 +1146,8 @@ pub fn ast_ty_to_ty<'tcx>(
def::DefAssociatedTy(trait_type_id) => {
let path_str = tcx.map.path_to_string(
tcx.map.get_parent(trait_type_id.node));
tcx.sess.span_err(ast_ty.span,
&format!("ambiguous associated \
span_err!(tcx.sess, ast_ty.span, E0223,
"ambiguous associated \
type; specify the type \
using the syntax `<Type \
as {}>::{}`",
Expand All @@ -1163,7 +1157,7 @@ pub fn ast_ty_to_ty<'tcx>(
.last()
.unwrap()
.identifier)
.get())[]);
.get());
this.tcx().types.err
}
def::DefAssociatedPath(provenance, assoc_ident) => {
Expand Down Expand Up @@ -1557,8 +1551,7 @@ fn conv_ty_poly_trait_ref<'tcx>(
None,
&mut projection_bounds))
} else {
this.tcx().sess.span_err(
span,
span_err!(this.tcx().sess, span, E0224,
"at least one non-builtin trait is required for an object type");
None
};
Expand Down Expand Up @@ -1593,10 +1586,9 @@ pub fn conv_existential_bounds_from_partitioned_bounds<'tcx>(

if !trait_bounds.is_empty() {
let b = &trait_bounds[0];
this.tcx().sess.span_err(
b.trait_ref.path.span,
&format!("only the builtin traits can be used \
as closure or object bounds")[]);
span_err!(this.tcx().sess, b.trait_ref.path.span, E0225,
"only the builtin traits can be used \
as closure or object bounds");
}

let region_bound = compute_region_bound(this,
Expand Down Expand Up @@ -1633,9 +1625,8 @@ fn compute_opt_region_bound<'tcx>(tcx: &ty::ctxt<'tcx>,
builtin_bounds.repr(tcx));

if explicit_region_bounds.len() > 1 {
tcx.sess.span_err(
explicit_region_bounds[1].span,
format!("only a single explicit lifetime bound is permitted").as_slice());
span_err!(tcx.sess, explicit_region_bounds[1].span, E0226,
"only a single explicit lifetime bound is permitted");
}

if explicit_region_bounds.len() != 0 {
Expand Down Expand Up @@ -1666,10 +1657,9 @@ fn compute_opt_region_bound<'tcx>(tcx: &ty::ctxt<'tcx>,
// error.
let r = derived_region_bounds[0];
if derived_region_bounds.slice_from(1).iter().any(|r1| r != *r1) {
tcx.sess.span_err(
span,
&format!("ambiguous lifetime bound, \
explicit lifetime bound required")[]);
span_err!(tcx.sess, span, E0227,
"ambiguous lifetime bound, \
explicit lifetime bound required");
}
return Some(r);
}
Expand All @@ -1693,9 +1683,8 @@ fn compute_region_bound<'tcx>(
match rscope.default_region_bound(span) {
Some(r) => { r }
None => {
this.tcx().sess.span_err(
span,
&format!("explicit lifetime bound required")[]);
span_err!(this.tcx().sess, span, E0228,
"explicit lifetime bound required");
ty::ReStatic
}
}
Expand Down Expand Up @@ -1779,8 +1768,7 @@ fn prohibit_projections<'tcx>(tcx: &ty::ctxt<'tcx>,
bindings: &[ConvertedBinding<'tcx>])
{
for binding in bindings.iter().take(1) {
tcx.sess.span_err(
binding.span,
span_err!(tcx.sess, binding.span, E0229,
"associated type bindings are not allowed here");
}
}
5 changes: 2 additions & 3 deletions src/librustc_typeck/check/closure.rs
Expand Up @@ -50,10 +50,9 @@ pub fn check_expr_closure<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,

check_unboxed_closure(fcx, expr, kind, decl, body, None);

fcx.ccx.tcx.sess.span_err(
expr.span,
span_err!(fcx.ccx.tcx.sess, expr.span, E0187,
"can't infer the \"kind\" of the closure, explicitly annotate it. e.g. \
`|&:| {}`");
`|&:| {{}}`");
},
Some((sig, kind)) => {
check_unboxed_closure(fcx, expr, kind, decl, body, Some(sig));
Expand Down
21 changes: 9 additions & 12 deletions src/librustc_typeck/check/compare_method.rs
Expand Up @@ -59,23 +59,21 @@ pub fn compare_impl_method<'tcx>(tcx: &ty::ctxt<'tcx>,
(&ty::StaticExplicitSelfCategory,
&ty::StaticExplicitSelfCategory) => {}
(&ty::StaticExplicitSelfCategory, _) => {
tcx.sess.span_err(
impl_m_span,
format!("method `{}` has a `{}` declaration in the impl, \
span_err!(tcx.sess, impl_m_span, E0185,
"method `{}` has a `{}` declaration in the impl, \
but not in the trait",
token::get_name(trait_m.name),
ppaux::explicit_self_category_to_str(
&impl_m.explicit_self)).as_slice());
&impl_m.explicit_self));
return;
}
(_, &ty::StaticExplicitSelfCategory) => {
tcx.sess.span_err(
impl_m_span,
format!("method `{}` has a `{}` declaration in the trait, \
span_err!(tcx.sess, impl_m_span, E0186,
"method `{}` has a `{}` declaration in the trait, \
but not in the impl",
token::get_name(trait_m.name),
ppaux::explicit_self_category_to_str(
&trait_m.explicit_self)).as_slice());
&trait_m.explicit_self));
return;
}
_ => {
Expand Down Expand Up @@ -400,11 +398,10 @@ pub fn compare_impl_method<'tcx>(tcx: &ty::ctxt<'tcx>,
// are zero. Since I don't quite know how to phrase things at
// the moment, give a kind of vague error message.
if trait_params.len() != impl_params.len() {
tcx.sess.span_err(
span,
&format!("lifetime parameters or bounds on method `{}` do \
span_err!(tcx.sess, span, E0195,
"lifetime parameters or bounds on method `{}` do \
not match the trait declaration",
token::get_name(impl_m.name))[]);
token::get_name(impl_m.name));
return false;
}

Expand Down
44 changes: 19 additions & 25 deletions src/librustc_typeck/check/mod.rs
Expand Up @@ -801,24 +801,23 @@ fn check_trait_on_unimplemented<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
}) {
Some(_) => (),
None => {
ccx.tcx.sess.span_err(attr.span,
format!("there is no type parameter \
span_err!(ccx.tcx.sess, attr.span, E0230,
"there is no type parameter \
{} on trait {}",
s, item.ident.as_str())
.as_slice());
s, item.ident.as_str());
}
},
// `{:1}` and `{}` are not to be used
Position::ArgumentIs(_) | Position::ArgumentNext => {
ccx.tcx.sess.span_err(attr.span,
span_err!(ccx.tcx.sess, attr.span, E0231,
"only named substitution \
parameters are allowed");
}
}
}
}
} else {
ccx.tcx.sess.span_err(attr.span,
span_err!(ccx.tcx.sess, attr.span, E0232,
"this attribute must have a value, \
eg `#[rustc_on_unimplemented = \"foo\"]`")
}
Expand Down Expand Up @@ -2099,8 +2098,8 @@ fn lookup_method_for_for_loop<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
let trait_did = match fcx.tcx().lang_items.require(IteratorItem) {
Ok(trait_did) => trait_did,
Err(ref err_string) => {
fcx.tcx().sess.span_err(iterator_expr.span,
&err_string[]);
span_err!(fcx.tcx().sess, iterator_expr.span, E0233,
"{}", &err_string[]);
return fcx.tcx().types.err
}
};
Expand All @@ -2123,11 +2122,10 @@ fn lookup_method_for_for_loop<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,

if !ty::type_is_error(true_expr_type) {
let ty_string = fcx.infcx().ty_to_string(true_expr_type);
fcx.tcx().sess.span_err(iterator_expr.span,
&format!("`for` loop expression has type `{}` which does \
span_err!(fcx.tcx().sess, iterator_expr.span, E0234,
"`for` loop expression has type `{}` which does \
not implement the `Iterator` trait; \
maybe try .iter()",
ty_string)[]);
maybe try .iter()", ty_string);
}
fcx.tcx().types.err
}
Expand Down Expand Up @@ -2162,11 +2160,10 @@ fn lookup_method_for_for_loop<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
fcx.tcx().types.err
}
_ => {
fcx.tcx().sess.span_err(iterator_expr.span,
&format!("`next` method of the `Iterator` \
span_err!(fcx.tcx().sess, iterator_expr.span, E0239,
"`next` method of the `Iterator` \
trait has an unexpected type `{}`",
fcx.infcx().ty_to_string(return_type))
[]);
fcx.infcx().ty_to_string(return_type));
fcx.tcx().types.err
}
}
Expand Down Expand Up @@ -3880,18 +3877,16 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
Err(type_error) => {
let type_error_description =
ty::type_err_to_str(tcx, &type_error);
fcx.tcx()
.sess
.span_err(path.span,
&format!("structure constructor specifies a \
span_err!(fcx.tcx().sess, path.span, E0235,
"structure constructor specifies a \
structure of type `{}`, but this \
structure has type `{}`: {}",
fcx.infcx()
.ty_to_string(type_and_substs.ty),
fcx.infcx()
.ty_to_string(
actual_structure_type),
type_error_description)[]);
type_error_description);
ty::note_and_explain_type_err(tcx, &type_error);
}
}
Expand Down Expand Up @@ -4012,7 +4007,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,

ty::mk_struct(tcx, did, tcx.mk_substs(substs))
} else {
tcx.sess.span_err(expr.span, "No lang item for range syntax");
span_err!(tcx.sess, expr.span, E0236, "no lang item for range syntax");
fcx.tcx().types.err
}
}
Expand All @@ -4022,7 +4017,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
let substs = Substs::new_type(vec![], vec![]);
ty::mk_struct(tcx, did, tcx.mk_substs(substs))
} else {
tcx.sess.span_err(expr.span, "No lang item for range syntax");
span_err!(tcx.sess, expr.span, E0237, "no lang item for range syntax");
fcx.tcx().types.err
}
}
Expand Down Expand Up @@ -4872,8 +4867,7 @@ pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
}

ast::ParenthesizedParameters(ref data) => {
fcx.tcx().sess.span_err(
span,
span_err!(fcx.tcx().sess, span, E0238,
"parenthesized parameters may only be used with a trait");
push_explicit_parenthesized_parameters_from_segment_to_substs(
fcx, space, span, type_defs, data, substs);
Expand Down

0 comments on commit 0c5225c

Please sign in to comment.