Skip to content

Commit cc598e6

Browse files
committed
Second approach - using type contents
1 parent bdfeb65 commit cc598e6

File tree

4 files changed

+11
-28
lines changed

4 files changed

+11
-28
lines changed

src/librustc/diagnostics.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,5 @@ register_diagnostics!(
167167
E0155,
168168
E0156,
169169
E0157,
170-
E0158,
171-
E0159
170+
E0158
172171
)

src/librustc/middle/kind.rs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,8 @@ fn check_ty(cx: &mut Context, aty: &Ty) {
596596
Some(ref item_substs) => {
597597
let def_map = cx.tcx.def_map.borrow();
598598
let did = def_map.get_copy(&id).def_id();
599-
let ty = ty::lookup_item_type(cx.tcx, did);
600-
for def in ty.generics.types.iter() {
599+
let generics = ty::lookup_item_type(cx.tcx, did).generics;
600+
for def in generics.types.iter() {
601601
let ty = *item_substs.substs.types.get(def.space,
602602
def.index);
603603
check_typaram_bounds(cx, aty.span, ty, def);
@@ -644,20 +644,6 @@ pub fn check_typaram_bounds(cx: &Context,
644644
});
645645
}
646646

647-
// Check that the programmer has not added the `Sized` bound to a trait type
648-
// which would fool the compiler into thinking that trait types are sized, when
649-
// they are really unsized.
650-
fn check_false_sized(cx: &Context, sp: Span, ty: ty::t) {
651-
match ty::get(ty).sty {
652-
ty::ty_trait(..) if ty::type_is_sized(cx.tcx, ty) => {
653-
span_err!(cx.tcx.sess, sp, E0159,
654-
"explicitly adding `Sized` bound to an unsized type `{}`",
655-
ty_to_string(cx.tcx, ty));
656-
}
657-
_ => {}
658-
}
659-
}
660-
661647
fn check_bounds_on_structs_or_enums_in_type_if_possible(cx: &mut Context,
662648
span: Span,
663649
ty: ty::t) {
@@ -688,7 +674,6 @@ fn check_bounds_on_structs_or_enums_in_type_if_possible(cx: &mut Context,
688674
.types
689675
.iter()) {
690676
check_typaram_bounds(cx, span, *ty, type_param_def);
691-
check_false_sized(cx, span, *ty);
692677
}
693678

694679
// Check trait bounds.
@@ -716,7 +701,6 @@ fn check_bounds_on_structs_or_enums_in_type_if_possible(cx: &mut Context,
716701
cx.tcx)).as_slice());
717702
})
718703
}
719-
ty::ty_uniq(ty) => check_false_sized(cx, span, ty),
720704
_ => {}
721705
}
722706
});

src/librustc/middle/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2362,7 +2362,7 @@ pub fn type_contents(cx: &ctxt, ty: t) -> TypeContents {
23622362
}
23632363

23642364
ty_trait(box ty::TyTrait { bounds, .. }) => {
2365-
object_contents(cx, bounds) | TC::ReachesFfiUnsafe
2365+
object_contents(cx, bounds) | TC::ReachesFfiUnsafe | TC::Nonsized
23662366
}
23672367

23682368
ty_ptr(ref mt) => {

src/test/compile-fail/bad-sized.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// ignore-tidy-linelength
12+
1113
use std::cell::RefCell;
1214

1315
trait Trait {}
1416

1517
pub fn main() {
1618
let x: Vec<Trait + Sized> = Vec::new();
17-
//~^ ERROR explicitly adding `Sized` bound to an unsized type `Trait+Sized`
18-
//~^^ ERROR explicitly adding `Sized` bound to an unsized type `Trait+Sized`
19-
let x: Vec<Box<Trait + Sized>> = Vec::new();
20-
//~^ ERROR explicitly adding `Sized` bound to an unsized type `Trait+Sized`
21-
//~^^ ERROR explicitly adding `Sized` bound to an unsized type `Trait+Sized`
19+
//~^ ERROR instantiating a type parameter with an incompatible type `Trait+Sized`, which does not fulfill `Sized`
20+
//~^^ ERROR instantiating a type parameter with an incompatible type `Trait+Sized`, which does not fulfill `Sized`
21+
//~^^^ ERROR instantiating a type parameter with an incompatible type `Trait+Sized`, which does not fulfill `Sized`
2222
let x: Vec<Box<RefCell<Trait + Sized>>> = Vec::new();
23-
//~^ ERROR explicitly adding `Sized` bound to an unsized type `Trait+Sized`
24-
//~^^ ERROR explicitly adding `Sized` bound to an unsized type `Trait+Sized`
23+
//~^ ERROR instantiating a type parameter with an incompatible type `Trait+Sized`, which does not fulfill `Sized`
24+
//~^^ ERROR instantiating a type parameter with an incompatible type `Trait+Sized`, which does not fulfill `Sized`
2525
}

0 commit comments

Comments
 (0)