Skip to content

Assign more diagnostic codes #15754

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from Jul 19, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 64 additions & 1 deletion src/librustc/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,68 @@ register_diagnostics!(
E0091,
E0092,
E0093,
E0094
E0094,
E0095,
E0096,
E0097,
E0098,
E0099,
E0100,
E0101,
E0102,
E0103,
E0104,
E0105,
E0106,
E0107,
E0108,
E0109,
E0110,
E0111,
E0112,
E0113,
E0114,
E0115,
E0116,
E0117,
E0118,
E0119,
E0120,
E0121,
E0122,
E0123,
E0124,
E0125,
E0126,
E0127,
E0128,
E0129,
E0130,
E0131,
E0132,
E0133,
E0134,
E0135,
E0136,
E0137,
E0138,
E0139,
E0140,
E0141,
E0142,
E0143,
E0144,
E0145,
E0146,
E0147,
E0148,
E0149,
E0150,
E0151,
E0152,
E0153,
E0154,
E0155,
E0156,
E0157
)
15 changes: 7 additions & 8 deletions src/librustc/middle/effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ impl<'a> EffectCheckVisitor<'a> {
match self.unsafe_context {
SafeContext => {
// Report an error.
self.tcx.sess.span_err(span,
format!("{} requires unsafe function or \
block",
description).as_slice())
span_err!(self.tcx.sess, span, E0133,
"{} requires unsafe function or block",
description);
}
UnsafeBlock(block_id) => {
// OK, but record this.
Expand All @@ -73,14 +72,14 @@ impl<'a> EffectCheckVisitor<'a> {
match ty::get(base_type).sty {
ty::ty_uniq(ty) | ty::ty_rptr(_, ty::mt{ty, ..}) => match ty::get(ty).sty {
ty::ty_str => {
self.tcx.sess.span_err(e.span,
"modification of string types is not allowed");
span_err!(self.tcx.sess, e.span, E0134,
"modification of string types is not allowed");
}
_ => {}
},
ty::ty_str => {
self.tcx.sess.span_err(e.span,
"modification of string types is not allowed");
span_err!(self.tcx.sess, e.span, E0135,
"modification of string types is not allowed");
}
_ => {}
}
Expand Down
15 changes: 6 additions & 9 deletions src/librustc/middle/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,8 @@ fn find_item(item: &Item, ctxt: &mut EntryContext) {
if ctxt.main_fn.is_none() {
ctxt.main_fn = Some((item.id, item.span));
} else {
ctxt.session.span_err(
item.span,
"multiple 'main' functions");
span_err!(ctxt.session, item.span, E0136,
"multiple 'main' functions");
}
} else {
// This isn't main
Expand All @@ -102,19 +101,17 @@ fn find_item(item: &Item, ctxt: &mut EntryContext) {
if ctxt.attr_main_fn.is_none() {
ctxt.attr_main_fn = Some((item.id, item.span));
} else {
ctxt.session.span_err(
item.span,
"multiple 'main' functions");
span_err!(ctxt.session, item.span, E0137,
"multiple functions with a #[main] attribute");
}
}

if attr::contains_name(item.attrs.as_slice(), "start") {
if ctxt.start_fn.is_none() {
ctxt.start_fn = Some((item.id, item.span));
} else {
ctxt.session.span_err(
item.span,
"multiple 'start' functions");
span_err!(ctxt.session, item.span, E0138,
"multiple 'start' functions");
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions src/librustc/middle/intrinsicck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,12 @@ impl<'a> IntrinsicCheckingVisitor<'a> {

fn check_transmute(&self, span: Span, from: ty::t, to: ty::t) {
if type_size_is_affected_by_type_parameters(self.tcx, from) {
self.tcx.sess.span_err(span,
"cannot transmute from a type that \
contains type parameters");
span_err!(self.tcx.sess, span, E0139,
"cannot transmute from a type that contains type parameters");
}
if type_size_is_affected_by_type_parameters(self.tcx, to) {
self.tcx.sess.span_err(span,
"cannot transmute to a type that contains \
type parameters");
span_err!(self.tcx.sess, span, E0140,
"cannot transmute to a type that contains type parameters");
}

let restriction = TransmuteRestriction {
Expand Down
130 changes: 59 additions & 71 deletions src/librustc/middle/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,20 @@ fn check_struct_safe_for_destructor(cx: &mut Context,
let struct_ty = ty::mk_struct(cx.tcx, struct_did,
subst::Substs::empty());
if !ty::type_is_sendable(cx.tcx, struct_ty) {
cx.tcx.sess.span_err(span,
"cannot implement a destructor on a \
structure that does not satisfy Send");
cx.tcx.sess.span_note(span,
"use \"#[unsafe_destructor]\" on the \
implementation to force the compiler to \
allow this");
span_err!(cx.tcx.sess, span, E0125,
"cannot implement a destructor on a \
structure that does not satisfy Send");
span_note!(cx.tcx.sess, span,
"use \"#[unsafe_destructor]\" on the implementation \
to force the compiler to allow this");
}
} else {
cx.tcx.sess.span_err(span,
"cannot implement a destructor on a structure \
with type parameters");
cx.tcx.sess.span_note(span,
"use \"#[unsafe_destructor]\" on the \
implementation to force the compiler to \
allow this");
span_err!(cx.tcx.sess, span, E0141,
"cannot implement a destructor on a structure \
with type parameters");
span_note!(cx.tcx.sess, span,
"use \"#[unsafe_destructor]\" on the implementation \
to force the compiler to allow this");
}
}

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

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

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

let fty = ty::node_id_to_type(cx.tcx, id);
Expand Down Expand Up @@ -489,12 +484,11 @@ pub fn check_typaram_bounds(cx: &Context,
ty,
type_param_def.bounds.builtin_bounds,
|missing| {
cx.tcx.sess.span_err(
sp,
format!("instantiating a type parameter with an incompatible type \
`{}`, which does not fulfill `{}`",
ty_to_string(cx.tcx, ty),
missing.user_string(cx.tcx)).as_slice());
span_err!(cx.tcx.sess, sp, E0144,
"instantiating a type parameter with an incompatible type \
`{}`, which does not fulfill `{}`",
ty_to_string(cx.tcx, ty),
missing.user_string(cx.tcx));
});
}

Expand All @@ -506,36 +500,32 @@ pub fn check_freevar_bounds(cx: &Context, sp: Span, ty: ty::t,
// Emit a less mysterious error message in this case.
match referenced_ty {
Some(rty) => {
cx.tcx.sess.span_err(sp,
format!("cannot implicitly borrow variable of type `{}` in a \
bounded stack closure (implicit reference does not \
fulfill `{}`)",
ty_to_string(cx.tcx, rty),
missing.user_string(cx.tcx)).as_slice())
span_err!(cx.tcx.sess, sp, E0145,
"cannot implicitly borrow variable of type `{}` in a \
bounded stack closure (implicit reference does not fulfill `{}`)",
ty_to_string(cx.tcx, rty), missing.user_string(cx.tcx));
}
None => {
cx.tcx.sess.span_err(sp,
format!("cannot capture variable of type `{}`, which does \
not fulfill `{}`, in a bounded closure",
ty_to_string(cx.tcx, ty),
missing.user_string(cx.tcx)).as_slice())
span_err!(cx.tcx.sess, sp, E0146,
"cannot capture variable of type `{}`, which does \
not fulfill `{}`, in a bounded closure",
ty_to_string(cx.tcx, ty), missing.user_string(cx.tcx));
}
}
cx.tcx.sess.span_note(
sp,
format!("this closure's environment must satisfy `{}`",
bounds.user_string(cx.tcx)).as_slice());
span_note!(cx.tcx.sess, sp,
"this closure's environment must satisfy `{}`",
bounds.user_string(cx.tcx));
});
}

pub fn check_trait_cast_bounds(cx: &Context, sp: Span, ty: ty::t,
bounds: ty::BuiltinBounds) {
check_builtin_bounds(cx, ty, bounds, |missing| {
cx.tcx.sess.span_err(sp,
format!("cannot pack type `{}`, which does not fulfill \
`{}`, as a trait bounded by {}",
ty_to_string(cx.tcx, ty), missing.user_string(cx.tcx),
bounds.user_string(cx.tcx)).as_slice());
span_err!(cx.tcx.sess, sp, E0147,
"cannot pack type `{}`, which does not fulfill `{}`, as a trait bounded by {}",
ty_to_string(cx.tcx, ty),
missing.user_string(cx.tcx),
bounds.user_string(cx.tcx));
});
}

Expand All @@ -544,26 +534,26 @@ fn check_copy(cx: &Context, ty: ty::t, sp: Span, reason: &str) {
ty_to_string(cx.tcx, ty),
ty::type_contents(cx.tcx, ty).to_string());
if ty::type_moves_by_default(cx.tcx, ty) {
cx.tcx.sess.span_err(
sp,
format!("copying a value of non-copyable type `{}`",
ty_to_string(cx.tcx, ty)).as_slice());
cx.tcx.sess.span_note(sp, format!("{}", reason).as_slice());
span_err!(cx.tcx.sess, sp, E0148,
"copying a value of non-copyable type `{}`",
ty_to_string(cx.tcx, ty));
span_note!(cx.tcx.sess, sp, "{}", reason.as_slice());
}
}

pub fn check_static(tcx: &ty::ctxt, ty: ty::t, sp: Span) -> bool {
if !ty::type_is_static(tcx, ty) {
match ty::get(ty).sty {
ty::ty_param(..) => {
tcx.sess.span_err(sp,
format!("value may contain references; \
add `'static` bound to `{}`",
ty_to_string(tcx, ty)).as_slice());
}
_ => {
tcx.sess.span_err(sp, "value may contain references");
}
ty::ty_param(..) => {
span_err!(tcx.sess, sp, E0149,
"value may contain references; \
add `'static` bound to `{}`",
ty_to_string(tcx, ty));
}
_ => {
span_err!(tcx.sess, sp, E0150,
"value may contain references");
}
}
false
} else {
Expand Down Expand Up @@ -680,11 +670,9 @@ pub fn check_cast_for_escaping_regions(
// Ensure that `ty` has a statically known size (i.e., it has the `Sized` bound).
fn check_sized(tcx: &ty::ctxt, ty: ty::t, name: String, sp: Span) {
if !ty::type_is_sized(tcx, ty) {
tcx.sess.span_err(sp,
format!("variable `{}` has dynamically sized type \
`{}`",
name,
ty_to_string(tcx, ty)).as_slice());
span_err!(tcx.sess, sp, E0151,
"variable `{}` has dynamically sized type `{}`",
name, ty_to_string(tcx, ty));
}
}

Expand Down
13 changes: 7 additions & 6 deletions src/librustc/middle/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use middle::weak_lang_items;
use syntax::ast;
use syntax::ast_util::local_def;
use syntax::attr::AttrMetaMethods;
use syntax::codemap::{DUMMY_SP, Span};
use syntax::parse::token::InternedString;
use syntax::visit::Visitor;
use syntax::visit;
Expand Down Expand Up @@ -122,7 +123,7 @@ impl<'a> Visitor<()> for LanguageItemCollector<'a> {

match item_index {
Some(item_index) => {
self.collect_item(item_index, local_def(item.id))
self.collect_item(item_index, local_def(item.id), item.span)
}
None => {}
}
Expand All @@ -147,13 +148,13 @@ impl<'a> LanguageItemCollector<'a> {
}
}

pub fn collect_item(&mut self, item_index: uint, item_def_id: ast::DefId) {
pub fn collect_item(&mut self, item_index: uint,
item_def_id: ast::DefId, span: Span) {
// Check for duplicates.
match self.items.items.get(item_index) {
&Some(original_def_id) if original_def_id != item_def_id => {
self.session.err(format!("duplicate entry for `{}`",
LanguageItems::item_name(
item_index)).as_slice());
span_err!(self.session, span, E0152,
"duplicate entry for `{}`", LanguageItems::item_name(item_index));
}
&Some(_) | &None => {
// OK.
Expand All @@ -173,7 +174,7 @@ impl<'a> LanguageItemCollector<'a> {
crate_store.iter_crate_data(|crate_number, _crate_metadata| {
each_lang_item(crate_store, crate_number, |node_id, item_index| {
let def_id = ast::DefId { krate: crate_number, node: node_id };
self.collect_item(item_index, def_id);
self.collect_item(item_index, def_id, DUMMY_SP);
true
});
})
Expand Down
Loading