Skip to content

Commit 9b81a4e

Browse files
committed
auto merge of #16811 : nick29581/rust/dst-bug-2, r=nikomatsakis
closes #16800 r? @nikomatsakis - I'm not 100% sure this is the right approach, it is kind of ad-hoc. The trouble is we don't have any intrinsic notion of which types are sized and which are not, we only have the Sized bound, so I have nothing to validate the Sized bound against.
2 parents 6ac4a30 + cc598e6 commit 9b81a4e

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

src/librustc/middle/kind.rs

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

11-
1211
use middle::freevars::freevar_entry;
1312
use middle::freevars;
1413
use middle::subst;
@@ -587,15 +586,15 @@ fn check_ty(cx: &mut Context, aty: &Ty) {
587586
match aty.node {
588587
TyPath(_, _, id) => {
589588
match cx.tcx.item_substs.borrow().find(&id) {
590-
None => { }
589+
None => {}
591590
Some(ref item_substs) => {
592591
let def_map = cx.tcx.def_map.borrow();
593592
let did = def_map.get_copy(&id).def_id();
594593
let generics = ty::lookup_item_type(cx.tcx, did).generics;
595594
for def in generics.types.iter() {
596595
let ty = *item_substs.substs.types.get(def.space,
597596
def.index);
598-
check_typaram_bounds(cx, aty.span, ty, def)
597+
check_typaram_bounds(cx, aty.span, ty, def);
599598
}
600599
}
601600
}
@@ -668,7 +667,7 @@ fn check_bounds_on_structs_or_enums_in_type_if_possible(cx: &mut Context,
668667
.zip(polytype.generics
669668
.types
670669
.iter()) {
671-
check_typaram_bounds(cx, span, *ty, type_param_def)
670+
check_typaram_bounds(cx, span, *ty, type_param_def);
672671
}
673672

674673
// Check trait bounds.

src/librustc/middle/ty.rs

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

24122412
ty_trait(box ty::TyTrait { bounds, .. }) => {
2413-
object_contents(cx, bounds) | TC::ReachesFfiUnsafe
2413+
object_contents(cx, bounds) | TC::ReachesFfiUnsafe | TC::Nonsized
24142414
}
24152415

24162416
ty_ptr(ref mt) => {

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// ignore-tidy-linelength
12+
13+
use std::cell::RefCell;
14+
15+
trait Trait {}
16+
17+
pub fn main() {
18+
let x: Vec<Trait + Sized> = Vec::new();
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`
22+
let x: Vec<Box<RefCell<Trait + Sized>>> = Vec::new();
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`
25+
}

0 commit comments

Comments
 (0)