From 5274e997abc9273ef259199a1036f7753246bada Mon Sep 17 00:00:00 2001 From: Jakub Wieczorek Date: Thu, 17 Jul 2014 19:56:37 +0200 Subject: [PATCH] Assign more diagnostic codes --- src/librustc/diagnostics.rs | 65 ++++++++- src/librustc/middle/effect.rs | 15 +- src/librustc/middle/entry.rs | 15 +- src/librustc/middle/intrinsicck.rs | 10 +- src/librustc/middle/kind.rs | 130 ++++++++---------- src/librustc/middle/lang_items.rs | 13 +- src/librustc/middle/resolve.rs | 29 ++-- src/librustc/middle/typeck/astconv.rs | 70 ++++------ src/librustc/middle/typeck/check/vtable.rs | 32 ++--- src/librustc/middle/typeck/check/writeback.rs | 48 +++---- src/librustc/middle/typeck/coherence.rs | 46 +++---- src/librustc/middle/typeck/collect.rs | 59 ++++---- src/librustc/middle/typeck/mod.rs | 10 +- src/libsyntax/diagnostics/macros.rs | 12 +- src/test/compile-fail/multiple-main-2.rs | 2 +- src/test/compile-fail/multiple-main-3.rs | 2 +- 16 files changed, 276 insertions(+), 282 deletions(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 5f3bbf48105..1b806e1c257 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -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 ) diff --git a/src/librustc/middle/effect.rs b/src/librustc/middle/effect.rs index fed2f91ce09..e6160038b1d 100644 --- a/src/librustc/middle/effect.rs +++ b/src/librustc/middle/effect.rs @@ -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. @@ -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"); } _ => {} } diff --git a/src/librustc/middle/entry.rs b/src/librustc/middle/entry.rs index 9a5f226bb73..3debdc158fe 100644 --- a/src/librustc/middle/entry.rs +++ b/src/librustc/middle/entry.rs @@ -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 @@ -102,9 +101,8 @@ 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"); } } @@ -112,9 +110,8 @@ fn find_item(item: &Item, ctxt: &mut EntryContext) { 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"); } } } diff --git a/src/librustc/middle/intrinsicck.rs b/src/librustc/middle/intrinsicck.rs index 93913f84271..6669147b0dc 100644 --- a/src/librustc/middle/intrinsicck.rs +++ b/src/librustc/middle/intrinsicck.rs @@ -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 { diff --git a/src/librustc/middle/kind.rs b/src/librustc/middle/kind.rs index 4f7cb742d8f..f06049127e5 100644 --- a/src/librustc/middle/kind.rs +++ b/src/librustc/middle/kind.rs @@ -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"); } } @@ -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. @@ -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); @@ -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)); }); } @@ -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)); }); } @@ -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 { @@ -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)); } } diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index 1a1d47b2547..9abc9226c13 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -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; @@ -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 => {} } @@ -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. @@ -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 }); }) diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 3ff2ef77089..0acfa50c919 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -4016,14 +4016,17 @@ impl<'a> Resolver<'a> { this.record_def(path_id, (def, lp)); } Some((DefStruct(_), _)) => { - this.session.span_err(t.span, - "super-struct is defined \ - in a different crate") + span_err!(this.session, t.span, E0154, + "super-struct is defined in a different crate"); }, - Some(_) => this.session.span_err(t.span, - "super-struct is not a struct type"), - None => this.session.span_err(t.span, - "super-struct could not be resolved"), + Some(_) => { + span_err!(this.session, t.span, E0155, + "super-struct is not a struct type"); + } + None => { + span_err!(this.session, t.span, E0156, + "super-struct could not be resolved"); + } } }, _ => this.session.span_bug(t.span, "path not mapped to a TyPath") @@ -4297,17 +4300,13 @@ impl<'a> Resolver<'a> { if path.segments .iter() .any(|s| !s.lifetimes.is_empty()) { - self.session.span_err(path.span, - "lifetime parameters \ - are not allowed on \ - this type") + span_err!(self.session, path.span, E0157, + "lifetime parameters are not allowed on this type"); } else if path.segments .iter() .any(|s| s.types.len() > 0) { - self.session.span_err(path.span, - "type parameters are \ - not allowed on this \ - type") + span_err!(self.session, path.span, E0153, + "type parameters are not allowed on this type"); } } None => { diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc/middle/typeck/astconv.rs index 6d215282cc4..8bdb9ec84d9 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc/middle/typeck/astconv.rs @@ -129,8 +129,8 @@ pub fn opt_ast_region_to_region( match rscope.anon_regions(default_span, 1) { Err(()) => { debug!("optional region in illegal location"); - this.tcx().sess.span_err( - default_span, "missing lifetime specifier"); + span_err!(this.tcx().sess, default_span, E0106, + "missing lifetime specifier"); ty::ReStatic } @@ -187,12 +187,9 @@ fn ast_path_substs( rscope.anon_regions(path.span, expected_num_region_params); if supplied_num_region_params != 0 || anon_regions.is_err() { - tcx.sess.span_err( - path.span, - format!("wrong number of lifetime parameters: \ - expected {} but found {}", - expected_num_region_params, - supplied_num_region_params).as_slice()); + span_err!(tcx.sess, path.span, E0107, + "wrong number of lifetime parameters: expected {} but found {}", + expected_num_region_params, supplied_num_region_params); } match anon_regions { @@ -235,10 +232,10 @@ fn ast_path_substs( if supplied_ty_param_count > required_ty_param_count && !this.tcx().sess.features.default_type_params.get() { - this.tcx().sess.span_err(path.span, "default type parameters are \ - experimental and possibly buggy"); - this.tcx().sess.span_note(path.span, "add #![feature(default_type_params)] \ - to the crate attributes to enable"); + span_err!(this.tcx().sess, path.span, E0108, + "default type parameters are experimental and possibly buggy"); + span_note!(this.tcx().sess, path.span, + "add #![feature(default_type_params)] to the crate attributes to enable"); } let tps = path.segments.iter().flat_map(|s| s.types.iter()) @@ -309,16 +306,14 @@ fn check_path_args(tcx: &ty::ctxt, flags: uint) { if (flags & NO_TPS) != 0u { if !path.segments.iter().all(|s| s.types.is_empty()) { - tcx.sess.span_err( - path.span, + span_err!(tcx.sess, path.span, E0109, "type parameters are not allowed on this type"); } } if (flags & NO_REGIONS) != 0u { if !path.segments.last().unwrap().lifetimes.is_empty() { - tcx.sess.span_err( - path.span, + span_err!(tcx.sess, path.span, E0110, "region parameters are not allowed on this type"); } } @@ -359,8 +354,8 @@ pub fn ast_ty_to_prim_ty(tcx: &ty::ctxt, ast_ty: &ast::Ty) -> Option { Some(ty::mk_mach_float(ft)) } ast::TyStr => { - tcx.sess.span_err(ast_ty.span, - "bare `str` is not a type"); + span_err!(tcx.sess, ast_ty.span, E0037, + "bare `str` is not a type"); // return /something/ so they can at least get more errors Some(ty::mk_uniq(tcx, ty::mk_str(tcx))) } @@ -408,10 +403,8 @@ pub fn ast_ty_to_builtin_ty 1 { - this.tcx() - .sess - .span_err(path.span, - "`Box` has only one type parameter") + span_err!(this.tcx().sess, path.span, E0047, + "`Box` has only one type parameter"); } for inner_ast_type in path.segments @@ -428,16 +421,12 @@ pub fn ast_ty_to_builtin_ty { - this.tcx() - .sess - .span_err(path.span, - "`Box` is not a type"); + span_err!(this.tcx().sess, path.span, E0111, + "`Box` is not a type"); ty::mk_err() } ty::ty_vec(_, None) => { - this.tcx() - .sess - .span_err(path.span, + span_err!(this.tcx().sess, path.span, E0112, "`Box<[T]>` is not a type"); ty::mk_err() } @@ -445,9 +434,8 @@ pub fn ast_ty_to_builtin_ty`"); + span_err!(this.tcx().sess, path.span, E0113, + "not enough type parameters supplied to `Box`"); Some(ty::mk_err()) } def::DefTy(did) | def::DefStruct(did) @@ -456,10 +444,8 @@ pub fn ast_ty_to_builtin_ty 1 { - this.tcx() - .sess - .span_err(path.span, - "`Gc` has only one type parameter") + span_err!(this.tcx().sess, path.span, E0048, + "`Gc` has only one type parameter"); } for inner_ast_type in path.segments @@ -476,17 +462,13 @@ pub fn ast_ty_to_builtin_ty { - this.tcx() - .sess - .span_err(path.span, - "`Gc` is not a type"); + span_err!(this.tcx().sess, path.span, E0114, + "`Gc` is not a type"); ty::mk_err() } ty::ty_vec(_, None) => { - this.tcx() - .sess - .span_err(path.span, - "`Gc<[T]>` is not a type"); + span_err!(this.tcx().sess, path.span, E0115, + "`Gc<[T]>` is not a type"); ty::mk_err() } _ => ty::mk_box(this.tcx(), typ), diff --git a/src/librustc/middle/typeck/check/vtable.rs b/src/librustc/middle/typeck/check/vtable.rs index d2a1ef786bd..07e5e10e34c 100644 --- a/src/librustc/middle/typeck/check/vtable.rs +++ b/src/librustc/middle/typeck/check/vtable.rs @@ -203,11 +203,10 @@ fn relate_trait_refs(vcx: &VtableContext, !ty::trait_ref_contains_error(&r_exp_trait_ref) { let tcx = vcx.tcx(); - tcx.sess.span_err(span, - format!("expected {}, but found {} ({})", - ppaux::trait_ref_to_string(tcx, &r_exp_trait_ref), - ppaux::trait_ref_to_string(tcx, &r_act_trait_ref), - ty::type_err_to_str(tcx, err)).as_slice()); + span_err!(tcx.sess, span, E0095, "expected {}, but found {} ({})", + ppaux::trait_ref_to_string(tcx, &r_exp_trait_ref), + ppaux::trait_ref_to_string(tcx, &r_act_trait_ref), + ty::type_err_to_str(tcx, err)); } } } @@ -449,7 +448,8 @@ fn search_for_vtable(vcx: &VtableContext, 1 => return Some(found.get(0).clone()), _ => { if !is_early { - vcx.tcx().sess.span_err(span, "multiple applicable methods in scope"); + span_err!(vcx.tcx().sess, span, E0096, + "multiple applicable methods in scope"); } return Some(found.get(0).clone()); } @@ -544,9 +544,7 @@ pub fn early_resolve_expr(ex: &ast::Expr, fcx: &FnCtxt, is_early: bool) { if !mutability_allowed(mt.mutbl, mutbl) => { match ty::get(ty).sty { ty::ty_trait(..) => { - fcx.tcx() - .sess - .span_err(ex.span, "types differ in mutability"); + span_err!(fcx.tcx().sess, ex.span, E0097, "types differ in mutability"); } _ => {} } @@ -622,11 +620,9 @@ pub fn early_resolve_expr(ex: &ast::Expr, fcx: &FnCtxt, is_early: bool) { (&ty::ty_uniq(ty), _) => { match ty::get(ty).sty { ty::ty_trait(..) => { - fcx.ccx.tcx.sess.span_err( - ex.span, - format!("can only cast an boxed pointer \ - to a boxed object, not a {}", - ty::ty_sort_string(fcx.tcx(), src_ty)).as_slice()); + span_err!(fcx.ccx.tcx.sess, ex.span, E0098, + "can only cast an boxed pointer to a boxed object, not a {}", + ty::ty_sort_string(fcx.tcx(), src_ty)); } _ => {} } @@ -635,11 +631,9 @@ pub fn early_resolve_expr(ex: &ast::Expr, fcx: &FnCtxt, is_early: bool) { (&ty::ty_rptr(_, ty::mt{ty, ..}), _) => { match ty::get(ty).sty { ty::ty_trait(..) => { - fcx.ccx.tcx.sess.span_err( - ex.span, - format!("can only cast an &-pointer \ - to an &-object, not a {}", - ty::ty_sort_string(fcx.tcx(), src_ty)).as_slice()); + span_err!(fcx.ccx.tcx.sess, ex.span, E0099, + "can only cast an &-pointer to an &-object, not a {}", + ty::ty_sort_string(fcx.tcx(), src_ty)); } _ => {} } diff --git a/src/librustc/middle/typeck/check/writeback.rs b/src/librustc/middle/typeck/check/writeback.rs index 59b65fdbec7..8d7b11bf731 100644 --- a/src/librustc/middle/typeck/check/writeback.rs +++ b/src/librustc/middle/typeck/check/writeback.rs @@ -237,9 +237,8 @@ impl<'cx> WritebackCx<'cx> { Some(&def::DefStruct(_)) => { } _ => { - self.tcx().sess.span_err( - reason.span(self.tcx()), - "cannot coerce non-statically resolved bare fn") + span_err!(self.tcx().sess, reason.span(self.tcx()), E0100, + "cannot coerce non-statically resolved bare fn"); } } @@ -399,47 +398,34 @@ impl<'cx> Resolver<'cx> { if !self.tcx.sess.has_errors() { match self.reason { ResolvingExpr(span) => { - self.tcx.sess.span_err( - span, - format!("cannot determine a type for \ - this expression: {}", - infer::fixup_err_to_string(e)).as_slice()) + span_err!(self.tcx.sess, span, E0101, + "cannot determine a type for this expression: {}", + infer::fixup_err_to_string(e)); } ResolvingLocal(span) => { - self.tcx.sess.span_err( - span, - format!("cannot determine a type for \ - this local variable: {}", - infer::fixup_err_to_string(e)).as_slice()) + span_err!(self.tcx.sess, span, E0102, + "cannot determine a type for this local variable: {}", + infer::fixup_err_to_string(e)); } ResolvingPattern(span) => { - self.tcx.sess.span_err( - span, - format!("cannot determine a type for \ - this pattern binding: {}", - infer::fixup_err_to_string(e)).as_slice()) + span_err!(self.tcx.sess, span, E0103, + "cannot determine a type for this pattern binding: {}", + infer::fixup_err_to_string(e)); } ResolvingUpvar(upvar_id) => { let span = self.reason.span(self.tcx); - self.tcx.sess.span_err( - span, - format!("cannot resolve lifetime for \ - captured variable `{}`: {}", - ty::local_var_name_str( - self.tcx, - upvar_id.var_id).get().to_string(), - infer::fixup_err_to_string(e)).as_slice()); + span_err!(self.tcx.sess, span, E0104, + "cannot resolve lifetime for captured variable `{}`: {}", + ty::local_var_name_str(self.tcx, upvar_id.var_id).get().to_string(), + infer::fixup_err_to_string(e)); } ResolvingImplRes(span) => { - self.tcx - .sess - .span_err(span, - "cannot determine a type for impl \ - supertrait"); + span_err!(self.tcx.sess, span, E0105, + "cannot determine a type for impl supertrait"); } } } diff --git a/src/librustc/middle/typeck/coherence.rs b/src/librustc/middle/typeck/coherence.rs index b9bf8e37dea..5c290151373 100644 --- a/src/librustc/middle/typeck/coherence.rs +++ b/src/librustc/middle/typeck/coherence.rs @@ -221,10 +221,10 @@ impl<'a> visit::Visitor<()> for PrivilegedScopeVisitor<'a> { if !self.cc.ast_type_is_defined_in_local_crate(&**ast_ty) { // This is an error. let session = &self.cc.crate_context.tcx.sess; - session.span_err(item.span, - "cannot associate methods with a type outside the \ - crate the type is defined in; define and implement \ - a trait or new type instead"); + span_err!(session, item.span, E0116, + "cannot associate methods with a type outside the \ + crate the type is defined in; define and implement \ + a trait or new type instead"); } } ItemImpl(_, Some(ref trait_ref), _, _) => { @@ -241,9 +241,9 @@ impl<'a> visit::Visitor<()> for PrivilegedScopeVisitor<'a> { if trait_def_id.krate != LOCAL_CRATE { let session = &self.cc.crate_context.tcx.sess; - session.span_err(item.span, - "cannot provide an extension implementation \ - where both trait and type are not defined in this crate"); + span_err!(session, item.span, E0117, + "cannot provide an extension implementation \ + where both trait and type are not defined in this crate"); } } @@ -299,9 +299,9 @@ impl<'a> CoherenceChecker<'a> { self_type.ty) { None => { let session = &self.crate_context.tcx.sess; - session.span_err(item.span, - "no base type found for inherent implementation; \ - implement a trait or new type instead"); + span_err!(session, item.span, E0118, + "no base type found for inherent implementation; \ + implement a trait or new type instead"); } Some(_) => { // Nothing to do. @@ -438,22 +438,18 @@ impl<'a> CoherenceChecker<'a> { if self.polytypes_unify(polytype_a.clone(), polytype_b) { let session = &self.crate_context.tcx.sess; - session.span_err( - self.span_of_impl(impl_a), - format!("conflicting implementations for trait `{}`", - ty::item_path_str( - self.crate_context.tcx, - trait_def_id)).as_slice()); + span_err!(session, self.span_of_impl(impl_a), E0119, + "conflicting implementations for trait `{}`", + ty::item_path_str(self.crate_context.tcx, trait_def_id)); if impl_b.krate == LOCAL_CRATE { - session.span_note(self.span_of_impl(impl_b), - "note conflicting implementation here"); + span_note!(session, self.span_of_impl(impl_b), + "note conflicting implementation here"); } else { let crate_store = &self.crate_context.tcx.sess.cstore; let cdata = crate_store.get_crate_data(impl_b.krate); - session.note( - format!("conflicting implementation in crate \ - `{}`", - cdata.name).as_slice()); + span_note!(session, self.span_of_impl(impl_a), + "conflicting implementation in crate `{}`", + cdata.name); } } } @@ -702,10 +698,8 @@ impl<'a> CoherenceChecker<'a> { { match tcx.map.find(impl_did.node) { Some(ast_map::NodeItem(item)) => { - tcx.sess.span_err((*item).span, - "the Drop trait may \ - only be implemented \ - on structures"); + span_err!(tcx.sess, item.span, E0120, + "the Drop trait may only be implemented on structures"); } _ => { tcx.sess.bug("didn't find impl in ast \ diff --git a/src/librustc/middle/typeck/collect.rs b/src/librustc/middle/typeck/collect.rs index 906cc1e0255..a0d2171c091 100644 --- a/src/librustc/middle/typeck/collect.rs +++ b/src/librustc/middle/typeck/collect.rs @@ -140,9 +140,8 @@ impl<'a> AstConv for CrateCtxt<'a> { } fn ty_infer(&self, span: Span) -> ty::t { - self.tcx.sess.span_err(span, "the type placeholder `_` is not \ - allowed within types on item \ - signatures."); + span_err!(self.tcx.sess, span, E0121, + "the type placeholder `_` is not allowed within types on item signatures."); ty::mk_err() } } @@ -417,10 +416,8 @@ pub fn ensure_no_ty_param_bounds(ccx: &CrateCtxt, thing: &'static str) { for ty_param in generics.ty_params.iter() { if ty_param.bounds.len() > 0 { - ccx.tcx.sess.span_err( - span, - format!("trait bounds are not allowed in {} definitions", - thing).as_slice()); + span_err!(ccx.tcx.sess, span, E0122, + "trait bounds are not allowed in {} definitions", thing); } } } @@ -431,8 +428,8 @@ fn ensure_generics_abi(ccx: &CrateCtxt, generics: &ast::Generics) { if generics.ty_params.len() > 0 && !(abi == abi::Rust || abi == abi::RustIntrinsic) { - ccx.tcx.sess.span_err(span, - "foreign functions may not use type parameters"); + span_err!(ccx.tcx.sess, span, E0123, + "foreign functions may not use type parameters"); } } @@ -585,12 +582,10 @@ pub fn convert_struct(ccx: &CrateCtxt, if result.name != special_idents::unnamed_field.name { let dup = match seen_fields.find(&result.name) { Some(prev_span) => { - tcx.sess.span_err( - f.span, - format!("field `{}` is already declared", - token::get_name(result.name)).as_slice()); - tcx.sess.span_note(*prev_span, - "previously declared here"); + span_err!(tcx.sess, f.span, E0124, + "field `{}` is already declared", + token::get_name(result.name)); + span_note!(tcx.sess, *prev_span, "previously declared here"); true }, None => false, @@ -619,9 +614,9 @@ pub fn convert_struct(ccx: &CrateCtxt, Some(ast_map::NodeItem(i)) => match i.node { ast::ItemStruct(struct_def, _) => { if !struct_def.is_virtual { - tcx.sess.span_err(t.span, - "struct inheritance is only \ - allowed from virtual structs"); + span_err!(tcx.sess, t.span, E0126, + "struct inheritance is only \ + allowed from virtual structs"); } }, _ => {}, @@ -840,8 +835,8 @@ pub fn trait_def_of_item(ccx: &CrateCtxt, it: &ast::Item) -> Rc { { // This means a trait inherited from the same // supertrait more than once. - tcx.sess.span_err(sp, "duplicate supertrait in \ - trait declaration"); + span_err!(tcx.sess, sp, E0127, + "duplicate supertrait in trait declaration"); break; } else { ty_trait_refs.push(trait_ref); @@ -1107,10 +1102,9 @@ fn ty_generics(ccx: &CrateCtxt, ty::walk_ty(ty, |t| { match ty::get(t).sty { ty::ty_param(p) => if p.idx > cur_idx { - ccx.tcx.sess.span_err( - path.span, - "type parameters with a default cannot use \ - forward declared identifiers") + span_err!(ccx.tcx.sess, path.span, E0128, + "type parameters with a default cannot use \ + forward declared identifiers"); }, _ => {} } @@ -1217,12 +1211,11 @@ fn ty_generics(ccx: &CrateCtxt, |trait_ref| { let trait_def = ty::lookup_trait_def(tcx, trait_ref.def_id); if trait_def.bounds.contains_elem(ty::BoundSized) { - tcx.sess.span_err(span, - format!("incompatible bounds on type parameter {}, \ - bound {} does not allow unsized type", - token::get_ident(ident), - ppaux::trait_ref_to_string(tcx, - &*trait_ref)).as_slice()); + span_err!(tcx.sess, span, E0129, + "incompatible bounds on type parameter {}, \ + bound {} does not allow unsized type", + token::get_ident(ident), + ppaux::trait_ref_to_string(tcx, &*trait_ref)); } true }); @@ -1241,8 +1234,10 @@ pub fn ty_of_foreign_fn_decl(ccx: &CrateCtxt, match (*i).pat.node { ast::PatIdent(_, _, _) => (), ast::PatWild => (), - _ => ccx.tcx.sess.span_err((*i).pat.span, - "patterns aren't allowed in foreign function declarations") + _ => { + span_err!(ccx.tcx.sess, (*i).pat.span, E0130, + "patterns aren't allowed in foreign function declarations"); + } } } diff --git a/src/librustc/middle/typeck/mod.rs b/src/librustc/middle/typeck/mod.rs index ad6864ba487..086b17db734 100644 --- a/src/librustc/middle/typeck/mod.rs +++ b/src/librustc/middle/typeck/mod.rs @@ -359,9 +359,8 @@ fn check_main_fn_ty(ccx: &CrateCtxt, match it.node { ast::ItemFn(_, _, _, ref ps, _) if ps.is_parameterized() => { - tcx.sess.span_err( - main_span, - "main function is not allowed to have type parameters"); + span_err!(ccx.tcx.sess, main_span, E0131, + "main function is not allowed to have type parameters"); return; } _ => () @@ -408,9 +407,8 @@ fn check_start_fn_ty(ccx: &CrateCtxt, match it.node { ast::ItemFn(_,_,_,ref ps,_) if ps.is_parameterized() => { - tcx.sess.span_err( - start_span, - "start function is not allowed to have type parameters"); + span_err!(tcx.sess, start_span, E0132, + "start function is not allowed to have type parameters"); return; } _ => () diff --git a/src/libsyntax/diagnostics/macros.rs b/src/libsyntax/diagnostics/macros.rs index b4af7205c42..4db5b93862f 100644 --- a/src/libsyntax/diagnostics/macros.rs +++ b/src/libsyntax/diagnostics/macros.rs @@ -44,24 +44,24 @@ macro_rules! __diagnostic_used( #[macro_export] macro_rules! span_err( - ($session:expr, $span:expr, $code:ident, $($arg:expr),*) => ({ + ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ __diagnostic_used!($code); - ($session).span_err_with_code($span, format!($($arg),*).as_slice(), stringify!($code)) + $session.span_err_with_code($span, format!($($message)*).as_slice(), stringify!($code)) }) ) #[macro_export] macro_rules! span_warn( - ($session:expr, $span:expr, $code:ident, $($arg:expr),*) => ({ + ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ __diagnostic_used!($code); - ($session).span_warn_with_code($span, format!($($arg),*).as_slice(), stringify!($code)) + $session.span_warn_with_code($span, format!($($message)*).as_slice(), stringify!($code)) }) ) #[macro_export] macro_rules! span_note( - ($session:expr, $span:expr, $($arg:expr),*) => ({ - ($session).span_note($span, format!($($arg),*).as_slice()) + ($session:expr, $span:expr, $($message:tt)*) => ({ + ($session).span_note($span, format!($($message)*).as_slice()) }) ) diff --git a/src/test/compile-fail/multiple-main-2.rs b/src/test/compile-fail/multiple-main-2.rs index 723aefb91cb..e3dbc67b7a9 100644 --- a/src/test/compile-fail/multiple-main-2.rs +++ b/src/test/compile-fail/multiple-main-2.rs @@ -13,5 +13,5 @@ fn bar() { } #[main] -fn foo() { //~ ERROR multiple 'main' functions +fn foo() { //~ ERROR multiple functions with a #[main] attribute } diff --git a/src/test/compile-fail/multiple-main-3.rs b/src/test/compile-fail/multiple-main-3.rs index 36da3e6e84a..58cc148568e 100644 --- a/src/test/compile-fail/multiple-main-3.rs +++ b/src/test/compile-fail/multiple-main-3.rs @@ -14,6 +14,6 @@ fn main1() { mod foo { #[main] - fn main2() { //~ ERROR multiple 'main' functions + fn main2() { //~ ERROR multiple functions with a #[main] attribute } }