Require that objects can only be made from Sized types. Fixes #18333.

This commit is contained in:
Niko Matsakis 2014-11-07 16:26:26 -05:00
parent dd5ce5ae2f
commit 7a372e23cb
6 changed files with 59 additions and 5 deletions

View file

@ -0,0 +1,30 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Test that we cannot create objects from unsized types.
trait Foo for Sized? {}
impl Foo for str {}
fn test<Sized? T: Foo>(t: &T) {
let u: &Foo = t;
//~^ ERROR `core::kinds::Sized` is not implemented for the type `T`
let v: &Foo = t as &Foo;
//~^ ERROR `core::kinds::Sized` is not implemented for the type `T`
}
fn main() {
let _: &[&Foo] = &["hi"];
//~^ ERROR `core::kinds::Sized` is not implemented for the type `str`
let _: &Foo = "hi" as &Foo;
//~^ ERROR `core::kinds::Sized` is not implemented for the type `str`
}

View file

@ -11,5 +11,5 @@
fn main() {
let _x = "test" as &::std::any::Any;
//~^ ERROR the trait `core::kinds::Sized` is not implemented for the type `str`
//~^^ NOTE the trait `core::kinds::Sized` must be implemented for the cast to the object type
//~^^ ERROR the trait `core::kinds::Sized` is not implemented for the type `str`
}