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:
parent
d15d743fa8
commit
09bf2fef22
@ -72,7 +72,6 @@ pub enum FooEnum {
|
||||
// Tests TyTrait
|
||||
pub trait FooTrait {
|
||||
fn foo_method(&self) -> usize;
|
||||
fn foo_static_method() -> usize;
|
||||
}
|
||||
|
||||
// Tests TyStruct
|
||||
|
@ -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>;
|
||||
}
|
||||
|
@ -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>;
|
||||
}
|
||||
|
||||
|
@ -21,10 +21,11 @@ fn foo<T>(&self, _: &T) {}
|
||||
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);
|
||||
}
|
||||
|
@ -18,11 +18,11 @@ fn qiz() {}
|
||||
}
|
||||
|
||||
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() { }
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -23,14 +23,15 @@ fn bar<T>(&self, t: T)
|
||||
|
||||
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 {
|
||||
|
@ -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 @@ fn print_element_count(&self) {
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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() {
|
||||
|
@ -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() {
|
||||
|
@ -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() {
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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"));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user