]> git.lizzy.rs Git - rust.git/commitdiff
Add error codes to rustc
authorBrian Anderson <banderson@mozilla.com>
Mon, 19 Jan 2015 00:58:25 +0000 (16:58 -0800)
committerBrian Anderson <banderson@mozilla.com>
Tue, 20 Jan 2015 19:27:51 +0000 (11:27 -0800)
12 files changed:
src/librustc/diagnostics.rs
src/librustc/middle/check_loop.rs
src/librustc/middle/check_match.rs
src/librustc/middle/check_static_recursion.rs
src/librustc/middle/infer/error_reporting.rs
src/librustc/middle/liveness.rs
src/librustc/middle/recursion_limit.rs
src/librustc/middle/resolve_lifetime.rs
src/librustc/middle/traits/error_reporting.rs
src/librustc/middle/traits/mod.rs
src/librustc/middle/ty.rs
src/librustc/middle/weak_lang_items.rs

index c3b87fdd8aaf6476c7de32ca3e270bbee7cf8cc9..1dbd6eb4e8d5a06e51eb2b411192e517e6485a2e 100644 (file)
     E0161,
     E0162,
     E0165,
-    E0170
+    E0170,
+    E0261, // use of undeclared lifetime name
+    E0262, // illegal lifetime parameter name
+    E0263, // lifetime name declared twice in same scope
+    E0264, // unknown external lang item
+    E0265, // recursive constant
+    E0266, // expected item
+    E0267, // thing inside of a closure
+    E0268, // thing outside of a loop
+    E0269, // not all control paths return a value
+    E0270, // computation may converge in a function marked as diverging
+    E0271, // type mismatch resolving
+    E0272, // rustc_on_unimplemented attribute refers to non-existent type parameter
+    E0273, // rustc_on_unimplemented must have named format arguments
+    E0274, // rustc_on_unimplemented must have a value
+    E0275, // overflow evaluating requirement
+    E0276, // requirement appears on impl method but not on corresponding trait method
+    E0277, // trait is not implemented for type
+    E0278, // requirement is not satisfied
+    E0279, // requirement is not satisfied
+    E0280, // requirement is not satisfied
+    E0281, // type implements trait but other trait is required
+    E0282, // unable to infer enough type information about
+    E0283, // cannot resolve type
+    E0284, // cannot resolve type
+    E0285, // overflow evaluation builtin bounds
+    E0296, // malformed recursion limit attribute
+    E0297, // refutable pattern in for loop binding
+    E0298, // mismatched types between arms
+    E0299, // mismatched types between arms
+    E0300, // unexpanded macro
+    E0301, // cannot mutable borrow in a pattern guard
+    E0302, // cannot assign in a pattern guard
+    E0303, // pattern bindings are not allowed after an `@`
+    E0304, // expected signed integer constant
+    E0305, // expected constant
+    E0306, // expected positive integer for repeat count
+    E0307, // expected constant integer for repeat count
+    E0308,
+    E0309, // thing may not live long enough
+    E0310, // thing may not live long enough
+    E0311, // thing may not live long enough
+    E0312, // lifetime of reference outlives lifetime of borrowed content
+    E0313, // lifetime of borrowed pointer outlives lifetime of captured variable
+    E0314, // closure outlives stack frame
+    E0315 // cannot invoke closure outside of its lifetime
 }
 
 __build_diagnostic_array! { DIAGNOSTICS }
index 1f779acac2503b10285a8f9762fa2becad809772..623f3525d4a90b3111740d20ce7e43b51d50c38a 100644 (file)
@@ -73,12 +73,12 @@ fn require_loop(&self, name: &str, span: Span) {
         match self.cx {
             Loop => {}
             Closure => {
-                self.sess.span_err(span,
-                                   &format!("`{}` inside of a closure", name)[]);
+                span_err!(self.sess, span, E0267,
+                                   "`{}` inside of a closure", name);
             }
             Normal => {
-                self.sess.span_err(span,
-                                   &format!("`{}` outside of loop", name)[]);
+                span_err!(self.sess, span, E0268,
+                                   "`{}` outside of loop", name);
             }
         }
     }
