Skip to content

Commit ab410cd

Browse files
committed
Add error codes to rustc_typeck
1 parent ac6d6d9 commit ab410cd

File tree

15 files changed

+179
-157
lines changed

15 files changed

+179
-157
lines changed

src/librustc_typeck/astconv.rs

Lines changed: 36 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ pub trait AstConv<'tcx> {
100100
-> Ty<'tcx>
101101
{
102102
if ty::binds_late_bound_regions(self.tcx(), &poly_trait_ref) {
103-
self.tcx().sess.span_err(
104-
span,
103+
span_err!(self.tcx().sess, span, E0212,
105104
"cannot extract an associated type from a higher-ranked trait bound \
106105
in this context");
107106
self.tcx().types.err
@@ -119,8 +118,7 @@ pub trait AstConv<'tcx> {
119118
_item_name: ast::Name)
120119
-> Ty<'tcx>
121120
{
122-
self.tcx().sess.span_err(
123-
span,
121+
span_err!(self.tcx().sess, span, E0213,
124122
"associated types are not accepted in this context");
125123

126124
self.tcx().types.err
@@ -268,8 +266,7 @@ pub fn ast_path_substs_for_ty<'tcx>(
268266
convert_angle_bracketed_parameters(this, rscope, data)
269267
}
270268
ast::ParenthesizedParameters(ref data) => {
271-
tcx.sess.span_err(
272-
path.span,
269+
span_err!(tcx.sess, path.span, E0214,
273270
"parenthesized parameters may only be used with a trait");
274271
(Vec::new(), convert_parenthesized_parameters(this, data), Vec::new())
275272
}
@@ -610,7 +607,7 @@ fn ast_path_to_trait_ref<'a,'tcx>(
610607
if !this.tcx().sess.features.borrow().unboxed_closures &&
611608
this.tcx().lang_items.fn_trait_kind(trait_def_id).is_some()
612609
{
613-
this.tcx().sess.span_err(path.span,
610+
span_err!(this.tcx().sess, path.span, E0215,
614611
"angle-bracket notation is not stable when \
615612
used with the `Fn` family of traits, use parentheses");
616613
span_help!(this.tcx().sess, path.span,
@@ -626,7 +623,7 @@ fn ast_path_to_trait_ref<'a,'tcx>(
626623
if !this.tcx().sess.features.borrow().unboxed_closures &&
627624
this.tcx().lang_items.fn_trait_kind(trait_def_id).is_none()
628625
{
629-
this.tcx().sess.span_err(path.span,
626+
span_err!(this.tcx().sess, path.span, E0216,
630627
"parenthetical notation is only stable when \
631628
used with the `Fn` family of traits");
632629
span_help!(this.tcx().sess, path.span,
@@ -738,32 +735,29 @@ fn ast_type_binding_to_projection_predicate<'tcx>(
738735
}
739736

740737
if candidates.len() > 1 {
741-
tcx.sess.span_err(
742-
binding.span,
743-
format!("ambiguous associated type: `{}` defined in multiple supertraits `{}`",
738+
span_err!(tcx.sess, binding.span, E0217,
739+
"ambiguous associated type: `{}` defined in multiple supertraits `{}`",
744740
token::get_name(binding.item_name),
745-
candidates.user_string(tcx)).as_slice());
741+
candidates.user_string(tcx));
746742
return Err(ErrorReported);
747743
}
748744

749745
let candidate = match candidates.pop() {
750746
Some(c) => c,
751747
None => {
752-
tcx.sess.span_err(
753-
binding.span,
754-
format!("no associated type `{}` defined in `{}`",
748+
span_err!(tcx.sess, binding.span, E0218,
749+
"no associated type `{}` defined in `{}`",
755750
token::get_name(binding.item_name),
756-
trait_ref.user_string(tcx)).as_slice());
751+
trait_ref.user_string(tcx));
757752
return Err(ErrorReported);
758753
}
759754
};
760755

761756
if ty::binds_late_bound_regions(tcx, &candidate) {
762-
tcx.sess.span_err(
763-
binding.span,
764-
format!("associated type `{}` defined in higher-ranked supertrait `{}`",
757+
span_err!(tcx.sess, binding.span, E0219,
758+
"associated type `{}` defined in higher-ranked supertrait `{}`",
765759
token::get_name(binding.item_name),
766-
candidate.user_string(tcx)).as_slice());
760+
candidate.user_string(tcx));
767761
return Err(ErrorReported);
768762
}
769763

@@ -964,18 +958,18 @@ fn associated_path_def_to_ty<'tcx>(this: &AstConv<'tcx>,
964958
}
965959

966960
if suitable_bounds.len() == 0 {
967-
tcx.sess.span_err(ast_ty.span,
968-
format!("associated type `{}` not found for type parameter `{}`",
961+
span_err!(tcx.sess, ast_ty.span, E0220,
962+
"associated type `{}` not found for type parameter `{}`",
969963
token::get_name(assoc_name),
970-
token::get_name(ty_param_name)).as_slice());
964+
token::get_name(ty_param_name));
971965
return this.tcx().types.err;
972966
}
973967

974968
if suitable_bounds.len() > 1 {
975-
tcx.sess.span_err(ast_ty.span,
976-
format!("ambiguous associated type `{}` in bounds of `{}`",
969+
span_err!(tcx.sess, ast_ty.span, E0221,
970+
"ambiguous associated type `{}` in bounds of `{}`",
977971
token::get_name(assoc_name),
978-
token::get_name(ty_param_name)).as_slice());
972+
token::get_name(ty_param_name));
979973

980974
for suitable_bound in suitable_bounds.iter() {
981975
span_note!(this.tcx().sess, ast_ty.span,
@@ -1093,7 +1087,7 @@ pub fn ast_ty_to_ty<'tcx>(
10931087
ast::TyParen(ref typ) => ast_ty_to_ty(this, rscope, &**typ),
10941088
ast::TyBareFn(ref bf) => {
10951089
if bf.decl.variadic && bf.abi != abi::C {
1096-
tcx.sess.span_err(ast_ty.span,
1090+
span_err!(tcx.sess, ast_ty.span, E0222,
10971091
"variadic function must have C calling convention");
10981092
}
10991093
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>(
11521146
def::DefAssociatedTy(trait_type_id) => {
11531147
let path_str = tcx.map.path_to_string(
11541148
tcx.map.get_parent(trait_type_id.node));
1155-
tcx.sess.span_err(ast_ty.span,
1156-
&format!("ambiguous associated \
1149+
span_err!(tcx.sess, ast_ty.span, E0223,
1150+
"ambiguous associated \
11571151
type; specify the type \
11581152
using the syntax `<Type \
11591153
as {}>::{}`",
@@ -1163,7 +1157,7 @@ pub fn ast_ty_to_ty<'tcx>(
11631157
.last()
11641158
.unwrap()
11651159
.identifier)
1166-
.get())[]);
1160+
.get());
11671161
this.tcx().types.err
11681162
}
11691163
def::DefAssociatedPath(provenance, assoc_ident) => {
@@ -1549,8 +1543,7 @@ fn conv_ty_poly_trait_ref<'tcx>(
15491543
None,
15501544
&mut projection_bounds))
15511545
} else {
1552-
this.tcx().sess.span_err(
1553-
span,
1546+
span_err!(this.tcx().sess, span, E0224,
15541547
"at least one non-builtin trait is required for an object type");
15551548
None
15561549
};
@@ -1585,10 +1578,9 @@ pub fn conv_existential_bounds_from_partitioned_bounds<'tcx>(
15851578

15861579
if !trait_bounds.is_empty() {
15871580
let b = &trait_bounds[0];
1588-
this.tcx().sess.span_err(
1589-
b.trait_ref.path.span,
1590-
&format!("only the builtin traits can be used \
1591-
as closure or object bounds")[]);
1581+
span_err!(this.tcx().sess, b.trait_ref.path.span, E0225,
1582+
"only the builtin traits can be used \
1583+
as closure or object bounds");
15921584
}
15931585

15941586
let region_bound = compute_region_bound(this,
@@ -1625,9 +1617,8 @@ fn compute_opt_region_bound<'tcx>(tcx: &ty::ctxt<'tcx>,
16251617
builtin_bounds.repr(tcx));
16261618

16271619
if explicit_region_bounds.len() > 1 {
1628-
tcx.sess.span_err(
1629-
explicit_region_bounds[1].span,
1630-
format!("only a single explicit lifetime bound is permitted").as_slice());
1620+
span_err!(tcx.sess, explicit_region_bounds[1].span, E0226,
1621+
"only a single explicit lifetime bound is permitted");
16311622
}
16321623

16331624
if explicit_region_bounds.len() != 0 {
@@ -1658,10 +1649,9 @@ fn compute_opt_region_bound<'tcx>(tcx: &ty::ctxt<'tcx>,
16581649
// error.
16591650
let r = derived_region_bounds[0];
16601651
if derived_region_bounds.slice_from(1).iter().any(|r1| r != *r1) {
1661-
tcx.sess.span_err(
1662-
span,
1663-
&format!("ambiguous lifetime bound, \
1664-
explicit lifetime bound required")[]);
1652+
span_err!(tcx.sess, span, E0227,
1653+
"ambiguous lifetime bound, \
1654+
explicit lifetime bound required");
16651655
}
16661656
return Some(r);
16671657
}
@@ -1685,9 +1675,8 @@ fn compute_region_bound<'tcx>(
16851675
match rscope.default_region_bound(span) {
16861676
Some(r) => { r }
16871677
None => {
1688-
this.tcx().sess.span_err(
1689-
span,
1690-
&format!("explicit lifetime bound required")[]);
1678+
span_err!(this.tcx().sess, span, E0228,
1679+
"explicit lifetime bound required");
16911680
ty::ReStatic
16921681
}
16931682
}
@@ -1771,8 +1760,7 @@ fn prohibit_projections<'tcx>(tcx: &ty::ctxt<'tcx>,
17711760
bindings: &[ConvertedBinding<'tcx>])
17721761
{
17731762
for binding in bindings.iter().take(1) {
1774-
tcx.sess.span_err(
1775-
binding.span,
1763+
span_err!(tcx.sess, binding.span, E0229,
17761764
"associated type bindings are not allowed here");
17771765
}
17781766
}

src/librustc_typeck/check/closure.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,9 @@ pub fn check_expr_closure<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
5050

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

53-
fcx.ccx.tcx.sess.span_err(
54-
expr.span,
53+
span_err!(fcx.ccx.tcx.sess, expr.span, E0187,
5554
"can't infer the \"kind\" of the closure, explicitly annotate it. e.g. \
56-
`|&:| {}`");
55+
`|&:| {{}}`");
5756
},
5857
Some((sig, kind)) => {
5958
check_unboxed_closure(fcx, expr, kind, decl, body, Some(sig));

src/librustc_typeck/check/compare_method.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,21 @@ pub fn compare_impl_method<'tcx>(tcx: &ty::ctxt<'tcx>,
5959
(&ty::StaticExplicitSelfCategory,
6060
&ty::StaticExplicitSelfCategory) => {}
6161
(&ty::StaticExplicitSelfCategory, _) => {
62-
tcx.sess.span_err(
63-
impl_m_span,
64-
format!("method `{}` has a `{}` declaration in the impl, \
62+
span_err!(tcx.sess, impl_m_span, E0185,
63+
"method `{}` has a `{}` declaration in the impl, \
6564
but not in the trait",
6665
token::get_name(trait_m.name),
6766
ppaux::explicit_self_category_to_str(
68-
&impl_m.explicit_self)).as_slice());
67+
&impl_m.explicit_self));
6968
return;
7069
}
7170
(_, &ty::StaticExplicitSelfCategory) => {
72-
tcx.sess.span_err(
73-
impl_m_span,
74-
format!("method `{}` has a `{}` declaration in the trait, \
71+
span_err!(tcx.sess, impl_m_span, E0186,
72+
"method `{}` has a `{}` declaration in the trait, \
7573
but not in the impl",
7674
token::get_name(trait_m.name),
7775
ppaux::explicit_self_category_to_str(
78-
&trait_m.explicit_self)).as_slice());
76+
&trait_m.explicit_self));
7977
return;
8078
}
8179
_ => {
@@ -400,11 +398,10 @@ pub fn compare_impl_method<'tcx>(tcx: &ty::ctxt<'tcx>,
400398
// are zero. Since I don't quite know how to phrase things at
401399
// the moment, give a kind of vague error message.
402400
if trait_params.len() != impl_params.len() {
403-
tcx.sess.span_err(
404-
span,
405-
&format!("lifetime parameters or bounds on method `{}` do \
401+
span_err!(tcx.sess, span, E0195,
402+
"lifetime parameters or bounds on method `{}` do \
406403
not match the trait declaration",
407-
token::get_name(impl_m.name))[]);
404+
token::get_name(impl_m.name));
408405
return false;
409406
}
410407

src/librustc_typeck/check/mod.rs

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -802,24 +802,23 @@ fn check_trait_on_unimplemented<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
802802
}) {
803803
Some(_) => (),
804804
None => {
805-
ccx.tcx.sess.span_err(attr.span,
806-
format!("there is no type parameter \
805+
span_err!(ccx.tcx.sess, attr.span, E0230,
806+
"there is no type parameter \
807807
{} on trait {}",
808-
s, item.ident.as_str())
809-
.as_slice());
808+
s, item.ident.as_str());
810809
}
811810
},
812811
// `{:1}` and `{}` are not to be used
813812
Position::ArgumentIs(_) | Position::ArgumentNext => {
814-
ccx.tcx.sess.span_err(attr.span,
813+
span_err!(ccx.tcx.sess, attr.span, E0231,
815814
"only named substitution \
816815
parameters are allowed");
817816
}
818817
}
819818
}
820819
}
821820
} else {
822-
ccx.tcx.sess.span_err(attr.span,
821+
span_err!(ccx.tcx.sess, attr.span, E0232,
823822
"this attribute must have a value, \
824823
eg `#[rustc_on_unimplemented = \"foo\"]`")
825824
}
@@ -2100,8 +2099,8 @@ fn lookup_method_for_for_loop<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
21002099
let trait_did = match fcx.tcx().lang_items.require(IteratorItem) {
21012100
Ok(trait_did) => trait_did,
21022101
Err(ref err_string) => {
2103-
fcx.tcx().sess.span_err(iterator_expr.span,
2104-
&err_string[]);
2102+
span_err!(fcx.tcx().sess, iterator_expr.span, E0233,
2103+
"{}", &err_string[]);
21052104
return fcx.tcx().types.err
21062105
}
21072106
};
@@ -2124,11 +2123,10 @@ fn lookup_method_for_for_loop<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
21242123

21252124
if !ty::type_is_error(true_expr_type) {
21262125
let ty_string = fcx.infcx().ty_to_string(true_expr_type);
2127-
fcx.tcx().sess.span_err(iterator_expr.span,
2128-
&format!("`for` loop expression has type `{}` which does \
2126+
span_err!(fcx.tcx().sess, iterator_expr.span, E0234,
2127+
"`for` loop expression has type `{}` which does \
21292128
not implement the `Iterator` trait; \
2130-
maybe try .iter()",
2131-
ty_string)[]);
2129+
maybe try .iter()", ty_string);
21322130
}
21332131
fcx.tcx().types.err
21342132
}
@@ -2163,11 +2161,10 @@ fn lookup_method_for_for_loop<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
21632161
fcx.tcx().types.err
21642162
}
21652163
_ => {
2166-
fcx.tcx().sess.span_err(iterator_expr.span,
2167-
&format!("`next` method of the `Iterator` \
2164+
span_err!(fcx.tcx().sess, iterator_expr.span, E0239,
2165+
"`next` method of the `Iterator` \
21682166
trait has an unexpected type `{}`",
2169-
fcx.infcx().ty_to_string(return_type))
2170-
[]);
2167+
fcx.infcx().ty_to_string(return_type));
21712168
fcx.tcx().types.err
21722169
}
21732170
}
@@ -3881,18 +3878,16 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
38813878
Err(type_error) => {
38823879
let type_error_description =
38833880
ty::type_err_to_str(tcx, &type_error);
3884-
fcx.tcx()
3885-
.sess
3886-
.span_err(path.span,
3887-
&format!("structure constructor specifies a \
3881+
span_err!(fcx.tcx().sess, path.span, E0235,
3882+
"structure constructor specifies a \
38883883
structure of type `{}`, but this \
38893884
structure has type `{}`: {}",
38903885
fcx.infcx()
38913886
.ty_to_string(type_and_substs.ty),
38923887
fcx.infcx()
38933888
.ty_to_string(
38943889
actual_structure_type),
3895-
type_error_description)[]);
3890+
type_error_description);
38963891
ty::note_and_explain_type_err(tcx, &type_error);
38973892
}
38983893
}
@@ -4013,7 +4008,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
40134008

40144009
ty::mk_struct(tcx, did, tcx.mk_substs(substs))
40154010
} else {
4016-
tcx.sess.span_err(expr.span, "No lang item for range syntax");
4011+
span_err!(tcx.sess, expr.span, E0236, "no lang item for range syntax");
40174012
fcx.tcx().types.err
40184013
}
40194014
}
@@ -4023,7 +4018,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
40234018
let substs = Substs::new_type(vec![], vec![]);
40244019
ty::mk_struct(tcx, did, tcx.mk_substs(substs))
40254020
} else {
4026-
tcx.sess.span_err(expr.span, "No lang item for range syntax");
4021+
span_err!(tcx.sess, expr.span, E0237, "no lang item for range syntax");
40274022
fcx.tcx().types.err
40284023
}
40294024
}
@@ -4873,8 +4868,7 @@ pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
48734868
}
48744869

48754870
ast::ParenthesizedParameters(ref data) => {
4876-
fcx.tcx().sess.span_err(
4877-
span,
4871+
span_err!(fcx.tcx().sess, span, E0238,
48784872
"parenthesized parameters may only be used with a trait");
48794873
push_explicit_parenthesized_parameters_from_segment_to_substs(
48804874
fcx, space, span, type_defs, data, substs);

0 commit comments

Comments
 (0)