Add error codes to rustc_typeck

This commit is contained in:
Brian Anderson 2015-01-17 13:36:59 -08:00
parent 953d6dfd7e
commit 0c5225c5bf
15 changed files with 179 additions and 157 deletions

View File

@ -100,8 +100,7 @@ pub trait AstConv<'tcx> {
-> Ty<'tcx> -> Ty<'tcx>
{ {
if ty::binds_late_bound_regions(self.tcx(), &poly_trait_ref) { if ty::binds_late_bound_regions(self.tcx(), &poly_trait_ref) {
self.tcx().sess.span_err( span_err!(self.tcx().sess, span, E0212,
span,
"cannot extract an associated type from a higher-ranked trait bound \ "cannot extract an associated type from a higher-ranked trait bound \
in this context"); in this context");
self.tcx().types.err self.tcx().types.err
@ -119,8 +118,7 @@ pub trait AstConv<'tcx> {
_item_name: ast::Name) _item_name: ast::Name)
-> Ty<'tcx> -> Ty<'tcx>
{ {
self.tcx().sess.span_err( span_err!(self.tcx().sess, span, E0213,
span,
"associated types are not accepted in this context"); "associated types are not accepted in this context");
self.tcx().types.err self.tcx().types.err
@ -268,8 +266,7 @@ pub fn ast_path_substs_for_ty<'tcx>(
convert_angle_bracketed_parameters(this, rscope, data) convert_angle_bracketed_parameters(this, rscope, data)
} }
ast::ParenthesizedParameters(ref data) => { ast::ParenthesizedParameters(ref data) => {
tcx.sess.span_err( span_err!(tcx.sess, path.span, E0214,
path.span,
"parenthesized parameters may only be used with a trait"); "parenthesized parameters may only be used with a trait");
(Vec::new(), convert_parenthesized_parameters(this, data), Vec::new()) (Vec::new(), convert_parenthesized_parameters(this, data), Vec::new())
} }
@ -610,7 +607,7 @@ fn ast_path_to_trait_ref<'a,'tcx>(
if !this.tcx().sess.features.borrow().unboxed_closures && if !this.tcx().sess.features.borrow().unboxed_closures &&
this.tcx().lang_items.fn_trait_kind(trait_def_id).is_some() 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 \ "angle-bracket notation is not stable when \
used with the `Fn` family of traits, use parentheses"); used with the `Fn` family of traits, use parentheses");
span_help!(this.tcx().sess, path.span, span_help!(this.tcx().sess, path.span,
@ -626,7 +623,7 @@ fn ast_path_to_trait_ref<'a,'tcx>(
if !this.tcx().sess.features.borrow().unboxed_closures && if !this.tcx().sess.features.borrow().unboxed_closures &&
this.tcx().lang_items.fn_trait_kind(trait_def_id).is_none() 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 \ "parenthetical notation is only stable when \
used with the `Fn` family of traits"); used with the `Fn` family of traits");
span_help!(this.tcx().sess, path.span, span_help!(this.tcx().sess, path.span,
@ -738,32 +735,29 @@ fn ast_type_binding_to_projection_predicate<'tcx>(
} }
if candidates.len() > 1 { if candidates.len() > 1 {
tcx.sess.span_err( span_err!(tcx.sess, binding.span, E0217,
binding.span, "ambiguous associated type: `{}` defined in multiple supertraits `{}`",
format!("ambiguous associated type: `{}` defined in multiple supertraits `{}`",
token::get_name(binding.item_name), token::get_name(binding.item_name),
candidates.user_string(tcx)).as_slice()); candidates.user_string(tcx));
return Err(ErrorReported); return Err(ErrorReported);
} }
let candidate = match candidates.pop() { let candidate = match candidates.pop() {
Some(c) => c, Some(c) => c,
None => { None => {
tcx.sess.span_err( span_err!(tcx.sess, binding.span, E0218,
binding.span, "no associated type `{}` defined in `{}`",
format!("no associated type `{}` defined in `{}`",
token::get_name(binding.item_name), token::get_name(binding.item_name),
trait_ref.user_string(tcx)).as_slice()); trait_ref.user_string(tcx));
return Err(ErrorReported); return Err(ErrorReported);
} }
}; };
if ty::binds_late_bound_regions(tcx, &candidate) { if ty::binds_late_bound_regions(tcx, &candidate) {
tcx.sess.span_err( span_err!(tcx.sess, binding.span, E0219,
binding.span, "associated type `{}` defined in higher-ranked supertrait `{}`",
format!("associated type `{}` defined in higher-ranked supertrait `{}`",
token::get_name(binding.item_name), token::get_name(binding.item_name),
candidate.user_string(tcx)).as_slice()); candidate.user_string(tcx));
return Err(ErrorReported); return Err(ErrorReported);
} }
@ -964,18 +958,18 @@ fn associated_path_def_to_ty<'tcx>(this: &AstConv<'tcx>,
} }
if suitable_bounds.len() == 0 { if suitable_bounds.len() == 0 {
tcx.sess.span_err(ast_ty.span, span_err!(tcx.sess, ast_ty.span, E0220,
format!("associated type `{}` not found for type parameter `{}`", "associated type `{}` not found for type parameter `{}`",
token::get_name(assoc_name), token::get_name(assoc_name),
token::get_name(ty_param_name)).as_slice()); token::get_name(ty_param_name));
return this.tcx().types.err; return this.tcx().types.err;
} }
if suitable_bounds.len() > 1 { if suitable_bounds.len() > 1 {
tcx.sess.span_err(ast_ty.span, span_err!(tcx.sess, ast_ty.span, E0221,
format!("ambiguous associated type `{}` in bounds of `{}`", "ambiguous associated type `{}` in bounds of `{}`",
token::get_name(assoc_name), 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() { for suitable_bound in suitable_bounds.iter() {
span_note!(this.tcx().sess, ast_ty.span, span_note!(this.tcx().sess, ast_ty.span,
@ -1093,7 +1087,7 @@ pub fn ast_ty_to_ty<'tcx>(
ast::TyParen(ref typ) => ast_ty_to_ty(this, rscope, &**typ), ast::TyParen(ref typ) => ast_ty_to_ty(this, rscope, &**typ),
ast::TyBareFn(ref bf) => { ast::TyBareFn(ref bf) => {
if bf.decl.variadic && bf.abi != abi::C { 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"); "variadic function must have C calling convention");
} }
let bare_fn = ty_of_bare_fn(this, bf.unsafety, bf.abi, &*bf.decl); let bare_fn = ty_of_bare_fn(this, bf.unsafety, bf.abi, &*bf.decl);
@ -1152,8 +1146,8 @@ pub fn ast_ty_to_ty<'tcx>(
def::DefAssociatedTy(trait_type_id) => { def::DefAssociatedTy(trait_type_id) => {
let path_str = tcx.map.path_to_string( let path_str = tcx.map.path_to_string(
tcx.map.get_parent(trait_type_id.node)); tcx.map.get_parent(trait_type_id.node));
tcx.sess.span_err(ast_ty.span, span_err!(tcx.sess, ast_ty.span, E0223,
&format!("ambiguous associated \ "ambiguous associated \
type; specify the type \ type; specify the type \
using the syntax `<Type \ using the syntax `<Type \
as {}>::{}`", as {}>::{}`",
@ -1163,7 +1157,7 @@ pub fn ast_ty_to_ty<'tcx>(
.last() .last()
.unwrap() .unwrap()
.identifier) .identifier)
.get())[]); .get());
this.tcx().types.err this.tcx().types.err
} }
def::DefAssociatedPath(provenance, assoc_ident) => { def::DefAssociatedPath(provenance, assoc_ident) => {
@ -1557,8 +1551,7 @@ fn conv_ty_poly_trait_ref<'tcx>(
None, None,
&mut projection_bounds)) &mut projection_bounds))
} else { } else {
this.tcx().sess.span_err( span_err!(this.tcx().sess, span, E0224,
span,
"at least one non-builtin trait is required for an object type"); "at least one non-builtin trait is required for an object type");
None None
}; };
@ -1593,10 +1586,9 @@ pub fn conv_existential_bounds_from_partitioned_bounds<'tcx>(
if !trait_bounds.is_empty() { if !trait_bounds.is_empty() {
let b = &trait_bounds[0]; let b = &trait_bounds[0];
this.tcx().sess.span_err( span_err!(this.tcx().sess, b.trait_ref.path.span, E0225,
b.trait_ref.path.span, "only the builtin traits can be used \
&format!("only the builtin traits can be used \ as closure or object bounds");
as closure or object bounds")[]);
} }
let region_bound = compute_region_bound(this, let region_bound = compute_region_bound(this,
@ -1633,9 +1625,8 @@ fn compute_opt_region_bound<'tcx>(tcx: &ty::ctxt<'tcx>,
builtin_bounds.repr(tcx)); builtin_bounds.repr(tcx));
if explicit_region_bounds.len() > 1 { if explicit_region_bounds.len() > 1 {
tcx.sess.span_err( span_err!(tcx.sess, explicit_region_bounds[1].span, E0226,
explicit_region_bounds[1].span, "only a single explicit lifetime bound is permitted");
format!("only a single explicit lifetime bound is permitted").as_slice());
} }
if explicit_region_bounds.len() != 0 { if explicit_region_bounds.len() != 0 {
@ -1666,10 +1657,9 @@ fn compute_opt_region_bound<'tcx>(tcx: &ty::ctxt<'tcx>,
// error. // error.
let r = derived_region_bounds[0]; let r = derived_region_bounds[0];
if derived_region_bounds.slice_from(1).iter().any(|r1| r != *r1) { if derived_region_bounds.slice_from(1).iter().any(|r1| r != *r1) {
tcx.sess.span_err( span_err!(tcx.sess, span, E0227,
span, "ambiguous lifetime bound, \
&format!("ambiguous lifetime bound, \ explicit lifetime bound required");
explicit lifetime bound required")[]);
} }
return Some(r); return Some(r);
} }
@ -1693,9 +1683,8 @@ fn compute_region_bound<'tcx>(
match rscope.default_region_bound(span) { match rscope.default_region_bound(span) {
Some(r) => { r } Some(r) => { r }
None => { None => {
this.tcx().sess.span_err( span_err!(this.tcx().sess, span, E0228,
span, "explicit lifetime bound required");
&format!("explicit lifetime bound required")[]);
ty::ReStatic ty::ReStatic
} }
} }
@ -1779,8 +1768,7 @@ fn prohibit_projections<'tcx>(tcx: &ty::ctxt<'tcx>,
bindings: &[ConvertedBinding<'tcx>]) bindings: &[ConvertedBinding<'tcx>])
{ {
for binding in bindings.iter().take(1) { for binding in bindings.iter().take(1) {
tcx.sess.span_err( span_err!(tcx.sess, binding.span, E0229,
binding.span,
"associated type bindings are not allowed here"); "associated type bindings are not allowed here");
} }
} }

View File

@ -50,10 +50,9 @@ pub fn check_expr_closure<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
check_unboxed_closure(fcx, expr, kind, decl, body, None); check_unboxed_closure(fcx, expr, kind, decl, body, None);
fcx.ccx.tcx.sess.span_err( span_err!(fcx.ccx.tcx.sess, expr.span, E0187,
expr.span,
"can't infer the \"kind\" of the closure, explicitly annotate it. e.g. \ "can't infer the \"kind\" of the closure, explicitly annotate it. e.g. \
`|&:| {}`"); `|&:| {{}}`");
}, },
Some((sig, kind)) => { Some((sig, kind)) => {
check_unboxed_closure(fcx, expr, kind, decl, body, Some(sig)); check_unboxed_closure(fcx, expr, kind, decl, body, Some(sig));

View File

@ -59,23 +59,21 @@ pub fn compare_impl_method<'tcx>(tcx: &ty::ctxt<'tcx>,
(&ty::StaticExplicitSelfCategory, (&ty::StaticExplicitSelfCategory,
&ty::StaticExplicitSelfCategory) => {} &ty::StaticExplicitSelfCategory) => {}
(&ty::StaticExplicitSelfCategory, _) => { (&ty::StaticExplicitSelfCategory, _) => {
tcx.sess.span_err( span_err!(tcx.sess, impl_m_span, E0185,
impl_m_span, "method `{}` has a `{}` declaration in the impl, \
format!("method `{}` has a `{}` declaration in the impl, \
but not in the trait", but not in the trait",
token::get_name(trait_m.name), token::get_name(trait_m.name),
ppaux::explicit_self_category_to_str( ppaux::explicit_self_category_to_str(
&impl_m.explicit_self)).as_slice()); &impl_m.explicit_self));
return; return;
} }
(_, &ty::StaticExplicitSelfCategory) => { (_, &ty::StaticExplicitSelfCategory) => {
tcx.sess.span_err( span_err!(tcx.sess, impl_m_span, E0186,
impl_m_span, "method `{}` has a `{}` declaration in the trait, \
format!("method `{}` has a `{}` declaration in the trait, \
but not in the impl", but not in the impl",
token::get_name(trait_m.name), token::get_name(trait_m.name),
ppaux::explicit_self_category_to_str( ppaux::explicit_self_category_to_str(
&trait_m.explicit_self)).as_slice()); &trait_m.explicit_self));
return; return;
} }
_ => { _ => {
@ -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 // are zero. Since I don't quite know how to phrase things at
// the moment, give a kind of vague error message. // the moment, give a kind of vague error message.
if trait_params.len() != impl_params.len() { if trait_params.len() != impl_params.len() {
tcx.sess.span_err( span_err!(tcx.sess, span, E0195,
span, "lifetime parameters or bounds on method `{}` do \
&format!("lifetime parameters or bounds on method `{}` do \
not match the trait declaration", not match the trait declaration",
token::get_name(impl_m.name))[]); token::get_name(impl_m.name));
return false; return false;
} }

View File

@ -801,16 +801,15 @@ fn check_trait_on_unimplemented<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
}) { }) {
Some(_) => (), Some(_) => (),
None => { None => {
ccx.tcx.sess.span_err(attr.span, span_err!(ccx.tcx.sess, attr.span, E0230,
format!("there is no type parameter \ "there is no type parameter \
{} on trait {}", {} on trait {}",
s, item.ident.as_str()) s, item.ident.as_str());
.as_slice());
} }
}, },
// `{:1}` and `{}` are not to be used // `{:1}` and `{}` are not to be used
Position::ArgumentIs(_) | Position::ArgumentNext => { Position::ArgumentIs(_) | Position::ArgumentNext => {
ccx.tcx.sess.span_err(attr.span, span_err!(ccx.tcx.sess, attr.span, E0231,
"only named substitution \ "only named substitution \
parameters are allowed"); parameters are allowed");
} }
@ -818,7 +817,7 @@ fn check_trait_on_unimplemented<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
} }
} }
} else { } else {
ccx.tcx.sess.span_err(attr.span, span_err!(ccx.tcx.sess, attr.span, E0232,
"this attribute must have a value, \ "this attribute must have a value, \
eg `#[rustc_on_unimplemented = \"foo\"]`") eg `#[rustc_on_unimplemented = \"foo\"]`")
} }
@ -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) { let trait_did = match fcx.tcx().lang_items.require(IteratorItem) {
Ok(trait_did) => trait_did, Ok(trait_did) => trait_did,
Err(ref err_string) => { Err(ref err_string) => {
fcx.tcx().sess.span_err(iterator_expr.span, span_err!(fcx.tcx().sess, iterator_expr.span, E0233,
&err_string[]); "{}", &err_string[]);
return fcx.tcx().types.err return fcx.tcx().types.err
} }
}; };
@ -2123,11 +2122,10 @@ fn lookup_method_for_for_loop<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
if !ty::type_is_error(true_expr_type) { if !ty::type_is_error(true_expr_type) {
let ty_string = fcx.infcx().ty_to_string(true_expr_type); let ty_string = fcx.infcx().ty_to_string(true_expr_type);
fcx.tcx().sess.span_err(iterator_expr.span, span_err!(fcx.tcx().sess, iterator_expr.span, E0234,
&format!("`for` loop expression has type `{}` which does \ "`for` loop expression has type `{}` which does \
not implement the `Iterator` trait; \ not implement the `Iterator` trait; \
maybe try .iter()", maybe try .iter()", ty_string);
ty_string)[]);
} }
fcx.tcx().types.err fcx.tcx().types.err
} }
@ -2162,11 +2160,10 @@ fn lookup_method_for_for_loop<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
fcx.tcx().types.err fcx.tcx().types.err
} }
_ => { _ => {
fcx.tcx().sess.span_err(iterator_expr.span, span_err!(fcx.tcx().sess, iterator_expr.span, E0239,
&format!("`next` method of the `Iterator` \ "`next` method of the `Iterator` \
trait has an unexpected type `{}`", trait has an unexpected type `{}`",
fcx.infcx().ty_to_string(return_type)) fcx.infcx().ty_to_string(return_type));
[]);
fcx.tcx().types.err fcx.tcx().types.err
} }
} }
@ -3880,10 +3877,8 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
Err(type_error) => { Err(type_error) => {
let type_error_description = let type_error_description =
ty::type_err_to_str(tcx, &type_error); ty::type_err_to_str(tcx, &type_error);
fcx.tcx() span_err!(fcx.tcx().sess, path.span, E0235,
.sess "structure constructor specifies a \
.span_err(path.span,
&format!("structure constructor specifies a \
structure of type `{}`, but this \ structure of type `{}`, but this \
structure has type `{}`: {}", structure has type `{}`: {}",
fcx.infcx() fcx.infcx()
@ -3891,7 +3886,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
fcx.infcx() fcx.infcx()
.ty_to_string( .ty_to_string(
actual_structure_type), actual_structure_type),
type_error_description)[]); type_error_description);
ty::note_and_explain_type_err(tcx, &type_error); ty::note_and_explain_type_err(tcx, &type_error);
} }
} }
@ -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)) ty::mk_struct(tcx, did, tcx.mk_substs(substs))
} else { } 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 fcx.tcx().types.err
} }
} }
@ -4022,7 +4017,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
let substs = Substs::new_type(vec![], vec![]); let substs = Substs::new_type(vec![], vec![]);
ty::mk_struct(tcx, did, tcx.mk_substs(substs)) ty::mk_struct(tcx, did, tcx.mk_substs(substs))
} else { } 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 fcx.tcx().types.err
} }
} }
@ -4872,8 +4867,7 @@ pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
} }
ast::ParenthesizedParameters(ref data) => { ast::ParenthesizedParameters(ref data) => {
fcx.tcx().sess.span_err( span_err!(fcx.tcx().sess, span, E0238,
span,
"parenthesized parameters may only be used with a trait"); "parenthesized parameters may only be used with a trait");
push_explicit_parenthesized_parameters_from_segment_to_substs( push_explicit_parenthesized_parameters_from_segment_to_substs(
fcx, space, span, type_defs, data, substs); fcx, space, span, type_defs, data, substs);

View File

@ -51,7 +51,7 @@ pub fn check_object_cast<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
{ {
let object_trait = object_trait(&object_trait_ty); let object_trait = object_trait(&object_trait_ty);
if !mutability_allowed(referent_mutbl, target_mutbl) { if !mutability_allowed(referent_mutbl, target_mutbl) {
fcx.tcx().sess.span_err(source_expr.span, span_err!(fcx.tcx().sess, source_expr.span, E0188,
"types differ in mutability"); "types differ in mutability");
} else { } else {
// Ensure that if &'a T is cast to &'b Trait, then T : Trait // Ensure that if &'a T is cast to &'b Trait, then T : Trait
@ -70,19 +70,17 @@ pub fn check_object_cast<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
} }
(_, &ty::ty_uniq(..)) => { (_, &ty::ty_uniq(..)) => {
fcx.ccx.tcx.sess.span_err( span_err!(fcx.ccx.tcx.sess, source_expr.span, E0189,
source_expr.span, "can only cast a boxed pointer \
&format!("can only cast an boxed pointer \
to a boxed object, not a {}", to a boxed object, not a {}",
ty::ty_sort_string(fcx.tcx(), source_ty))[]); ty::ty_sort_string(fcx.tcx(), source_ty));
} }
(_, &ty::ty_rptr(..)) => { (_, &ty::ty_rptr(..)) => {
fcx.ccx.tcx.sess.span_err( span_err!(fcx.ccx.tcx.sess, source_expr.span, E0190,
source_expr.span, "can only cast a &-pointer \
&format!("can only cast a &-pointer \
to an &-object, not a {}", to an &-object, not a {}",
ty::ty_sort_string(fcx.tcx(), source_ty))[]); ty::ty_sort_string(fcx.tcx(), source_ty));
} }
_ => { _ => {
@ -272,11 +270,10 @@ fn check_object_type_binds_all_associated_types<'tcx>(tcx: &ty::ctxt<'tcx>,
} }
for (trait_def_id, name) in associated_types.into_iter() { for (trait_def_id, name) in associated_types.into_iter() {
tcx.sess.span_err( span_err!(tcx.sess, span, E0191,
span, "the value of the associated type `{}` (from the trait `{}`) must be specified",
format!("the value of the associated type `{}` (from the trait `{}`) must be specified",
name.user_string(tcx), name.user_string(tcx),
ty::item_path_str(tcx, trait_def_id)).as_slice()); ty::item_path_str(tcx, trait_def_id));
} }
} }

