]> git.lizzy.rs Git - rust.git/commitdiff
Convert 15 diagnostics to have error codes (E0380-E0394).
authorNick Hamann <nick@wabbo.org>
Tue, 19 May 2015 21:53:34 +0000 (16:53 -0500)
committerNick Hamann <nick@wabbo.org>
Tue, 26 May 2015 20:12:52 +0000 (15:12 -0500)
Also adds explanations for E0380 and E0381.

src/librustc/diagnostics.rs
src/librustc/middle/check_const.rs
src/librustc_borrowck/borrowck/mod.rs
src/librustc_borrowck/diagnostics.rs
src/librustc_typeck/astconv.rs
src/librustc_typeck/check/wf.rs
src/librustc_typeck/coherence/orphan.rs
src/librustc_typeck/collect.rs
src/librustc_typeck/diagnostics.rs

index 0f950d7ceb3ab634cd9602e28310be45ac98daca..9d459027bf5cdfa7360281ceb1c78337ea0b74e9 100644 (file)
@@ -891,5 +891,7 @@ struct Foo<T: 'static> {
     E0315, // cannot invoke closure outside of its lifetime
     E0316, // nested quantification of lifetimes
     E0370, // discriminant overflow
-    E0378  // method calls limited to constant inherent methods
+    E0378, // method calls limited to constant inherent methods
+    E0394  // cannot refer to other statics by value, use the address-of
+           // operator or a constant instead
 }
index a70df34bd70a82037ad022031e5748cf493ff08d..c54517e00173b21f7fccd46c9b7b7f68139d4ede 100644 (file)
@@ -762,9 +762,9 @@ fn consume(&mut self,
                         // statics cannot be consumed by value at any time, that would imply
                         // that they're an initializer (what a const is for) or kept in sync
                         // over time (not feasible), so deny it outright.
-                        self.tcx.sess.span_err(consume_span,
-                            "cannot refer to other statics by value, use the \
-                             address-of operator or a constant instead");
+                        span_err!(self.tcx.sess, consume_span, E0394,
+                                  "cannot refer to other statics by value, use the \
+                                   address-of operator or a constant instead");
                     }
                     break;
                 }
index 27adf5bf21b63297a5491ba94efd3bea8f50867d..472aff6625bc70fbdee887760ce878ca2e12a545 100644 (file)
@@ -603,11 +603,12 @@ pub fn report_use_of_moved_value<'b>(&self,
 
         let (ol, moved_lp_msg) = match the_move.kind {
             move_data::Declared => {
-                self.tcx.sess.span_err(
-                    use_span,
-                    &format!("{} of possibly uninitialized variable: `{}`",
-                            verb,
-                            self.loan_path_to_string(lp)));
+                span_err!(
+                    self.tcx.sess, use_span, E0381,
+                    "{} of possibly uninitialized variable: `{}`",
+                    verb,
+                    self.loan_path_to_string(lp));
+
                 (self.loan_path_to_string(moved_lp),
                  String::new())
             }
@@ -644,12 +645,10 @@ pub fn report_use_of_moved_value<'b>(&self,
                 let msg = if !has_fork && partial { "partially " }
                           else if has_fork && !has_common { "collaterally "}
                           else { "" };
-                self.tcx.sess.span_err(
-                    use_span,
-                    &format!("{} of {}moved value: `{}`",
-                            verb,
-                            msg,
-                            nl));
+                span_err!(
+                    self.tcx.sess, use_span, E0382,
+                    "{} of {}moved value: `{}`",
+                    verb, msg, nl);
                 (ol, moved_lp_msg)
             }
         };
