]> git.lizzy.rs Git - rust.git/commitdiff
Second approach - using type contents
authorNick Cameron <ncameron@mozilla.com>
Sun, 31 Aug 2014 21:48:19 +0000 (09:48 +1200)
committerNick Cameron <ncameron@mozilla.com>
Sun, 31 Aug 2014 21:48:19 +0000 (09:48 +1200)
src/librustc/diagnostics.rs
src/librustc/middle/kind.rs
src/librustc/middle/ty.rs
src/test/compile-fail/bad-sized.rs

index 2698ac94a99c6f0fd3ce3db217d89206b90c5ff2..77e73c46c402cf2f6ac23962b2dc4d80124759be 100644 (file)
     E0155,
     E0156,
     E0157,
-    E0158,
-    E0159
+    E0158
 )
index ee2d73dda95231e570bc6c31cd6a0ea01673c081..c3a001116b34c3d52b6ee3f1fb1fb7076c689602 100644 (file)
@@ -596,8 +596,8 @@ fn check_ty(cx: &mut Context, aty: &Ty) {
                 Some(ref item_substs) => {
                     let def_map = cx.tcx.def_map.borrow();
                     let did = def_map.get_copy(&id).def_id();
-                    let ty = ty::lookup_item_type(cx.tcx, did);
-                    for def in ty.generics.types.iter() {
+                    let generics = ty::lookup_item_type(cx.tcx, did).generics;
+                    for def in generics.types.iter() {
                         let ty = *item_substs.substs.types.get(def.space,
                                                                def.index);
                         check_typaram_bounds(cx, aty.span, ty, def);
@@ -644,20 +644,6 @@ pub fn check_typaram_bounds(cx: &Context,
     });
 }
 
-// Check that the programmer has not added the `Sized` bound to a trait type
-// which would fool the compiler into thinking that trait types are sized, when
-// they are really unsized.
-fn check_false_sized(cx: &Context, sp: Span, ty: ty::t) {
-    match ty::get(ty).sty {
-        ty::ty_trait(..) if ty::type_is_sized(cx.tcx, ty) => {
-            span_err!(cx.tcx.sess, sp, E0159,
-                      "explicitly adding `Sized` bound to an unsized type `{}`",
-                       ty_to_string(cx.tcx, ty));
-        }
-        _ => {}
-    }
-}
-
 fn check_bounds_on_structs_or_enums_in_type_if_possible(cx: &mut Context,
                                                         span: Span,
                                                         ty: ty::t) {
@@ -688,7 +674,6 @@ fn check_bounds_on_structs_or_enums_in_type_if_possible(cx: &mut Context,
                                                                .types
                                                                .iter()) {
                     check_typaram_bounds(cx, span, *ty, type_param_def);
-                    check_false_sized(cx, span, *ty);
                 }
 
                 // Check trait bounds.
@@ -716,7 +701,6 @@ fn check_bounds_on_structs_or_enums_in_type_if_possible(cx: &mut Context,
                                             cx.tcx)).as_slice());
                 })
             }
-            ty::ty_uniq(ty) => check_false_sized(cx, span, ty),
             _ => {}
         }
     });
index 2d3096d13eae078a08be9637beafc8ed3743f96e..2cd76404ecbacf9c870a378f118922d2882ce038 100644 (file)
@@ -2362,7 +2362,7 @@ fn tc_ty(cx: &ctxt,
             }
 
             ty_trait(box ty::TyTrait { bounds, .. }) => {
-                object_contents(cx, bounds) | TC::ReachesFfiUnsafe
+                object_contents(cx, bounds) | TC::ReachesFfiUnsafe | TC::Nonsized
             }
 
             ty_ptr(ref mt) => {
index e0a929dcf4f8c4157adf410151bd12fac8570733..fb9a060cb602a75e66c7e43e867c8f1e162fe70b 100644 (file)
@@ -8,18 +8,18 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+// ignore-tidy-linelength
+
 use std::cell::RefCell;
 
 trait Trait {}
 
 pub fn main() {
     let x: Vec<Trait + Sized> = Vec::new();
-    //~^ ERROR explicitly adding `Sized` bound to an unsized type `Trait+Sized`
-    //~^^ ERROR explicitly adding `Sized` bound to an unsized type `Trait+Sized`
-    let x: Vec<Box<Trait + Sized>> = Vec::new();
-    //~^ ERROR explicitly adding `Sized` bound to an unsized type `Trait+Sized`
-    //~^^ ERROR explicitly adding `Sized` bound to an unsized type `Trait+Sized`
+    //~^ ERROR instantiating a type parameter with an incompatible type `Trait+Sized`, which does not fulfill `Sized`
+    //~^^ ERROR instantiating a type parameter with an incompatible type `Trait+Sized`, which does not fulfill `Sized`
+    //~^^^ ERROR instantiating a type parameter with an incompatible type `Trait+Sized`, which does not fulfill `Sized`
     let x: Vec<Box<RefCell<Trait + Sized>>> = Vec::new();
-    //~^ ERROR explicitly adding `Sized` bound to an unsized type `Trait+Sized`
-    //~^^ ERROR explicitly adding `Sized` bound to an unsized type `Trait+Sized`
+    //~^ ERROR instantiating a type parameter with an incompatible type `Trait+Sized`, which does not fulfill `Sized`
+    //~^^ ERROR instantiating a type parameter with an incompatible type `Trait+Sized`, which does not fulfill `Sized`
 }