View File

@ -81,10 +81,9 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
match ccx.tcx.lang_items.to_builtin_kind(trait_ref.def_id) { match ccx.tcx.lang_items.to_builtin_kind(trait_ref.def_id) {
Some(ty::BoundSend) | Some(ty::BoundSync) => {} Some(ty::BoundSend) | Some(ty::BoundSync) => {}
Some(_) | None => { Some(_) | None => {
ccx.tcx.sess.span_err( span_err!(ccx.tcx.sess, item.span, E0192,
item.span, "negative impls are currently \
format!("negative impls are currently \ allowed just for `Send` and `Sync`")
allowed just for `Send` and `Sync`").as_slice())
} }
} }
} }
@ -302,12 +301,11 @@ fn reject_non_type_param_bounds<'tcx>(tcx: &ty::ctxt<'tcx>,
fn report_bound_error<'t>(tcx: &ty::ctxt<'t>, fn report_bound_error<'t>(tcx: &ty::ctxt<'t>,
span: Span, span: Span,
bounded_ty: ty::Ty<'t>) { bounded_ty: ty::Ty<'t>) {
tcx.sess.span_err( span_err!(tcx.sess, span, E0193,
span, "cannot bound type `{}`, where clause \
format!("cannot bound type `{}`, where clause \
bounds may only be attached to types involving \ bounds may only be attached to types involving \
type parameters", type parameters",
bounded_ty.repr(tcx)).as_slice()) bounded_ty.repr(tcx))
} }
fn is_ty_param(ty: ty::Ty) -> bool { fn is_ty_param(ty: ty::Ty) -> bool {
@ -326,10 +324,9 @@ fn reject_shadowing_type_parameters<'tcx>(tcx: &ty::ctxt<'tcx>,
for method_param in generics.types.get_slice(subst::FnSpace).iter() { for method_param in generics.types.get_slice(subst::FnSpace).iter() {
if impl_params.contains(&method_param.name) { if impl_params.contains(&method_param.name) {
tcx.sess.span_err( span_err!(tcx.sess, span, E0194,
span, "type parameter `{}` shadows another type parameter of the same name",
&*format!("type parameter `{}` shadows another type parameter of the same name", token::get_name(method_param.name));
token::get_name(method_param.name)));
} }
} }
} }

