|
8 | 8 | // option. This file may not be copied, modified, or distributed
|
9 | 9 | // except according to those terms.
|
10 | 10 |
|
11 |
| - |
12 | 11 | use middle::freevars::freevar_entry;
|
13 | 12 | use middle::freevars;
|
14 | 13 | use middle::subst;
|
@@ -593,15 +592,15 @@ fn check_ty(cx: &mut Context, aty: &Ty) {
|
593 | 592 | match aty.node {
|
594 | 593 | TyPath(_, _, id) => {
|
595 | 594 | match cx.tcx.item_substs.borrow().find(&id) {
|
596 |
| - None => { } |
| 595 | + None => {} |
597 | 596 | Some(ref item_substs) => {
|
598 | 597 | let def_map = cx.tcx.def_map.borrow();
|
599 | 598 | let did = def_map.get_copy(&id).def_id();
|
600 |
| - let generics = ty::lookup_item_type(cx.tcx, did).generics; |
601 |
| - for def in generics.types.iter() { |
| 599 | + let ty = ty::lookup_item_type(cx.tcx, did); |
| 600 | + for def in ty.generics.types.iter() { |
602 | 601 | let ty = *item_substs.substs.types.get(def.space,
|
603 | 602 | def.index);
|
604 |
| - check_typaram_bounds(cx, aty.span, ty, def) |
| 603 | + check_typaram_bounds(cx, aty.span, ty, def); |
605 | 604 | }
|
606 | 605 | }
|
607 | 606 | }
|
@@ -645,6 +644,20 @@ pub fn check_typaram_bounds(cx: &Context,
|
645 | 644 | });
|
646 | 645 | }
|
647 | 646 |
|
| 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 | + |
648 | 661 | fn check_bounds_on_structs_or_enums_in_type_if_possible(cx: &mut Context,
|
649 | 662 | span: Span,
|
650 | 663 | ty: ty::t) {
|
@@ -674,7 +687,8 @@ fn check_bounds_on_structs_or_enums_in_type_if_possible(cx: &mut Context,
|
674 | 687 | .zip(polytype.generics
|
675 | 688 | .types
|
676 | 689 | .iter()) {
|
677 |
| - check_typaram_bounds(cx, span, *ty, type_param_def) |
| 690 | + check_typaram_bounds(cx, span, *ty, type_param_def); |
| 691 | + check_false_sized(cx, span, *ty); |
678 | 692 | }
|
679 | 693 |
|
680 | 694 | // Check trait bounds.
|
@@ -702,6 +716,7 @@ fn check_bounds_on_structs_or_enums_in_type_if_possible(cx: &mut Context,
|
702 | 716 | cx.tcx)).as_slice());
|
703 | 717 | })
|
704 | 718 | }
|
| 719 | + ty::ty_uniq(ty) => check_false_sized(cx, span, ty), |
705 | 720 | _ => {}
|
706 | 721 | }
|
707 | 722 | });
|
|
0 commit comments