index a1a90395b3b783306c08c7a9f488348694a53a58..f6db0cf755b9c9b4318dda54465c4e03c4dc204d 100644 (file)
@@ -226,11 +226,10 @@ fn check_expr(cx: &mut MatchCheckCtxt, ex: &ast::Expr) {
         ast::ExprForLoop(ref pat, _, _, _) => {
             let mut static_inliner = StaticInliner::new(cx.tcx);
             is_refutable(cx, &*static_inliner.fold_pat((*pat).clone()), |uncovered_pat| {
-                cx.tcx.sess.span_err(
-                    pat.span,
-                    &format!("refutable pattern in `for` loop binding: \
+                span_err!(cx.tcx.sess, pat.span, E0297,
+                    "refutable pattern in `for` loop binding: \
                             `{}` not covered",
-                            pat_to_string(uncovered_pat))[]);
+                            pat_to_string(uncovered_pat));
             });
 
             // Check legality of move bindings.
@@ -869,7 +868,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
                 Some(true) => Some(vec![]),
                 Some(false) => None,
                 None => {
-                    cx.tcx.sess.span_err(pat_span, "mismatched types between arms");
+                    span_err!(cx.tcx.sess, pat_span, E0298, "mismatched types between arms");
                     None
                 }
             }
@@ -882,7 +881,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
                 Some(true) => Some(vec![]),
                 Some(false) => None,
                 None => {
-                    cx.tcx.sess.span_err(pat_span, "mismatched types between arms");
+                    span_err!(cx.tcx.sess, pat_span, E0299, "mismatched types between arms");
                     None
                 }
             }
@@ -921,7 +920,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
         }
 
         ast::PatMac(_) => {
-            cx.tcx.sess.span_err(pat_span, "unexpanded macro");
+            span_err!(cx.tcx.sess, pat_span, E0300, "unexpanded macro");
             None
         }
     };