@@ -762,12 +761,10 @@ pub fn report_partial_reinitialization_of_uninitialized_structure(
             &self,
             span: Span,
             lp: &LoanPath<'tcx>) {
-        self.tcx
-            .sess
-            .span_err(span,
-                      &format!("partial reinitialization of uninitialized \
-                               structure `{}`",
-                               self.loan_path_to_string(lp)));
+        span_err!(
+            self.tcx.sess, span, E0383,
+            "partial reinitialization of uninitialized structure `{}`",
+            self.loan_path_to_string(lp));
     }
 
     pub fn report_reassigned_immutable_variable(&self,
@@ -775,10 +772,10 @@ pub fn report_reassigned_immutable_variable(&self,
                                                 lp: &LoanPath<'tcx>,
                                                 assign:
                                                 &move_data::Assignment) {
-        self.tcx.sess.span_err(
-            span,
-            &format!("re-assignment of immutable variable `{}`",
-                    self.loan_path_to_string(lp)));
+        span_err!(
+            self.tcx.sess, span, E0384,
+            "re-assignment of immutable variable `{}`",
+            self.loan_path_to_string(lp));
         self.tcx.sess.span_note(assign.span, "prior assignment occurs here");
     }
 
@@ -896,21 +893,19 @@ pub fn report_aliasability_violation(&self,
 
         match cause {
             mc::AliasableOther => {
-                self.tcx.sess.span_err(
-                    span,
-                    &format!("{} in an aliasable location",
-                             prefix));
+                span_err!(
+                    self.tcx.sess, span, E0385,
+                    "{} in an aliasable location", prefix);
             }
             mc::AliasableReason::UnaliasableImmutable => {
-                self.tcx.sess.span_err(
-                    span,
-                    &format!("{} in an immutable container",
-                             prefix));
+                span_err!(
+                    self.tcx.sess, span, E0386,
+                    "{} in an immutable container", prefix);
             }
             mc::AliasableClosure(id) => {
-                self.tcx.sess.span_err(span,
-                                       &format!("{} in a captured outer \
-                                                variable in an `Fn` closure", prefix));
+                span_err!(
+                    self.tcx.sess, span, E0387,
+                    "{} in a captured outer variable in an `Fn` closure", prefix);
                 if let BorrowViolation(euv::ClosureCapture(_)) = kind {
                     // The aliasability violation with closure captures can
                     // happen for nested closures, so we know the enclosing
@@ -925,14 +920,14 @@ pub fn report_aliasability_violation(&self,
             }
             mc::AliasableStatic(..) |
             mc::AliasableStaticMut(..) => {
-                self.tcx.sess.span_err(
-                    span,
-                    &format!("{} in a static location", prefix));
+                span_err!(
+                    self.tcx.sess, span, E0388,
+                    "{} in a static location", prefix);
             }
             mc::AliasableBorrowed => {
-                self.tcx.sess.span_err(
-                    span,
-                    &format!("{} in a `&` reference", prefix));
+                span_err!(
+                    self.tcx.sess, span, E0389,
+                    "{} in a `&` reference", prefix);
             }
         }
 
index a43268ff1a8827c1cad97eef5a5f66c481467bb8..3e7cfe3ee7f88aaa8bacbaf24992108d36bdc108 100644 (file)
 
 #![allow(non_snake_case)]
 
+register_long_diagnostics! {
+
+E0381: r##"
+It is not allowed to use or capture an uninitialized variable. For example:
+
+```
+fn main() {
+    let x: i32;
+    let y = x; // error, use of possibly uninitialized variable
+```
+
+To fix this, ensure that any declared variables are initialized before being
+used.
+"##
+
+}
+
 register_diagnostics! {
-    E0373 // closure may outlive current fn, but it borrows {}, which is owned by current fn
+    E0373, // closure may outlive current fn, but it borrows {}, which is owned by current fn
+    E0382, // use of partially/collaterally moved value
+    E0383, // partial reinitialization of uninitialized structure
+    E0384, // reassignment of immutable variable
+    E0385, // {} in an aliasable location
+    E0386, // {} in an immutable container
+    E0387, // {} in a captured outer variable in an `Fn` closure
+    E0388, // {} in a static location
+    E0389  // {} in a `&` reference
 }
index b9a5e597c260c518d0057190d85a5ea90de020d0..90bbd1af4efd035f43aea82d0a854dd854acbe5a 100644 (file)
@@ -437,13 +437,12 @@ fn create_substs_for_ast_path<'tcx>(
             // defaults. This will lead to an ICE if we are not
             // careful!
             if self_ty.is_none() && ty::type_has_self(default) {
-                tcx.sess.span_err(
-                    span,
-                    &format!("the type parameter `{}` must be explicitly specified \
-                              in an object type because its default value `{}` references \
-                              the type `Self`",
-                             param.name.user_string(tcx),
-                             default.user_string(tcx)));
+                span_err!(tcx.sess, span, E0393,
+                          "the type parameter `{}` must be explicitly specified \
+                           in an object type because its default value `{}` references \
+                           the type `Self`",
+                          param.name.user_string(tcx),
+                          default.user_string(tcx));
                 substs.types.push(TypeSpace, tcx.types.err);
             } else {
                 // This is a default type parameter.
index 8ec406ff41b92b4f5a3ed7f62f111cbc6de93c5f..405d43548b23af8fa9ef8e9f13c9b02dbe6e3782 100644 (file)
@@ -124,10 +124,9 @@ fn check_item_well_formed(&mut self, item: &ast::Item) {
                 reject_non_type_param_bounds(ccx.tcx, item.span, &trait_predicates);
                 if ty::trait_has_default_impl(ccx.tcx, local_def(item.id)) {
                     if !items.is_empty() {
-                        ccx.tcx.sess.span_err(
-                            item.span,
-                            "traits with default impls (`e.g. unsafe impl Trait for ..`) must \
-                            have no methods or associated items")
+                        span_err!(ccx.tcx.sess, item.span, E0380,
+                                  "traits with default impls (`e.g. unsafe impl \
+                                  Trait for ..`) must have no methods or associated items")
                     }
                 }
             }
@@ -353,10 +352,8 @@ fn report_bivariance(&self,
                          span: Span,
                          param_name: ast::Name)
     {
-        self.tcx().sess.span_err(
-            span,
-            &format!("parameter `{}` is never used",
-                     param_name.user_string(self.tcx())));
+        span_err!(self.tcx().sess, span, E0392,
+            "parameter `{}` is never used", param_name.user_string(self.tcx()));
 
         let suggested_marker_id = self.tcx().lang_items.phantom_data();
         match suggested_marker_id {
index 4c9fe6492e9ca530430ea1884d5b5532b781e087..7dc865ef8855cb3877a07567b9cb91f24c4ab27d 100644 (file)
@@ -48,10 +48,9 @@ fn check_primitive_impl(&self,
         match lang_def_id {
             Some(lang_def_id) if lang_def_id == impl_def_id => { /* OK */ },
             _ => {
-                self.tcx.sess.span_err(
-                    span,
-                    &format!("only a single inherent implementation marked with `#[lang = \"{}\"]` \
-                              is allowed for the `{}` primitive", lang, ty));
+                span_err!(self.tcx.sess, span, E0390,
+                          "only a single inherent implementation marked with `#[lang = \"{}\"]` \
+                           is allowed for the `{}` primitive", lang, ty);
             }
         }
     }
index 22223bc3814566351cb642f2f1c1c48637ee36cb..42d1c122fba83b5cff4cb2f3128690674e9eed66 100644 (file)
@@ -236,9 +236,8 @@ fn report_cycle(&self,
         assert!(!cycle.is_empty());
         let tcx = self.tcx;
 
-        tcx.sess.span_err(
-            span,
-            &format!("unsupported cyclic reference between types/traits detected"));
+        span_err!(tcx.sess, span, E0391,
+            "unsupported cyclic reference between types/traits detected");
 
         match cycle[0] {
             AstConvRequest::GetItemTypeScheme(def_id) |
index 0f381b590de81535c70ac243afb2f2a756f6ff10..edfad77d588df1d40a394cce1cb5b98c243e3368 100644 (file)
@@ -1096,6 +1096,12 @@ impl Baz for Bar { } // Note: This is OK
 [RFC 255] for more details on object safety rules.
 
 [RFC 255]: https://github.com/rust-lang/rfcs/pull/255
+"##,
+
+E0380: r##"
+Default impls are only allowed for traits with no methods or associated items.
+For more information see the [opt-in builtin traits RFC](https://github.com/rust
+-lang/rfcs/blob/master/text/0019-opt-in-builtin-traits.md).
 "##
 
 }
@@ -1229,5 +1235,11 @@ impl Baz for Bar { } // Note: This is OK
            // between structures
     E0377, // the trait `CoerceUnsized` may only be implemented for a coercion
            // between structures with the same definition
-    E0379  // trait fns cannot be const
+    E0379,  // trait fns cannot be const
+    E0390, // only a single inherent implementation marked with
+           // `#[lang = \"{}\"]` is allowed for the `{}` primitive
+    E0391, // unsupported cyclic reference between types/traits detected
+    E0392, // parameter `{}` is never used
+    E0393  // the type parameter `{}` must be explicitly specified in an object
+           // type because its default value `{}` references the type `Self`"
 }