Skip to content

Commit 5274e99

Browse files
author
Jakub Wieczorek
committed
Assign more diagnostic codes
1 parent 5ddc7b4 commit 5274e99

File tree

16 files changed

+276
-282
lines changed

16 files changed

+276
-282
lines changed

src/librustc/diagnostics.rs

+64-1
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,68 @@ register_diagnostics!(
110110
E0091,
111111
E0092,
112112
E0093,
113-
E0094
113+
E0094,
114+
E0095,
115+
E0096,
116+
E0097,
117+
E0098,
118+
E0099,
119+
E0100,
120+
E0101,
121+
E0102,
122+
E0103,
123+
E0104,
124+
E0105,
125+
E0106,
126+
E0107,
127+
E0108,
128+
E0109,
129+
E0110,
130+
E0111,
131+
E0112,
132+
E0113,
133+
E0114,
134+
E0115,
135+
E0116,
136+
E0117,
137+
E0118,
138+
E0119,
139+
E0120,
140+
E0121,
141+
E0122,
142+
E0123,
143+
E0124,
144+
E0125,
145+
E0126,
146+
E0127,
147+
E0128,
148+
E0129,
149+
E0130,
150+
E0131,
151+
E0132,
152+
E0133,
153+
E0134,
154+
E0135,
155+
E0136,
156+
E0137,
157+
E0138,
158+
E0139,
159+
E0140,
160+
E0141,
161+
E0142,
162+
E0143,
163+
E0144,
164+
E0145,
165+
E0146,
166+
E0147,
167+
E0148,
168+
E0149,
169+
E0150,
170+
E0151,
171+
E0152,
172+
E0153,
173+
E0154,
174+
E0155,
175+
E0156,
176+
E0157
114177
)