@@ -1082,11 +1081,8 @@ fn borrow(&mut self,
               _: LoanCause) {
         match kind {
             MutBorrow => {
-                self.cx
-                    .tcx
-                    .sess
-                    .span_err(span,
-                              "cannot mutably borrow in a pattern guard")
+                span_err!(self.cx.tcx.sess, span, E0301,
+                          "cannot mutably borrow in a pattern guard")
             }
             ImmBorrow | UniqueImmBorrow => {}
         }
@@ -1095,10 +1091,7 @@ fn decl_without_init(&mut self, _: NodeId, _: Span) {}
     fn mutate(&mut self, _: NodeId, span: Span, _: cmt, mode: MutateMode) {
         match mode {
             JustWrite | WriteAndRead => {
-                self.cx
-                    .tcx
-                    .sess
-                    .span_err(span, "cannot assign in a pattern guard")
+                span_err!(self.cx.tcx.sess, span, E0302, "cannot assign in a pattern guard")
             }
             Init => {}
         }
@@ -1120,7 +1113,7 @@ struct AtBindingPatternVisitor<'a, 'b:'a, 'tcx:'b> {
 impl<'a, 'b, 'tcx, 'v> Visitor<'v> for AtBindingPatternVisitor<'a, 'b, 'tcx> {
     fn visit_pat(&mut self, pat: &Pat) {
         if !self.bindings_allowed && pat_is_binding(&self.cx.tcx.def_map, pat) {
-            self.cx.tcx.sess.span_err(pat.span,
+            span_err!(self.cx.tcx.sess, pat.span, E0303,
                                       "pattern bindings are not allowed \
                                        after an `@`");
         }
index 86a58dae45aa4c96676b6df893f1a8a2ba46a0c5..4280b7fe3f09649170a73dc7e37f90873a22fa9f 100644 (file)
@@ -83,7 +83,7 @@ pub fn check_item_recursion<'a>(sess: &'a Session,
 impl<'a, 'ast, 'v> Visitor<'v> for CheckItemRecursionVisitor<'a, 'ast> {
     fn visit_item(&mut self, it: &ast::Item) {
         if self.idstack.iter().any(|x| x == &(it.id)) {
-            self.sess.span_err(self.root_it.span, "recursive constant");
+            span_err!(self.sess, self.root_it.span, E0265, "recursive constant");
             return;
         }
         self.idstack.push(it.id);
@@ -103,9 +103,9 @@ fn visit_expr(&mut self, e: &ast::Expr) {
                             self.visit_item(item),
                           ast_map::NodeForeignItem(_) => {},
                           _ => {
-                            self.sess.span_err(e.span,
-                              &format!("expected item, found {}",
-                                      self.ast_map.node_to_string(def_id.node))[]);
+                            span_err!(self.sess, e.span, E0266,
+                              "expected item, found {}",
+                                      self.ast_map.node_to_string(def_id.node));
                             return;
                           },
                         }
index 1b9d6ec6c33b694162c4451075d24838b7e2f9fb..18c36f870b5bce09da24a3222f81d46bc56a487f 100644 (file)
@@ -371,12 +371,11 @@ fn report_type_error(&self, trace: TypeTrace<'tcx>, terr: &ty::type_err<'tcx>) {
             infer::EquatePredicate(_) => "equality predicate not satisfied",
         };
 
-        self.tcx.sess.span_err(
-            trace.origin.span(),
-            &format!("{}: {} ({})",
+        span_err!(self.tcx.sess, trace.origin.span(), E0308,
+            "{}: {} ({})",
                  message_root_str,
                  expected_found_str,
-                 ty::type_err_to_str(self.tcx, terr))[]);
+                 ty::type_err_to_str(self.tcx, terr));
 
         match trace.origin {
             infer::MatchExpressionArm(_, arm_span) =>
@@ -443,9 +442,8 @@ fn report_generic_bound_failure(&self,
         match sub {
             ty::ReFree(ty::FreeRegion {bound_region: ty::BrNamed(..), ..}) => {
                 // Does the required lifetime have a nice name we can print?
-                self.tcx.sess.span_err(
-                    origin.span(),
-                    &format!("{} may not live long enough", labeled_user_string)[]);
+                span_err!(self.tcx.sess, origin.span(), E0309,
+                    "{} may not live long enough", labeled_user_string);
                 self.tcx.sess.span_help(
                     origin.span(),
                     &format!(
@@ -456,9 +454,8 @@ fn report_generic_bound_failure(&self,
 
             ty::ReStatic => {
                 // Does the required lifetime have a nice name we can print?
-                self.tcx.sess.span_err(
-                    origin.span(),
-                    &format!("{} may not live long enough", labeled_user_string)[]);
+                span_err!(self.tcx.sess, origin.span(), E0310,
+                    "{} may not live long enough", labeled_user_string);
                 self.tcx.sess.span_help(
                     origin.span(),
                     &format!(
@@ -468,11 +465,9 @@ fn report_generic_bound_failure(&self,
 
             _ => {
                 // If not, be less specific.
-                self.tcx.sess.span_err(
-                    origin.span(),
-                    &format!(
+                span_err!(self.tcx.sess, origin.span(), E0311,
                         "{} may not live long enough",
-                        labeled_user_string)[]);
+                        labeled_user_string);
                 self.tcx.sess.span_help(
                     origin.span(),
                     &format!(
@@ -499,8 +494,7 @@ fn report_concrete_failure(&self,
                 self.report_and_explain_type_error(trace, &terr);
             }
             infer::Reborrow(span) => {
-                self.tcx.sess.span_err(
-                    span,
+                span_err!(self.tcx.sess, span, E0312,
                     "lifetime of reference outlines \
                      lifetime of borrowed content...");
                 note_and_explain_region(
@@ -515,14 +509,13 @@ fn report_concrete_failure(&self,
                     "");
             }
             infer::ReborrowUpvar(span, ref upvar_id) => {
-                self.tcx.sess.span_err(
-                    span,
-                    &format!("lifetime of borrowed pointer outlives \
+                span_err!(self.tcx.sess, span, E0313,
+                    "lifetime of borrowed pointer outlives \
                             lifetime of captured variable `{}`...",
                             ty::local_var_name_str(self.tcx,
                                                    upvar_id.var_id)
                                 .get()
-                                .to_string())[]);
+                                .to_string());
                 note_and_explain_region(
                     self.tcx,
                     "...the borrowed pointer is valid for ",
@@ -539,8 +532,7 @@ fn report_concrete_failure(&self,
                     "");
             }
             infer::InfStackClosure(span) => {
-                self.tcx.sess.span_err(
-                    span,
+                span_err!(self.tcx.sess, span, E0314,
                     "closure outlives stack frame");
                 note_and_explain_region(
                     self.tcx,
@@ -554,8 +546,7 @@ fn report_concrete_failure(&self,
                     "");
             }
             infer::InvokeClosure(span) => {
-                self.tcx.sess.span_err(
-                    span,
+                span_err!(self.tcx.sess, span, E0315,
                     "cannot invoke closure outside of its lifetime");
                 note_and_explain_region(
                     self.tcx,
index 27a0324a3c4135178d5d39096198c0aff9b95f00..f71779e23333f80d6de43509b86b86c0b1a0ba38 100644 (file)
@@ -1557,8 +1557,7 @@ fn check_ret(&self,
                             },
                         _ => false
                     };
-                    self.ir.tcx.sess.span_err(
-                        sp, "not all control paths return a value");
+                    span_err!(self.ir.tcx.sess, sp, E0269, "not all control paths return a value");
                     if ends_with_stmt {
                         let last_stmt = body.stmts.first().unwrap();
                         let original_span = original_sp(self.ir.tcx.sess.codemap(),
@@ -1575,7 +1574,7 @@ fn check_ret(&self,
             }
             ty::FnDiverging
                 if self.live_on_entry(entry_ln, self.s.clean_exit_var).is_some() => {
-                    self.ir.tcx.sess.span_err(sp,
+                    span_err!(self.ir.tcx.sess, sp, E0270,
                         "computation may converge in a function marked as diverging");
                 }
 
index 017641bd3b71aeb6cbf4f6fbe75412c9fc2c6e4d..81cbdf13c518925c60ef57b9b1d260a42fb8b870 100644 (file)
@@ -33,7 +33,7 @@ pub fn update_recursion_limit(sess: &Session, krate: &ast::Crate) {
             }
         }
 
-        sess.span_err(attr.span, "malformed recursion limit attribute, \
+        span_err!(sess, attr.span, E0296, "malformed recursion limit attribute, \
                                   expected #![recursion_limit=\"N\"]");
     }
 }
index eff0018becc01c8fa822b0b03deae2ab571136b1..be2b3026755b203ea9a433b89513c99f5d3fc012 100644 (file)
@@ -396,10 +396,9 @@ fn resolve_free_lifetime_ref(&mut self,
     }
 
     fn unresolved_lifetime_ref(&self, lifetime_ref: &ast::Lifetime) {
-        self.sess.span_err(
-            lifetime_ref.span,
-            &format!("use of undeclared lifetime name `{}`",
-                    token::get_name(lifetime_ref.name))[]);
+        span_err!(self.sess, lifetime_ref.span, E0261,
+            "use of undeclared lifetime name `{}`",
+                    token::get_name(lifetime_ref.name));
     }
 
     fn check_lifetime_defs(&mut self, old_scope: Scope, lifetimes: &Vec<ast::LifetimeDef>) {
@@ -409,11 +408,9 @@ fn check_lifetime_defs(&mut self, old_scope: Scope, lifetimes: &Vec<ast::Lifetim
             let special_idents = [special_idents::static_lifetime];
             for lifetime in lifetimes.iter() {
                 if special_idents.iter().any(|&i| i.name == lifetime.lifetime.name) {
-                    self.sess.span_err(
-                        lifetime.lifetime.span,
-                        &format!("illegal lifetime parameter name: `{}`",
-                                token::get_name(lifetime.lifetime.name))
-                        []);
+                    span_err!(self.sess, lifetime.lifetime.span, E0262,
+                        "illegal lifetime parameter name: `{}`",
+                                token::get_name(lifetime.lifetime.name));
                 }
             }
 
@@ -422,12 +419,10 @@ fn check_lifetime_defs(&mut self, old_scope: Scope, lifetimes: &Vec<ast::Lifetim
                 let lifetime_j = &lifetimes[j];
 
                 if lifetime_i.lifetime.name == lifetime_j.lifetime.name {
-                    self.sess.span_err(
-                        lifetime_j.lifetime.span,
-                        &format!("lifetime name `{}` declared twice in \
+                    span_err!(self.sess, lifetime_j.lifetime.span, E0263,
+                        "lifetime name `{}` declared twice in \
                                 the same scope",
-                                token::get_name(lifetime_j.lifetime.name))
-                        []);
+                                token::get_name(lifetime_j.lifetime.name));
                 }
             }
 
index 6d0e60ec495a7bee25ea3fe8249befef125adf29..93805750606efa8afe4e511b9e99d489afc0b9ca 100644 (file)
@@ -55,12 +55,10 @@ pub fn report_projection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
     let predicate =
         infcx.resolve_type_vars_if_possible(&obligation.predicate);
     if !predicate.references_error() {
-        infcx.tcx.sess.span_err(
-            obligation.cause.span,
-            format!(
+        span_err!(infcx.tcx.sess, obligation.cause.span, E0271,
                 "type mismatch resolving `{}`: {}",
                 predicate.user_string(infcx.tcx),
-                ty::type_err_to_str(infcx.tcx, &error.err)).as_slice());
+                ty::type_err_to_str(infcx.tcx, &error.err));
         note_obligation_cause(infcx, obligation);
     }
 }
@@ -97,28 +95,25 @@ fn report_on_unimplemented<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
                             Position::ArgumentNamed(s) => match generic_map.get(s) {
                                 Some(val) => Some(val.as_slice()),
                                 None => {
-                                    infcx.tcx.sess
-                                         .span_err(err_sp,
-                                                   format!("the #[rustc_on_unimplemented] \
+                                    span_err!(infcx.tcx.sess, err_sp, E0272,
+                                                   "the #[rustc_on_unimplemented] \
                                                             attribute on \
                                                             trait definition for {} refers to \
                                                             non-existent type parameter {}",
-                                                           trait_str, s)
-                                                   .as_slice());
+                                                           trait_str, s);
                                     errored = true;
                                     None
                                 }
                             },
                             _ => {
-                                infcx.tcx.sess
-                                     .span_err(err_sp,
-                                               format!("the #[rustc_on_unimplemented] \
+                                     span_err!(infcx.tcx.sess, err_sp, E0273,
+                                               "the #[rustc_on_unimplemented] \
                                                         attribute on \
                                                         trait definition for {} must have named \
                                                         format arguments, \
                                                         eg `#[rustc_on_unimplemented = \
                                                         \"foo {{T}}\"]`",
-                                                       trait_str).as_slice());
+                                                       trait_str);
                                 errored = true;
                                 None
                             }
@@ -130,11 +125,11 @@ trait definition for {} must have named \
                     report = Some(err);
                 }
             } else {
-                infcx.tcx.sess.span_err(err_sp,
-                                        format!("the #[rustc_on_unimplemented] attribute on \
+                span_err!(infcx.tcx.sess, err_sp, E0274,
+                                        "the #[rustc_on_unimplemented] attribute on \
                                                  trait definition for {} must have a value, \
                                                  eg `#[rustc_on_unimplemented = \"foo\"]`",
-                                                 trait_str).as_slice());
+                                                 trait_str);
             }
             break;
         }
@@ -151,11 +146,9 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
             // We could track the stack here more precisely if we wanted, I imagine.
             let predicate =
                 infcx.resolve_type_vars_if_possible(&obligation.predicate);
-            infcx.tcx.sess.span_err(
-                obligation.cause.span,
-                format!(
+            span_err!(infcx.tcx.sess, obligation.cause.span, E0275,
                     "overflow evaluating the requirement `{}`",
-                    predicate.user_string(infcx.tcx)).as_slice());
+                    predicate.user_string(infcx.tcx));
 
             suggest_new_overflow_limit(infcx.tcx, obligation.cause.span);
 
@@ -165,12 +158,10 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
         SelectionError::Unimplemented => {
             match &obligation.cause.code {
                 &ObligationCauseCode::CompareImplMethodObligation => {
-                    infcx.tcx.sess.span_err(
-                        obligation.cause.span,
-                        format!(
+                    span_err!(infcx.tcx.sess, obligation.cause.span, E0276,
                             "the requirement `{}` appears on the impl \
                             method but not on the corresponding trait method",
-                            obligation.predicate.user_string(infcx.tcx)).as_slice());
+                            obligation.predicate.user_string(infcx.tcx));;
                 }
                 _ => {
                     match obligation.predicate {
@@ -180,12 +171,10 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
 
                             if !trait_predicate.references_error() {
                                 let trait_ref = trait_predicate.to_poly_trait_ref();
-                                infcx.tcx.sess.span_err(
-                                    obligation.cause.span,
-                                    format!(
+                                span_err!(infcx.tcx.sess, obligation.cause.span, E0277,
                                         "the trait `{}` is not implemented for the type `{}`",
                                         trait_ref.user_string(infcx.tcx),
-                                        trait_ref.self_ty().user_string(infcx.tcx)).as_slice());
+                                        trait_ref.self_ty().user_string(infcx.tcx));
                                 // Check if it has a custom "#[rustc_on_unimplemented]"
                                 // error message, report with that message if it does
                                 let custom_note = report_on_unimplemented(infcx, &*trait_ref.0,
@@ -201,34 +190,28 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
                             let predicate = infcx.resolve_type_vars_if_possible(predicate);
                             let err = infcx.equality_predicate(obligation.cause.span,
                                                                &predicate).unwrap_err();
-                            infcx.tcx.sess.span_err(
-                                obligation.cause.span,
-                                format!(
+                            span_err!(infcx.tcx.sess, obligation.cause.span, E0278,
                                     "the requirement `{}` is not satisfied (`{}`)",
                                     predicate.user_string(infcx.tcx),
-                                    ty::type_err_to_str(infcx.tcx, &err)).as_slice());
+                                    ty::type_err_to_str(infcx.tcx, &err));
                         }
 
                         ty::Predicate::RegionOutlives(ref predicate) => {
                             let predicate = infcx.resolve_type_vars_if_possible(predicate);
                             let err = infcx.region_outlives_predicate(obligation.cause.span,
                                                                       &predicate).unwrap_err();
-                            infcx.tcx.sess.span_err(
-                                obligation.cause.span,
-                                format!(
+                            span_err!(infcx.tcx.sess, obligation.cause.span, E0279,
                                     "the requirement `{}` is not satisfied (`{}`)",
                                     predicate.user_string(infcx.tcx),
-                                    ty::type_err_to_str(infcx.tcx, &err)).as_slice());
+                                    ty::type_err_to_str(infcx.tcx, &err));
                         }
 
                         ty::Predicate::Projection(..) | ty::Predicate::TypeOutlives(..) => {
                                 let predicate =
                                     infcx.resolve_type_vars_if_possible(&obligation.predicate);
-                                infcx.tcx.sess.span_err(
-                                    obligation.cause.span,
-                                    format!(
+                                span_err!(infcx.tcx.sess, obligation.cause.span, E0280,
                                         "the requirement `{}` is not satisfied",
-                                        predicate.user_string(infcx.tcx)).as_slice());
+                                        predicate.user_string(infcx.tcx));
                         }
                     }
                 }
@@ -239,15 +222,13 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
             let expected_trait_ref = infcx.resolve_type_vars_if_possible(&*expected_trait_ref);
             let actual_trait_ref = infcx.resolve_type_vars_if_possible(&*actual_trait_ref);
             if !ty::type_is_error(actual_trait_ref.self_ty()) {
-                infcx.tcx.sess.span_err(
-                    obligation.cause.span,
-                    format!(
+                span_err!(infcx.tcx.sess, obligation.cause.span, E0281,
                         "type mismatch: the type `{}` implements the trait `{}`, \
                         but the trait `{}` is required ({})",
                         expected_trait_ref.self_ty().user_string(infcx.tcx),
                         expected_trait_ref.user_string(infcx.tcx),
                         actual_trait_ref.user_string(infcx.tcx),
-                        ty::type_err_to_str(infcx.tcx, e)).as_slice());
+                        ty::type_err_to_str(infcx.tcx, e));
                     note_obligation_cause(infcx, obligation);
             }
         }
@@ -293,18 +274,14 @@ pub fn maybe_report_ambiguity<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
                         infcx.tcx.lang_items.sized_trait()
                         .map_or(false, |sized_id| sized_id == trait_ref.def_id())
                     {
-                        infcx.tcx.sess.span_err(
-                            obligation.cause.span,
-                            format!(
+                        span_err!(infcx.tcx.sess, obligation.cause.span, E0282,
                                 "unable to infer enough type information about `{}`; \
                                  type annotations required",
-                                self_ty.user_string(infcx.tcx)).as_slice());
+                                self_ty.user_string(infcx.tcx));
                     } else {
-                        infcx.tcx.sess.span_err(
-                            obligation.cause.span,
-                            format!(
+                        span_err!(infcx.tcx.sess, obligation.cause.span, E0283,
                                 "type annotations required: cannot resolve `{}`",
-                                predicate.user_string(infcx.tcx)).as_slice());
+                                predicate.user_string(infcx.tcx));;
                         note_obligation_cause(infcx, obligation);
                     }
                 }
@@ -323,11 +300,9 @@ pub fn maybe_report_ambiguity<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
 
         _ => {
             if !infcx.tcx.sess.has_errors() {
-                infcx.tcx.sess.span_err(
-                    obligation.cause.span,
-                    format!(
+                span_err!(infcx.tcx.sess, obligation.cause.span, E0284,
                         "type annotations required: cannot resolve `{}`",
-                        predicate.user_string(infcx.tcx)).as_slice());
+                        predicate.user_string(infcx.tcx));;
                 note_obligation_cause(infcx, obligation);
             }
         }
index 425765edf870c5c30cd56a007ca2d2a3d7e639c6..89459f95b879fe730c020fc9ab88ae94309b54ba 100644 (file)
@@ -379,11 +379,10 @@ pub fn type_known_to_meet_builtin_bound<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>,
             false
         }
         Err(Overflow) => {
-            infcx.tcx.sess.span_err(
-                span,
-                format!("overflow evaluating whether `{}` is `{}`",
-                        ty.user_string(infcx.tcx),
-                        bound.user_string(infcx.tcx)).as_slice());
+            span_err!(infcx.tcx.sess, span, E0285,
+                "overflow evaluating whether `{}` is `{}`",
+                      ty.user_string(infcx.tcx),
+                      bound.user_string(infcx.tcx));
             suggest_new_overflow_limit(infcx.tcx, span);
             false
         }
index be6c6b9d34f3784caf6f3713739855531a35fb8f..e5bbd01dde67724c2817a6f58bc4868c04b321c6 100644 (file)
@@ -5369,15 +5369,13 @@ pub fn enum_variants<'tcx>(cx: &ctxt<'tcx>, id: ast::DefId)
                                                 discriminant = val as Disr
                                             }
                                             Ok(_) => {
-                                                cx.sess
-                                                  .span_err(e.span,
+                                                span_err!(cx.sess, e.span, E0304,
                                                             "expected signed integer constant");
                                             }
                                             Err(ref err) => {
-                                                cx.sess
-                                                  .span_err(e.span,
-                                                            &format!("expected constant: {}",
-                                                                    *err)[]);
+                                                span_err!(cx.sess, e.span, E0305,
+                                                            "expected constant: {}",
+                                                                    *err);
                                             }
                                         },
                                     None => {}
@@ -5851,9 +5849,9 @@ pub fn eval_repeat_count(tcx: &ctxt, count_expr: &ast::Expr) -> uint {
                 const_eval::const_binary(_) =>
                     "binary array"
             };
-            tcx.sess.span_err(count_expr.span, &format!(
+            span_err!(tcx.sess, count_expr.span, E0306,
                 "expected positive integer for repeat count, found {}",
-                found)[]);
+                found);
         }
         Err(_) => {
             let found = match count_expr.node {
@@ -5866,9 +5864,9 @@ pub fn eval_repeat_count(tcx: &ctxt, count_expr: &ast::Expr) -> uint {
                 _ =>
                     "non-constant expression"
             };
-            tcx.sess.span_err(count_expr.span, &format!(
+            span_err!(tcx.sess, count_expr.span, E0307,
                 "expected constant integer for repeat count, found {}",
-                found)[]);
+                found);
         }
     }
     0
index 892a8004fec1c99ecd4efae1b9d22fc7f6125de0..25cca98c5fb4788af7f1fce215b2444bb43f8579 100644 (file)
@@ -99,9 +99,9 @@ fn register(&mut self, name: &str, span: Span) {
                 self.items.missing.push(lang_items::$item);
             }
         } else)* {
-            self.sess.span_err(span,
-                               format!("unknown external lang item: `{}`",
-                                       name).as_slice());
+            span_err!(self.sess, span, E0264,
+                               "unknown external lang item: `{}`",
+                                       name);
         }
     }
 }