Fallout in tests -- we now report an error if you even reference a type

`&Foo` where `Foo` is a trait that is not object-safe
This commit is contained in:
Niko Matsakis 2015-08-07 10:58:00 -04:00
parent d15d743fa8
commit 09bf2fef22
14 changed files with 34 additions and 27 deletions

View file

@ -72,7 +72,6 @@ pub mod testtypes {
// Tests TyTrait
pub trait FooTrait {
fn foo_method(&self) -> usize;
fn foo_static_method() -> usize;
}
// Tests TyStruct

View file

@ -9,12 +9,12 @@
// except according to those terms.
fn main() {
&1 as Copy;
&1 as Send;
//~^ ERROR cast to unsized type
//~| HELP try casting to a reference instead:
//~| SUGGESTION &1 as &Copy;
Box::new(1) as Copy;
//~| SUGGESTION &1 as &Send;
Box::new(1) as Send;
//~^ ERROR cast to unsized type
//~| HELP try casting to a `Box` instead:
//~| SUGGESTION Box::new(1) as Box<Copy>;
//~| SUGGESTION Box::new(1) as Box<Send>;
}

View file

@ -15,7 +15,7 @@
// so for now just live with it.
// This test case was originally for issue #2258.
trait ToOpt {
trait ToOpt: Sized {
fn to_option(&self) -> Option<Self>;
}

View file

@ -21,10 +21,11 @@ impl Foo for Thing {
fn foo(b: &Bar) {
b.foo(&0)
//~^ ERROR the trait `Foo` is not implemented for the type `Bar`
//~| ERROR E0038
}
fn main() {
let mut thing = Thing;
let test: &Bar = &mut thing; //~ ERROR cannot convert to a trait object
let test: &Bar = &mut thing; //~ ERROR E0038
foo(test);
}

View file

@ -18,11 +18,11 @@ impl Qiz for Foo {
}
struct Bar {
//~^ ERROR E0038
foos: &'static [&'static (Qiz + 'static)]
}
const FOO : Foo = Foo;
const BAR : Bar = Bar { foos: &[&FOO]};
//~^ ERROR: cannot convert to a trait object because trait `Qiz` is not object-safe [E0038]
fn main() { }

View file

@ -25,5 +25,6 @@ impl Bar for Thing { }
fn main() {
let mut thing = Thing;
let test: &mut Bar = &mut thing;
//~^ ERROR cannot convert to a trait object because trait `Bar` is not object-safe
//~^ ERROR E0038
//~| ERROR E0038
}

View file

@ -23,14 +23,15 @@ trait Quux {
fn make_bar<T:Bar>(t: &T) -> &Bar {
t
//~^ ERROR `Bar` is not object-safe
//~^ ERROR E0038
//~| NOTE method `bar` has generic type parameters
}
fn make_bar_explicit<T:Bar>(t: &T) -> &Bar {
t as &Bar
//~^ ERROR `Bar` is not object-safe
//~^ ERROR E0038
//~| NOTE method `bar` has generic type parameters
//~| ERROR E0038
}
fn make_quux<T:Quux>(t: &T) -> &Quux {

View file

@ -18,7 +18,7 @@ trait Expr: Debug + PartialEq {
//#[derive(PartialEq)]
#[derive(Debug)]
struct SExpr<'x> {
struct SExpr<'x> { //~ ERROR E0038
elements: Vec<Box<Expr+ 'x>>,
}
@ -43,8 +43,8 @@ impl <'x> Expr for SExpr<'x> {
}
fn main() {
let a: Box<Expr> = Box::new(SExpr::new()); //~ ERROR trait `Expr` is not object-safe
let b: Box<Expr> = Box::new(SExpr::new()); //~ ERROR trait `Expr` is not object-safe
let a: Box<Expr> = Box::new(SExpr::new());
let b: Box<Expr> = Box::new(SExpr::new());
assert_eq!(a , b);
}

View file

@ -26,26 +26,28 @@ trait Quux {
fn make_bar<T:Bar>(t: &T) -> &Bar {
t
//~^ ERROR `Bar` is not object-safe
//~^ ERROR E0038
//~| NOTE method `bar` references the `Self` type in its arguments or return type
}
fn make_bar_explicit<T:Bar>(t: &T) -> &Bar {
t as &Bar
//~^ ERROR `Bar` is not object-safe
//~^ ERROR E0038
//~| NOTE method `bar` references the `Self` type in its arguments or return type
//~| ERROR E0038
}
fn make_baz<T:Baz>(t: &T) -> &Baz {
t
//~^ ERROR `Baz` is not object-safe
//~^ ERROR E0038
//~| NOTE method `bar` references the `Self` type in its arguments or return type
}
fn make_baz_explicit<T:Baz>(t: &T) -> &Baz {
t as &Baz
//~^ ERROR `Baz` is not object-safe
//~^ ERROR E0038
//~| NOTE method `bar` references the `Self` type in its arguments or return type
//~| ERROR E0038
}
fn make_quux<T:Quux>(t: &T) -> &Quux {

View file

@ -17,14 +17,15 @@ trait Foo {
fn foo_implicit<T:Foo+'static>(b: Box<T>) -> Box<Foo+'static> {
b
//~^ ERROR cannot convert to a trait object
//~^ ERROR E0038
//~| NOTE method `foo` has no receiver
}
fn foo_explicit<T:Foo+'static>(b: Box<T>) -> Box<Foo+'static> {
b as Box<Foo>
//~^ ERROR cannot convert to a trait object
//~^ ERROR E0038
//~| NOTE method `foo` has no receiver
//~| ERROR E0038
}
fn main() {

View file

@ -19,14 +19,15 @@ trait Bar
fn make_bar<T:Bar>(t: &T) -> &Bar {
t
//~^ ERROR `Bar` is not object-safe
//~^ ERROR E0038
//~| NOTE the trait cannot require that `Self : Sized`
}
fn make_bar_explicit<T:Bar>(t: &T) -> &Bar {
t as &Bar
//~^ ERROR `Bar` is not object-safe
//~^ ERROR E0038
//~| NOTE the trait cannot require that `Self : Sized`
//~| ERROR E0038
}
fn main() {

View file

@ -17,14 +17,15 @@ trait Bar : Sized {
fn make_bar<T:Bar>(t: &T) -> &Bar {
t
//~^ ERROR `Bar` is not object-safe
//~^ ERROR E0038
//~| NOTE the trait cannot require that `Self : Sized`
}
fn make_bar_explicit<T:Bar>(t: &T) -> &Bar {
t as &Bar
//~^ ERROR `Bar` is not object-safe
//~^ ERROR E0038
//~| NOTE the trait cannot require that `Self : Sized`
//~| ERROR E0038
}
fn main() {

View file

@ -24,7 +24,7 @@ fn make_bar<T:Bar<u32>>(t: &T) -> &Bar<u32> {
fn make_baz<T:Baz>(t: &T) -> &Baz {
t
//~^ ERROR `Baz` is not object-safe
//~^ ERROR E0038
//~| NOTE the trait cannot use `Self` as a type parameter in the supertrait listing
}

View file

@ -21,10 +21,10 @@ fn main() {
// str
std::intrinsics::type_name::<str>(),
// Trait
std::intrinsics::type_name::<Copy>(),
std::intrinsics::type_name::<Send>(),
// Newtype
std::intrinsics::type_name::<NT>(),
// DST
std::intrinsics::type_name::<DST>()
)}, ("[u8]", "str", "core::marker::Copy + 'static", "NT", "DST"));
)}, ("[u8]", "str", "core::marker::Send + 'static", "NT", "DST"));
}