View File

@ -416,7 +416,7 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
ResolvingUnboxedClosure(_) => { ResolvingUnboxedClosure(_) => {
let span = self.reason.span(self.tcx); let span = self.reason.span(self.tcx);
self.tcx.sess.span_err(span, span_err!(self.tcx.sess, span, E0196,
"cannot determine a type for this \ "cannot determine a type for this \
unboxed closure") unboxed closure")
} }

View File

@ -34,10 +34,9 @@ impl<'cx, 'tcx,'v> visit::Visitor<'v> for ImplsChecker<'cx, 'tcx> {
match trait_ref.self_ty().sty { match trait_ref.self_ty().sty {
ty::ty_struct(..) | ty::ty_enum(..) => {} ty::ty_struct(..) | ty::ty_enum(..) => {}
_ => { _ => {
self.tcx.sess.span_err( span_err!(self.tcx.sess, item.span, E0209,
item.span, "builtin traits can only be \
&format!("builtin traits can only be \ implemented on structs or enums");
implemented on structs or enums")[]);
} }
} }
} }

View File

@ -490,24 +490,21 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
match ty::can_type_implement_copy(&param_env, span, self_type) { match ty::can_type_implement_copy(&param_env, span, self_type) {
Ok(()) => {} Ok(()) => {}
Err(ty::FieldDoesNotImplementCopy(name)) => { Err(ty::FieldDoesNotImplementCopy(name)) => {
tcx.sess span_err!(tcx.sess, span, E0204,
.span_err(span, "the trait `Copy` may not be \
&format!("the trait `Copy` may not be \
implemented for this type; field \ implemented for this type; field \
`{}` does not implement `Copy`", `{}` does not implement `Copy`",
token::get_name(name))[]) token::get_name(name))
} }
Err(ty::VariantDoesNotImplementCopy(name)) => { Err(ty::VariantDoesNotImplementCopy(name)) => {
tcx.sess span_err!(tcx.sess, span, E0205,
.span_err(span, "the trait `Copy` may not be \
&format!("the trait `Copy` may not be \
implemented for this type; variant \ implemented for this type; variant \
`{}` does not implement `Copy`", `{}` does not implement `Copy`",
token::get_name(name))[]) token::get_name(name))
} }
Err(ty::TypeIsStructural) => { Err(ty::TypeIsStructural) => {
tcx.sess span_err!(tcx.sess, span, E0206,
.span_err(span,
"the trait `Copy` may not be implemented \ "the trait `Copy` may not be implemented \
for this type; type is not a structure or \ for this type; type is not a structure or \
enumeration") enumeration")

View File

@ -89,13 +89,11 @@ impl<'cx, 'tcx,'v> visit::Visitor<'v> for OrphanChecker<'cx, 'tcx> {
} }
Err(traits::OrphanCheckErr::UncoveredTy(param_ty)) => { Err(traits::OrphanCheckErr::UncoveredTy(param_ty)) => {
if !ty::has_attr(self.tcx, trait_def_id, "old_orphan_check") { if !ty::has_attr(self.tcx, trait_def_id, "old_orphan_check") {
self.tcx.sess.span_err( span_err!(self.tcx.sess, item.span, E0210,
item.span,
format!(
"type parameter `{}` is not constrained by any local type; \ "type parameter `{}` is not constrained by any local type; \
only traits defined in the current crate can be implemented \ only traits defined in the current crate can be implemented \
for a type parameter", for a type parameter",
param_ty.user_string(self.tcx)).as_slice()); param_ty.user_string(self.tcx));
self.tcx.sess.span_note( self.tcx.sess.span_note(
item.span, item.span,
format!("for a limited time, you can add \ format!("for a limited time, you can add \

View File

@ -37,8 +37,7 @@ impl<'cx, 'tcx,'v> visit::Visitor<'v> for UnsafetyChecker<'cx, 'tcx> {
match unsafety { match unsafety {
ast::Unsafety::Normal => { /* OK */ } ast::Unsafety::Normal => { /* OK */ }
ast::Unsafety::Unsafe => { ast::Unsafety::Unsafe => {
self.tcx.sess.span_err( span_err!(self.tcx.sess, item.span, E0197,
item.span,
"inherent impls cannot be declared as unsafe"); "inherent impls cannot be declared as unsafe");
} }
} }
@ -49,24 +48,21 @@ impl<'cx, 'tcx,'v> visit::Visitor<'v> for UnsafetyChecker<'cx, 'tcx> {
match (trait_def.unsafety, unsafety, polarity) { match (trait_def.unsafety, unsafety, polarity) {
(ast::Unsafety::Unsafe, (ast::Unsafety::Unsafe,
ast::Unsafety::Unsafe, ast::ImplPolarity::Negative) => { ast::Unsafety::Unsafe, ast::ImplPolarity::Negative) => {
self.tcx.sess.span_err( span_err!(self.tcx.sess, item.span, E0198,
item.span, "negative implementations are not unsafe");
format!("negative implementations are not unsafe").as_slice());
} }
(ast::Unsafety::Normal, ast::Unsafety::Unsafe, _) => { (ast::Unsafety::Normal, ast::Unsafety::Unsafe, _) => {
self.tcx.sess.span_err( span_err!(self.tcx.sess, item.span, E0199,
item.span, "implementing the trait `{}` is not unsafe",
format!("implementing the trait `{}` is not unsafe", trait_ref.user_string(self.tcx));
trait_ref.user_string(self.tcx)).as_slice());
} }
(ast::Unsafety::Unsafe, (ast::Unsafety::Unsafe,
ast::Unsafety::Normal, ast::ImplPolarity::Positive) => { ast::Unsafety::Normal, ast::ImplPolarity::Positive) => {
self.tcx.sess.span_err( span_err!(self.tcx.sess, item.span, E0200,
item.span, "the trait `{}` requires an `unsafe impl` declaration",
format!("the trait `{}` requires an `unsafe impl` declaration", trait_ref.user_string(self.tcx));
trait_ref.user_string(self.tcx)).as_slice());
} }
(ast::Unsafety::Unsafe, (ast::Unsafety::Unsafe,

View File

@ -452,7 +452,7 @@ fn convert_methods<'a,'tcx,'i,I>(ccx: &CollectCtxt<'a, 'tcx>,
let mut seen_methods = FnvHashSet(); let mut seen_methods = FnvHashSet();
for m in ms { for m in ms {
if !seen_methods.insert(m.pe_ident().repr(tcx)) { if !seen_methods.insert(m.pe_ident().repr(tcx)) {
tcx.sess.span_err(m.span, "duplicate method in trait impl"); span_err!(tcx.sess, m.span, E0201, "duplicate method in trait impl");
} }
let m_def_id = local_def(m.id); let m_def_id = local_def(m.id);
@ -608,7 +608,7 @@ fn convert(ccx: &CollectCtxt, it: &ast::Item) {
} }
ast::TypeImplItem(ref typedef) => { ast::TypeImplItem(ref typedef) => {
if opt_trait_ref.is_none() { if opt_trait_ref.is_none() {
tcx.sess.span_err(typedef.span, span_err!(tcx.sess, typedef.span, E0202,
"associated items are not allowed in inherent impls"); "associated items are not allowed in inherent impls");
} }
@ -1160,7 +1160,8 @@ fn add_unsized_bound<'a,'tcx>(ccx: &CollectCtxt<'a,'tcx>,
assert!(ptr.bound_lifetimes.is_empty()); assert!(ptr.bound_lifetimes.is_empty());
unbound = Some(ptr.trait_ref.clone()); unbound = Some(ptr.trait_ref.clone());
} else { } else {
ccx.tcx.sess.span_err(span, "type parameter has more than one relaxed default \ span_err!(ccx.tcx.sess, span, E0203,
"type parameter has more than one relaxed default \
bound, only one is supported"); bound, only one is supported");
} }
} }
@ -1690,11 +1691,10 @@ fn enforce_impl_ty_params_are_constrained<'tcx>(tcx: &ty::ctxt<'tcx>,
impl trait, self type, or predicates", impl trait, self type, or predicates",
param_ty.user_string(tcx)).as_slice()); param_ty.user_string(tcx)).as_slice());
} else { } else {
tcx.sess.span_err( span_err!(tcx.sess, ty_param.span, E0207,
ty_param.span, "the type parameter `{}` is not constrained by the \
format!("the type parameter `{}` is not constrained by the \
impl trait, self type, or predicates", impl trait, self type, or predicates",
param_ty.user_string(tcx)).as_slice()); param_ty.user_string(tcx));
tcx.sess.span_help( tcx.sess.span_help(
ty_param.span, ty_param.span,
format!("you can temporarily opt out of this rule by placing \ format!("you can temporarily opt out of this rule by placing \

View File

@ -100,7 +100,67 @@ register_diagnostics! {
E0178, E0178,
E0182, E0182,
E0183, E0183,
E0184 E0184,
E0185,
E0186,
E0187, // can't infer the kind of the closure
E0188, // types differ in mutability
E0189, // can only cast a boxed pointer to a boxed object
E0190, // can only cast a &-pointer to an &-object
E0191, // value of the associated type must be specified
E0192, // negative imples are allowed just fo `Send` and `Sync`
E0193, // cannot bound type where clause bounds may only be attached to types
// involving type parameters
E0194,
E0195, // lifetime parameters or bounds on method do not match the trait declaration
E0196, // cannot determine a type for this unboxed closure
E0197, // inherent impls cannot be declared as unsafe
E0198, // negative implementations are not unsafe
E0199, // implementing trait is not unsafe
E0200, // trait requires an `unsafe impl` declaration
E0201, // duplicate method in trait impl
E0202, // associated items are not allowed in inherint impls
E0203, // type parameter has more than one relaxed default bound,
// and only one is supported
E0204, // trait `Copy` may not be implemented for this type; field
// does not implement `Copy`
E0205, // trait `Copy` may not be implemented for this type; variant
// does not implement `copy`
E0206, // trait `Copy` may not be implemented for this type; type is
// not a structure or enumeration
E0207, // type parameter is not constrained by the impl trait, self type, or predicate
E0208,
E0209, // builtin traits can only be implemented on structs or enums
E0210, // type parameter is not constrained by any local type
E0211,
E0212, // cannot extract an associated type from a higher-ranked trait bound
E0213, // associated types are not accepted in this context
E0214, // parenthesized parameters may only be used with a trait
E0215, // angle-bracket notation is not stable with `Fn`
E0216, // parenthetical notation is only stable with `Fn`
E0217, // ambiguous associated type, defined in multiple supertraits
E0218, // no associated type defined
E0219, // associated type defined in higher-ranked supertrait
E0220, // associated type not found for type parameter
E0221, // ambiguous associated type in bounds
E0222, // variadic function must have C calling convention
E0223, // ambiguous associated type
E0224, // at least one non-builtin train is required for an object type
E0225, // only the builtin traits can be used as closure or object bounds
E0226, // only a single explicit lifetime bound is permitted
E0227, // ambiguous lifetime bound, explicit lifetime bound required
E0228, // explicit lifetime bound required
E0229, // associated type bindings are not allowed here
E0230, // there is no type parameter on trait
E0231, // only named substitution parameters are allowed
E0232, // this attribute must have a value
E0233,
E0234, // `for` loop expression has type which does not implement the `Iterator` trait
E0235, // structure constructor specifies a structure of type but
E0236, // no lang item for range syntax
E0237, // no lang item for range syntax
E0238, // parenthesized parameters may only be used with a trait
E0239 // `next` method of `Iterator` trait has unexpected type
} }
__build_diagnostic_array! { DIAGNOSTICS } __build_diagnostic_array! { DIAGNOSTICS }

View File

@ -206,11 +206,11 @@ fn require_same_types<'a, 'tcx, M>(tcx: &ty::ctxt<'tcx>,
match result { match result {
Ok(_) => true, Ok(_) => true,
Err(ref terr) => { Err(ref terr) => {
tcx.sess.span_err(span, span_err!(tcx.sess, span, E0211,
&format!("{}: {}", "{}: {}",
msg(), msg(),
ty::type_err_to_str(tcx, ty::type_err_to_str(tcx,
terr))[]); terr));
ty::note_and_explain_type_err(tcx, terr); ty::note_and_explain_type_err(tcx, terr);
false false
} }

View File

@ -1055,7 +1055,7 @@ impl<'a, 'tcx> SolveContext<'a, 'tcx> {
// attribute and report an error with various results if found. // attribute and report an error with various results if found.
if ty::has_attr(tcx, item_def_id, "rustc_variance") { if ty::has_attr(tcx, item_def_id, "rustc_variance") {
let found = item_variances.repr(tcx); let found = item_variances.repr(tcx);
tcx.sess.span_err(tcx.map.span(item_id), &found[]); span_err!(tcx.sess, tcx.map.span(item_id), E0208, "{}", &found[]);
} }
let newly_added = tcx.item_variance_map.borrow_mut() let newly_added = tcx.item_variance_map.borrow_mut()