]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_typeck/collect.rs
rollup merge of #21438: taralx/kill-racycell
[rust.git] / src / librustc_typeck / collect.rs
index 79e98f15a2d43daf7a4a609886f632debf61542e..664e5eaa45baeb896ca73e8f0d74f7bbbebb5b80 100644 (file)
@@ -212,7 +212,7 @@ fn get_enum_variant_types<'a, 'tcx>(ccx: &CollectCtxt<'a, 'tcx>,
             ast::TupleVariantKind(ref args) if args.len() > 0 => {
                 let rs = ExplicitRscope;
                 let input_tys: Vec<_> = args.iter().map(|va| ccx.to_ty(&rs, &*va.ty)).collect();
-                ty::mk_ctor_fn(tcx, variant_def_id, input_tys.index(&FullRange), enum_ty)
+                ty::mk_ctor_fn(tcx, variant_def_id, &input_tys[], enum_ty)
             }
 
             ast::TupleVariantKind(_) => {
@@ -259,7 +259,7 @@ fn collect_trait_methods<'a, 'tcx>(ccx: &CollectCtxt<'a, 'tcx>,
                                     ccx,
                                     trait_id,
                                     &trait_def.generics,
-                                    trait_items.index(&FullRange),
+                                    &trait_items[],
                                     &m.id,
                                     &m.ident.name,
                                     &m.explicit_self,
@@ -273,7 +273,7 @@ fn collect_trait_methods<'a, 'tcx>(ccx: &CollectCtxt<'a, 'tcx>,
                                     ccx,
                                     trait_id,
                                     &trait_def.generics,
-                                    trait_items.index(&FullRange),
+                                    &trait_items[],
                                     &m.id,
                                     &m.pe_ident().name,
                                     m.pe_explicit_self(),
@@ -449,10 +449,10 @@ fn convert_methods<'a,'tcx,'i,I>(ccx: &CollectCtxt<'a, 'tcx>,
            rcvr_ty_generics.repr(ccx.tcx));
 
     let tcx = ccx.tcx;
-    let mut seen_methods = FnvHashSet::new();
+    let mut seen_methods = FnvHashSet();
     for m in ms {
         if !seen_methods.insert(m.pe_ident().repr(tcx)) {
-            tcx.sess.span_err(m.span, "duplicate method in trait impl");
+            span_err!(tcx.sess, m.span, E0201, "duplicate method in trait impl");
         }
 
         let m_def_id = local_def(m.id);
@@ -607,6 +607,11 @@ fn convert(ccx: &CollectCtxt, it: &ast::Item) {
                         methods.push(&**method);
                     }
                     ast::TypeImplItem(ref typedef) => {
+                        if opt_trait_ref.is_none() {
+                            span_err!(tcx.sess, typedef.span, E0202,
+                                              "associated items are not allowed in inherent impls");
+                        }
+
                         let typ = ccx.to_ty(&ExplicitRscope, &*typedef.typ);
                         tcx.tcache
                            .borrow_mut()
@@ -732,7 +737,7 @@ fn convert_struct<'a, 'tcx>(ccx: &CollectCtxt<'a, 'tcx>,
     let tcx = ccx.tcx;
 
     // Write the type of each of the members and check for duplicate fields.
-    let mut seen_fields: FnvHashMap<ast::Name, Span> = FnvHashMap::new();
+    let mut seen_fields: FnvHashMap<ast::Name, Span> = FnvHashMap();
     let field_tys = struct_def.fields.iter().map(|f| {
         let result = convert_field(ccx, &scheme.generics, f, local_def(id));
 
@@ -779,7 +784,7 @@ fn convert_struct<'a, 'tcx>(ccx: &CollectCtxt<'a, 'tcx>,
                             local_def(field.node.id)].ty).collect();
                 let ctor_fn_ty = ty::mk_ctor_fn(tcx,
                                                 local_def(ctor_id),
-                                                inputs.index(&FullRange),
+                                                &inputs[],
                                                 selfty);
                 write_ty_to_tcx(tcx, ctor_id, ctor_fn_ty);
                 tcx.tcache.borrow_mut().insert(local_def(ctor_id),
@@ -819,8 +824,8 @@ fn get_trait_def<'a, 'tcx>(ccx: &CollectCtxt<'a, 'tcx>,
     match ccx.tcx.map.get(trait_id.node) {
         ast_map::NodeItem(item) => trait_def_of_item(ccx, &*item),
         _ => {
-            ccx.tcx.sess.bug(format!("get_trait_def({}): not an item",
-                                     trait_id.node).index(&FullRange))
+            ccx.tcx.sess.bug(&format!("get_trait_def({}): not an item",
+                                     trait_id.node)[])
         }
     }
 }
@@ -845,7 +850,7 @@ fn trait_def_of_item<'a, 'tcx>(ccx: &CollectCtxt<'a, 'tcx>,
         ref s => {
             tcx.sess.span_bug(
                 it.span,
-                format!("trait_def_of_item invoked on {:?}", s).index(&FullRange));
+                &format!("trait_def_of_item invoked on {:?}", s)[]);
         }
     };
 
@@ -1030,8 +1035,8 @@ fn ty_generics_for_type_or_impl<'a, 'tcx>(ccx: &CollectCtxt<'a, 'tcx>,
                                           -> ty::Generics<'tcx> {
     ty_generics(ccx,
                 subst::TypeSpace,
-                generics.lifetimes.index(&FullRange),
-                generics.ty_params.index(&FullRange),
+                &generics.lifetimes[],
+                &generics.ty_params[],
                 ty::Generics::empty(),
                 &generics.where_clause)
 }
@@ -1049,8 +1054,8 @@ fn ty_generics_for_trait<'a, 'tcx>(ccx: &CollectCtxt<'a, 'tcx>,
     let mut generics =
         ty_generics(ccx,
                     subst::TypeSpace,
-                    ast_generics.lifetimes.index(&FullRange),
-                    ast_generics.ty_params.index(&FullRange),
+                    &ast_generics.lifetimes[],
+                    &ast_generics.ty_params[],
                     ty::Generics::empty(),
                     &ast_generics.where_clause);
 
@@ -1135,8 +1140,8 @@ fn ty_generics_for_fn_or_method<'a,'tcx>(ccx: &CollectCtxt<'a,'tcx>,
     let early_lifetimes = resolve_lifetime::early_bound_lifetimes(generics);
     ty_generics(ccx,
                 subst::FnSpace,
-                early_lifetimes.index(&FullRange),
-                generics.ty_params.index(&FullRange),
+                &early_lifetimes[],
+                &generics.ty_params[],
                 base_generics,
                 &generics.where_clause)
 }
@@ -1155,7 +1160,8 @@ fn add_unsized_bound<'a,'tcx>(ccx: &CollectCtxt<'a,'tcx>,
                 assert!(ptr.bound_lifetimes.is_empty());
                 unbound = Some(ptr.trait_ref.clone());
             } else {
-                ccx.tcx.sess.span_err(span, "type parameter has more than one relaxed default \
+                span_err!(ccx.tcx.sess, span, E0203,
+                          "type parameter has more than one relaxed default \
                                                 bound, only one is supported");
             }
         }
@@ -1323,7 +1329,7 @@ fn get_or_create_type_parameter_def<'a,'tcx>(ccx: &CollectCtxt<'a,'tcx>,
     let param_ty = ty::ParamTy::new(space, index, param.ident.name);
     let bounds = compute_bounds(ccx,
                                 param_ty.to_ty(ccx.tcx),
-                                param.bounds.index(&FullRange),
+                                &param.bounds[],
                                 SizedByDefault::Yes,
                                 param.span);
     let default = match param.default {
@@ -1404,7 +1410,7 @@ fn check_bounds_compatible<'tcx>(tcx: &ty::ctxt<'tcx>,
     if !param_bounds.builtin_bounds.contains(&ty::BoundSized) {
         ty::each_bound_trait_and_supertraits(
             tcx,
-            param_bounds.trait_bounds.index(&FullRange),
+            &param_bounds.trait_bounds[],
             |trait_ref| {
                 let trait_def = ty::lookup_trait_def(tcx, trait_ref.def_id());
                 if trait_def.bounds.builtin_bounds.contains(&ty::BoundSized) {
@@ -1483,7 +1489,9 @@ fn ty_of_foreign_fn_decl<'a, 'tcx>(ccx: &CollectCtxt<'a, 'tcx>,
     let output = match decl.output {
         ast::Return(ref ty) =>
             ty::FnConverging(ast_ty_to_ty(ccx, &rb, &**ty)),
-        ast::NoReturn(_) =>
+        ast::DefaultReturn(..) =>
+            ty::FnConverging(ty::mk_nil(ccx.tcx)),
+        ast::NoReturn(..) =>
             ty::FnDiverging
     };
 
@@ -1683,11 +1691,10 @@ fn enforce_impl_ty_params_are_constrained<'tcx>(tcx: &ty::ctxt<'tcx>,
                              impl trait, self type, or predicates",
                             param_ty.user_string(tcx)).as_slice());
             } else {
-                tcx.sess.span_err(
-                    ty_param.span,
-                    format!("the type parameter `{}` is not constrained by the \
+                span_err!(tcx.sess, ty_param.span, E0207,
+                    "the type parameter `{}` is not constrained by the \
                              impl trait, self type, or predicates",
-                            param_ty.user_string(tcx)).as_slice());
+                            param_ty.user_string(tcx));
                 tcx.sess.span_help(
                     ty_param.span,
                     format!("you can temporarily opt out of this rule by placing \