]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_typeck/check/mod.rs
rollup merge of #21438: taralx/kill-racycell
[rust.git] / src / librustc_typeck / check / mod.rs
index a4fa594621eff95426a7d5341f6451821f975320..db4962b0d22db299b517bf75c1c9750a23a86131 100644 (file)
 use session::Session;
 use {CrateCtxt, lookup_def_ccx, no_params, require_same_types};
 use TypeAndSubsts;
-use middle::lang_items::TypeIdLangItem;
 use lint;
 use util::common::{block_query, indenter, loop_query};
 use util::ppaux::{self, Repr};
@@ -802,16 +801,15 @@ fn check_trait_on_unimplemented<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
                         }) {
                             Some(_) => (),
                             None => {
-                                ccx.tcx.sess.span_err(attr.span,
-                                                 format!("there is no type parameter \
+                                span_err!(ccx.tcx.sess, attr.span, E0230,
+                                                 "there is no type parameter \
                                                           {} on trait {}",
-                                                           s, item.ident.as_str())
-                                            .as_slice());
+                                                           s, item.ident.as_str());
                             }
                         },
                         // `{:1}` and `{}` are not to be used
                         Position::ArgumentIs(_) | Position::ArgumentNext => {
-                            ccx.tcx.sess.span_err(attr.span,
+                            span_err!(ccx.tcx.sess, attr.span, E0231,
                                                   "only named substitution \
                                                    parameters are allowed");
                         }
@@ -819,7 +817,7 @@ fn check_trait_on_unimplemented<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
                 }
             }
         } else {
-            ccx.tcx.sess.span_err(attr.span,
+            span_err!(ccx.tcx.sess, attr.span, E0232,
                                   "this attribute must have a value, \
                                    eg `#[rustc_on_unimplemented = \"foo\"]`")
         }
@@ -2100,8 +2098,8 @@ fn lookup_method_for_for_loop<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
     let trait_did = match fcx.tcx().lang_items.require(IteratorItem) {
         Ok(trait_did) => trait_did,
         Err(ref err_string) => {
-            fcx.tcx().sess.span_err(iterator_expr.span,
-                                    &err_string[]);
+            span_err!(fcx.tcx().sess, iterator_expr.span, E0233,
+                                    "{}", &err_string[]);
             return fcx.tcx().types.err
         }
     };
@@ -2124,11 +2122,10 @@ fn lookup_method_for_for_loop<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
 
             if !ty::type_is_error(true_expr_type) {
                 let ty_string = fcx.infcx().ty_to_string(true_expr_type);
-                fcx.tcx().sess.span_err(iterator_expr.span,
-                                        &format!("`for` loop expression has type `{}` which does \
+                span_err!(fcx.tcx().sess, iterator_expr.span, E0234,
+                                        "`for` loop expression has type `{}` which does \
                                                 not implement the `Iterator` trait; \
-                                                maybe try .iter()",
-                                                ty_string)[]);
+                                                maybe try .iter()", ty_string);
             }
             fcx.tcx().types.err
         }
@@ -2163,11 +2160,10 @@ fn lookup_method_for_for_loop<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
                     fcx.tcx().types.err
                 }
                 _ => {
-                    fcx.tcx().sess.span_err(iterator_expr.span,
-                                            &format!("`next` method of the `Iterator` \
+                    span_err!(fcx.tcx().sess, iterator_expr.span, E0239,
+                                            "`next` method of the `Iterator` \
                                                     trait has an unexpected type `{}`",
-                                                    fcx.infcx().ty_to_string(return_type))
-                                            []);
+                                                    fcx.infcx().ty_to_string(return_type));
                     fcx.tcx().types.err
                 }
             }
@@ -3881,10 +3877,8 @@ fn check_struct_fields_on_error(fcx: &FnCtxt,
                 Err(type_error) => {
                     let type_error_description =
                         ty::type_err_to_str(tcx, &type_error);
-                    fcx.tcx()
-                       .sess
-                       .span_err(path.span,
-                                 &format!("structure constructor specifies a \
+                    span_err!(fcx.tcx().sess, path.span, E0235,
+                                 "structure constructor specifies a \
                                          structure of type `{}`, but this \
                                          structure has type `{}`: {}",
                                          fcx.infcx()
@@ -3892,7 +3886,7 @@ fn check_struct_fields_on_error(fcx: &FnCtxt,
                                          fcx.infcx()
                                             .ty_to_string(
                                                 actual_structure_type),
-                                         type_error_description)[]);
+                                         type_error_description);
                     ty::note_and_explain_type_err(tcx, &type_error);
                 }
             }
@@ -4013,7 +4007,7 @@ fn check_struct_fields_on_error(fcx: &FnCtxt,
 
                     ty::mk_struct(tcx, did, tcx.mk_substs(substs))
                 } else {
-                    tcx.sess.span_err(expr.span, "No lang item for range syntax");
+                    span_err!(tcx.sess, expr.span, E0236, "no lang item for range syntax");
                     fcx.tcx().types.err
                 }
             }
@@ -4023,7 +4017,7 @@ fn check_struct_fields_on_error(fcx: &FnCtxt,
                     let substs = Substs::new_type(vec![], vec![]);
                     ty::mk_struct(tcx, did, tcx.mk_substs(substs))
                 } else {
-                    tcx.sess.span_err(expr.span, "No lang item for range syntax");
+                    span_err!(tcx.sess, expr.span, E0237, "no lang item for range syntax");
                     fcx.tcx().types.err
                 }
             }
@@ -4873,8 +4867,7 @@ fn push_explicit_parameters_from_segment_to_substs<'a, 'tcx>(
             }
 
             ast::ParenthesizedParameters(ref data) => {
-                fcx.tcx().sess.span_err(
-                    span,
+                span_err!(fcx.tcx().sess, span, E0238,
                     "parenthesized parameters may only be used with a trait");
                 push_explicit_parenthesized_parameters_from_segment_to_substs(
                     fcx, space, span, type_defs, data, substs);
@@ -5231,7 +5224,7 @@ fn param<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, n: u32) -> Ty<'tcx> {
             "get_tydesc" => {
               let tydesc_ty = match ty::get_tydesc_ty(ccx.tcx) {
                   Ok(t) => t,
-                  Err(s) => { tcx.sess.span_fatal(it.span, &s[]); }
+                  Err(s) => { span_fatal!(tcx.sess, it.span, E0240, "{}", &s[]); }
               };
               let td_ptr = ty::mk_ptr(ccx.tcx, ty::mt {
                   ty: tydesc_ty,
@@ -5239,18 +5232,7 @@ fn param<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, n: u32) -> Ty<'tcx> {
               });
               (1u, Vec::new(), td_ptr)
             }
-            "type_id" => {
-                let langid = ccx.tcx.lang_items.require(TypeIdLangItem);
-                match langid {
-                    Ok(did) => (1u,
-                                Vec::new(),
-                                ty::mk_struct(ccx.tcx, did,
-                                              ccx.tcx.mk_substs(subst::Substs::empty()))),
-                    Err(msg) => {
-                        tcx.sess.span_fatal(it.span, &msg[]);
-                    }
-                }
-            },
+            "type_id" => (1u, Vec::new(), ccx.tcx.types.u64),
             "offset" => {
               (1,
                vec!(