src/librustc/middle/effect.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,9 @@ impl<'a> EffectCheckVisitor<'a> {
4949
match self.unsafe_context {
5050
SafeContext => {
5151
// Report an error.
52-
self.tcx.sess.span_err(span,
53-
format!("{} requires unsafe function or \
54-
block",
55-
description).as_slice())
52+
span_err!(self.tcx.sess, span, E0133,
53+
"{} requires unsafe function or block",
54+
description);
5655
}
5756
UnsafeBlock(block_id) => {
5857
// OK, but record this.
@@ -73,14 +72,14 @@ impl<'a> EffectCheckVisitor<'a> {
7372
match ty::get(base_type).sty {
7473
ty::ty_uniq(ty) | ty::ty_rptr(_, ty::mt{ty, ..}) => match ty::get(ty).sty {
7574
ty::ty_str => {
76-
self.tcx.sess.span_err(e.span,
77-
"modification of string types is not allowed");
75+
span_err!(self.tcx.sess, e.span, E0134,
76+
"modification of string types is not allowed");
7877
}
7978
_ => {}
8079
},
8180
ty::ty_str => {
82-
self.tcx.sess.span_err(e.span,
83-
"modification of string types is not allowed");
81+
span_err!(self.tcx.sess, e.span, E0135,
82+
"modification of string types is not allowed");
8483
}
8584
_ => {}
8685
}

src/librustc/middle/entry.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,8 @@ fn find_item(item: &Item, ctxt: &mut EntryContext) {
8787
if ctxt.main_fn.is_none() {
8888
ctxt.main_fn = Some((item.id, item.span));
8989
} else {
90-
ctxt.session.span_err(
91-
item.span,
92-
"multiple 'main' functions");
90+
span_err!(ctxt.session, item.span, E0136,
91+
"multiple 'main' functions");
9392
}
9493
} else {
9594
// This isn't main
@@ -102,19 +101,17 @@ fn find_item(item: &Item, ctxt: &mut EntryContext) {
102101
if ctxt.attr_main_fn.is_none() {
103102
ctxt.attr_main_fn = Some((item.id, item.span));
104103
} else {
105-
ctxt.session.span_err(
106-
item.span,
107-
"multiple 'main' functions");
104+
span_err!(ctxt.session, item.span, E0137,
105+
"multiple functions with a #[main] attribute");
108106
}
109107
}
110108

111109
if attr::contains_name(item.attrs.as_slice(), "start") {
112110
if ctxt.start_fn.is_none() {
113111
ctxt.start_fn = Some((item.id, item.span));
114112
} else {
115-
ctxt.session.span_err(
116-
item.span,
117-
"multiple 'start' functions");
113+
span_err!(ctxt.session, item.span, E0138,
114+
"multiple 'start' functions");
118115
}
119116
}
120117
}

src/librustc/middle/intrinsicck.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,12 @@ impl<'a> IntrinsicCheckingVisitor<'a> {
9494

9595
fn check_transmute(&self, span: Span, from: ty::t, to: ty::t) {
9696
if type_size_is_affected_by_type_parameters(self.tcx, from) {
97-
self.tcx.sess.span_err(span,
98-
"cannot transmute from a type that \
99-
contains type parameters");
97+
span_err!(self.tcx.sess, span, E0139,
98+
"cannot transmute from a type that contains type parameters");
10099
}
101100
if type_size_is_affected_by_type_parameters(self.tcx, to) {
102-
self.tcx.sess.span_err(span,
103-
"cannot transmute to a type that contains \
104-
type parameters");
101+
span_err!(self.tcx.sess, span, E0140,
102+
"cannot transmute to a type that contains type parameters");
105103
}
106104

107105
let restriction = TransmuteRestriction {

src/librustc/middle/kind.rs

+59-71
Original file line numberDiff line numberDiff line change
@@ -92,22 +92,20 @@ fn check_struct_safe_for_destructor(cx: &mut Context,
9292
let struct_ty = ty::mk_struct(cx.tcx, struct_did,
9393
subst::Substs::empty());
9494
if !ty::type_is_sendable(cx.tcx, struct_ty) {
95-
cx.tcx.sess.span_err(span,
96-
"cannot implement a destructor on a \
97-
structure that does not satisfy Send");
98-
cx.tcx.sess.span_note(span,
99-
"use \"#[unsafe_destructor]\" on the \
100-
implementation to force the compiler to \
101-
allow this");
95+
span_err!(cx.tcx.sess, span, E0125,
96+
"cannot implement a destructor on a \
97+
structure that does not satisfy Send");
98+
span_note!(cx.tcx.sess, span,
99+
"use \"#[unsafe_destructor]\" on the implementation \
100+
to force the compiler to allow this");
102101
}
103102
} else {
104-
cx.tcx.sess.span_err(span,
105-
"cannot implement a destructor on a structure \
106-
with type parameters");
107-
cx.tcx.sess.span_note(span,
108-
"use \"#[unsafe_destructor]\" on the \
109-
implementation to force the compiler to \
110-
allow this");
103+
span_err!(cx.tcx.sess, span, E0141,
104+
"cannot implement a destructor on a structure \
105+
with type parameters");
106+
span_note!(cx.tcx.sess, span,
107+
"use \"#[unsafe_destructor]\" on the implementation \
108+
to force the compiler to allow this");
111109
}
112110
}
113111

@@ -124,14 +122,12 @@ fn check_impl_of_trait(cx: &mut Context, it: &Item, trait_ref: &TraitRef, self_t
124122
let self_ty: ty::t = ty::node_id_to_type(cx.tcx, it.id);
125123
debug!("checking impl with self type {}", ty::get(self_ty).sty);
126124
check_builtin_bounds(cx, self_ty, trait_def.bounds, |missing| {
127-
cx.tcx.sess.span_err(self_type.span,
128-
format!("the type `{}', which does not fulfill `{}`, cannot implement this \
129-
trait",
130-
ty_to_string(cx.tcx, self_ty),
131-
missing.user_string(cx.tcx)).as_slice());
132-
cx.tcx.sess.span_note(self_type.span,
133-
format!("types implementing this trait must fulfill `{}`",
134-
trait_def.bounds.user_string(cx.tcx)).as_slice());
125+
span_err!(cx.tcx.sess, self_type.span, E0142,
126+
"the type `{}', which does not fulfill `{}`, cannot implement this trait",
127+
ty_to_string(cx.tcx, self_ty), missing.user_string(cx.tcx));
128+
span_note!(cx.tcx.sess, self_type.span,
129+
"types implementing this trait must fulfill `{}`",
130+
trait_def.bounds.user_string(cx.tcx));
135131
});
136132

137133
// If this is a destructor, check kinds.
@@ -191,10 +187,9 @@ fn with_appropriate_checker(cx: &Context,
191187
}
192188

193189
fn check_for_bare(cx: &Context, fv: &freevar_entry) {
194-
cx.tcx.sess.span_err(
195-
fv.span,
196-
"can't capture dynamic environment in a fn item; \
197-
use the || { ... } closure form instead");
190+
span_err!(cx.tcx.sess, fv.span, E0143,
191+
"can't capture dynamic environment in a fn item; \
192+
use the || {} closure form instead", "{ ... }");
198193
} // same check is done in resolve.rs, but shouldn't be done
199194

200195
let fty = ty::node_id_to_type(cx.tcx, id);
@@ -489,12 +484,11 @@ pub fn check_typaram_bounds(cx: &Context,
489484
ty,
490485
type_param_def.bounds.builtin_bounds,
491486
|missing| {
492-
cx.tcx.sess.span_err(
493-
sp,
494-
format!("instantiating a type parameter with an incompatible type \
495-
`{}`, which does not fulfill `{}`",
496-
ty_to_string(cx.tcx, ty),
497-
missing.user_string(cx.tcx)).as_slice());
487+
span_err!(cx.tcx.sess, sp, E0144,
488+
"instantiating a type parameter with an incompatible type \
489+
`{}`, which does not fulfill `{}`",
490+
ty_to_string(cx.tcx, ty),
491+
missing.user_string(cx.tcx));
498492
});
499493
}
500494

@@ -506,36 +500,32 @@ pub fn check_freevar_bounds(cx: &Context, sp: Span, ty: ty::t,
506500
// Emit a less mysterious error message in this case.
507501
match referenced_ty {
508502
Some(rty) => {
509-
cx.tcx.sess.span_err(sp,
510-
format!("cannot implicitly borrow variable of type `{}` in a \
511-
bounded stack closure (implicit reference does not \
512-
fulfill `{}`)",
513-
ty_to_string(cx.tcx, rty),
514-
missing.user_string(cx.tcx)).as_slice())
503+
span_err!(cx.tcx.sess, sp, E0145,
504+
"cannot implicitly borrow variable of type `{}` in a \
505+
bounded stack closure (implicit reference does not fulfill `{}`)",
506+
ty_to_string(cx.tcx, rty), missing.user_string(cx.tcx));
515507
}
516508
None => {
517-
cx.tcx.sess.span_err(sp,
518-
format!("cannot capture variable of type `{}`, which does \
519-
not fulfill `{}`, in a bounded closure",
520-
ty_to_string(cx.tcx, ty),
521-
missing.user_string(cx.tcx)).as_slice())
509+
span_err!(cx.tcx.sess, sp, E0146,
510+
"cannot capture variable of type `{}`, which does \
511+
not fulfill `{}`, in a bounded closure",
512+
ty_to_string(cx.tcx, ty), missing.user_string(cx.tcx));
522513
}
523514
}
524-
cx.tcx.sess.span_note(
525-
sp,
526-
format!("this closure's environment must satisfy `{}`",
527-
bounds.user_string(cx.tcx)).as_slice());
515+
span_note!(cx.tcx.sess, sp,
516+
"this closure's environment must satisfy `{}`",
517+
bounds.user_string(cx.tcx));
528518
});
529519
}
530520

531521
pub fn check_trait_cast_bounds(cx: &Context, sp: Span, ty: ty::t,
532522
bounds: ty::BuiltinBounds) {
533523
check_builtin_bounds(cx, ty, bounds, |missing| {
534-
cx.tcx.sess.span_err(sp,
535-
format!("cannot pack type `{}`, which does not fulfill \
536-
`{}`, as a trait bounded by {}",
537-
ty_to_string(cx.tcx, ty), missing.user_string(cx.tcx),
538-
bounds.user_string(cx.tcx)).as_slice());
524+
span_err!(cx.tcx.sess, sp, E0147,
525+
"cannot pack type `{}`, which does not fulfill `{}`, as a trait bounded by {}",
526+
ty_to_string(cx.tcx, ty),
527+
missing.user_string(cx.tcx),
528+
bounds.user_string(cx.tcx));
539529
});
540530
}
541531

@@ -544,26 +534,26 @@ fn check_copy(cx: &Context, ty: ty::t, sp: Span, reason: &str) {
544534
ty_to_string(cx.tcx, ty),
545535
ty::type_contents(cx.tcx, ty).to_string());
546536
if ty::type_moves_by_default(cx.tcx, ty) {
547-
cx.tcx.sess.span_err(
548-
sp,
549-
format!("copying a value of non-copyable type `{}`",
550-
ty_to_string(cx.tcx, ty)).as_slice());
551-
cx.tcx.sess.span_note(sp, format!("{}", reason).as_slice());
537+
span_err!(cx.tcx.sess, sp, E0148,
538+
"copying a value of non-copyable type `{}`",
539+
ty_to_string(cx.tcx, ty));
540+
span_note!(cx.tcx.sess, sp, "{}", reason.as_slice());
552541
}
553542
}
554543

555544
pub fn check_static(tcx: &ty::ctxt, ty: ty::t, sp: Span) -> bool {
556545
if !ty::type_is_static(tcx, ty) {
557546
match ty::get(ty).sty {
558-
ty::ty_param(..) => {
559-
tcx.sess.span_err(sp,
560-
format!("value may contain references; \
561-
add `'static` bound to `{}`",
562-
ty_to_string(tcx, ty)).as_slice());
563-
}
564-
_ => {
565-
tcx.sess.span_err(sp, "value may contain references");
566-
}
547+
ty::ty_param(..) => {
548+
span_err!(tcx.sess, sp, E0149,
549+
"value may contain references; \
550+
add `'static` bound to `{}`",
551+
ty_to_string(tcx, ty));
552+
}
553+
_ => {
554+
span_err!(tcx.sess, sp, E0150,
555+
"value may contain references");
556+
}
567557
}
568558
false
569559
} else {
@@ -680,11 +670,9 @@ pub fn check_cast_for_escaping_regions(
680670
// Ensure that `ty` has a statically known size (i.e., it has the `Sized` bound).
681671
fn check_sized(tcx: &ty::ctxt, ty: ty::t, name: String, sp: Span) {
682672
if !ty::type_is_sized(tcx, ty) {
683-
tcx.sess.span_err(sp,
684-
format!("variable `{}` has dynamically sized type \
685-
`{}`",
686-
name,
687-
ty_to_string(tcx, ty)).as_slice());
673+
span_err!(tcx.sess, sp, E0151,
674+
"variable `{}` has dynamically sized type `{}`",
675+
name, ty_to_string(tcx, ty));
688676
}
689677
}
690678

src/librustc/middle/lang_items.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use middle::weak_lang_items;
2727
use syntax::ast;
2828
use syntax::ast_util::local_def;
2929
use syntax::attr::AttrMetaMethods;
30+
use syntax::codemap::{DUMMY_SP, Span};
3031
use syntax::parse::token::InternedString;
3132
use syntax::visit::Visitor;
3233
use syntax::visit;
@@ -122,7 +123,7 @@ impl<'a> Visitor<()> for LanguageItemCollector<'a> {
122123

123124
match item_index {
124125
Some(item_index) => {
125-
self.collect_item(item_index, local_def(item.id))
126+
self.collect_item(item_index, local_def(item.id), item.span)
126127
}
127128
None => {}
128129
}
@@ -147,13 +148,13 @@ impl<'a> LanguageItemCollector<'a> {
147148
}
148149
}
149150

150-
pub fn collect_item(&mut self, item_index: uint, item_def_id: ast::DefId) {
151+
pub fn collect_item(&mut self, item_index: uint,
152+
item_def_id: ast::DefId, span: Span) {
151153
// Check for duplicates.
152154
match self.items.items.get(item_index) {
153155
&Some(original_def_id) if original_def_id != item_def_id => {
154-
self.session.err(format!("duplicate entry for `{}`",
155-
LanguageItems::item_name(
156-
item_index)).as_slice());
156+
span_err!(self.session, span, E0152,
157+
"duplicate entry for `{}`", LanguageItems::item_name(item_index));
157158
}
158159
&Some(_) | &None => {
159160
// OK.
@@ -173,7 +174,7 @@ impl<'a> LanguageItemCollector<'a> {
173174
crate_store.iter_crate_data(|crate_number, _crate_metadata| {
174175
each_lang_item(crate_store, crate_number, |node_id, item_index| {
175176
let def_id = ast::DefId { krate: crate_number, node: node_id };
176-
self.collect_item(item_index, def_id);
177+
self.collect_item(item_index, def_id, DUMMY_SP);
177178
true
178179
});
179180
})

0 commit comments

Comments
 (0)