Skip to content

Commit 09bf2fe

Browse files
committed
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
1 parent d15d743 commit 09bf2fe

14 files changed

+34
-27
lines changed

src/test/auxiliary/issue13507.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ pub mod testtypes {
7272
// Tests TyTrait
7373
pub trait FooTrait {
7474
fn foo_method(&self) -> usize;
75-
fn foo_static_method() -> usize;
7675
}
7776

7877
// Tests TyStruct

src/test/compile-fail/cast-to-unsized-trait-object-suggestion.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
// except according to those terms.
1010

1111
fn main() {
12-
&1 as Copy;
12+
&1 as Send;
1313
//~^ ERROR cast to unsized type
1414
//~| HELP try casting to a reference instead:
15-
//~| SUGGESTION &1 as &Copy;
16-
Box::new(1) as Copy;
15+
//~| SUGGESTION &1 as &Send;
16+
Box::new(1) as Send;
1717
//~^ ERROR cast to unsized type
1818
//~| HELP try casting to a `Box` instead:
19-
//~| SUGGESTION Box::new(1) as Box<Copy>;
19+
//~| SUGGESTION Box::new(1) as Box<Send>;
2020
}

src/test/compile-fail/infinite-instantiation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// so for now just live with it.
1616
// This test case was originally for issue #2258.
1717

18-
trait ToOpt {
18+
trait ToOpt: Sized {
1919
fn to_option(&self) -> Option<Self>;
2020
}
2121

src/test/compile-fail/issue-18959.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ impl Foo for Thing {
2121
fn foo(b: &Bar) {
2222
b.foo(&0)
2323
//~^ ERROR the trait `Foo` is not implemented for the type `Bar`
24+
//~| ERROR E0038
2425
}
2526

2627
fn main() {
2728
let mut thing = Thing;
28-
let test: &Bar = &mut thing; //~ ERROR cannot convert to a trait object
29+
let test: &Bar = &mut thing; //~ ERROR E0038
2930
foo(test);
3031
}

src/test/compile-fail/issue-19380.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ impl Qiz for Foo {
1818
}
1919

2020
struct Bar {
21+
//~^ ERROR E0038
2122
foos: &'static [&'static (Qiz + 'static)]
2223
}
2324

2425
const FOO : Foo = Foo;
2526
const BAR : Bar = Bar { foos: &[&FOO]};
26-
//~^ ERROR: cannot convert to a trait object because trait `Qiz` is not object-safe [E0038]
2727

2828
fn main() { }

src/test/compile-fail/issue-19538.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ impl Bar for Thing { }
2525
fn main() {
2626
let mut thing = Thing;
2727
let test: &mut Bar = &mut thing;
28-
//~^ ERROR cannot convert to a trait object because trait `Bar` is not object-safe
28+
//~^ ERROR E0038
29+
//~| ERROR E0038
2930
}

src/test/compile-fail/object-safety-generics.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ trait Quux {
2323

2424
fn make_bar<T:Bar>(t: &T) -> &Bar {
2525
t
26-
//~^ ERROR `Bar` is not object-safe
26+
//~^ ERROR E0038
2727
//~| NOTE method `bar` has generic type parameters
2828
}
2929

3030
fn make_bar_explicit<T:Bar>(t: &T) -> &Bar {
3131
t as &Bar
32-
//~^ ERROR `Bar` is not object-safe
32+
//~^ ERROR E0038
3333
//~| NOTE method `bar` has generic type parameters
34+
//~| ERROR E0038
3435
}
3536

3637
fn make_quux<T:Quux>(t: &T) -> &Quux {

src/test/compile-fail/object-safety-issue-22040.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ trait Expr: Debug + PartialEq {
1818

1919
//#[derive(PartialEq)]
2020
#[derive(Debug)]
21-
struct SExpr<'x> {
21+
struct SExpr<'x> { //~ ERROR E0038
2222
elements: Vec<Box<Expr+ 'x>>,
2323
}
2424

@@ -43,8 +43,8 @@ impl <'x> Expr for SExpr<'x> {
4343
}
4444

4545
fn main() {
46-
let a: Box<Expr> = Box::new(SExpr::new()); //~ ERROR trait `Expr` is not object-safe
47-
let b: Box<Expr> = Box::new(SExpr::new()); //~ ERROR trait `Expr` is not object-safe
46+
let a: Box<Expr> = Box::new(SExpr::new());
47+
let b: Box<Expr> = Box::new(SExpr::new());
4848

4949
assert_eq!(a , b);
5050
}

src/test/compile-fail/object-safety-mentions-Self.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,28 @@ trait Quux {
2626

2727
fn make_bar<T:Bar>(t: &T) -> &Bar {
2828
t
29-
//~^ ERROR `Bar` is not object-safe
29+
//~^ ERROR E0038
3030
//~| NOTE method `bar` references the `Self` type in its arguments or return type
3131
}
3232

3333
fn make_bar_explicit<T:Bar>(t: &T) -> &Bar {
3434
t as &Bar
35-
//~^ ERROR `Bar` is not object-safe
35+
//~^ ERROR E0038
3636
//~| NOTE method `bar` references the `Self` type in its arguments or return type
37+
//~| ERROR E0038
3738
}
3839

3940
fn make_baz<T:Baz>(t: &T) -> &Baz {
4041
t
41-
//~^ ERROR `Baz` is not object-safe
42+
//~^ ERROR E0038
4243
//~| NOTE method `bar` references the `Self` type in its arguments or return type
4344
}
4445

4546
fn make_baz_explicit<T:Baz>(t: &T) -> &Baz {
4647
t as &Baz
47-
//~^ ERROR `Baz` is not object-safe
48+
//~^ ERROR E0038
4849
//~| NOTE method `bar` references the `Self` type in its arguments or return type
50+
//~| ERROR E0038
4951
}
5052

5153
fn make_quux<T:Quux>(t: &T) -> &Quux {

src/test/compile-fail/object-safety-no-static.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ trait Foo {
1717

1818
fn foo_implicit<T:Foo+'static>(b: Box<T>) -> Box<Foo+'static> {
1919
b
20-
//~^ ERROR cannot convert to a trait object
20+
//~^ ERROR E0038
2121
//~| NOTE method `foo` has no receiver
2222
}
2323

2424
fn foo_explicit<T:Foo+'static>(b: Box<T>) -> Box<Foo+'static> {
2525
b as Box<Foo>
26-
//~^ ERROR cannot convert to a trait object
26+
//~^ ERROR E0038
2727
//~| NOTE method `foo` has no receiver
28+
//~| ERROR E0038
2829
}
2930

3031
fn main() {

src/test/compile-fail/object-safety-sized-2.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ trait Bar
1919

2020
fn make_bar<T:Bar>(t: &T) -> &Bar {
2121
t
22-
//~^ ERROR `Bar` is not object-safe
22+
//~^ ERROR E0038
2323
//~| NOTE the trait cannot require that `Self : Sized`
2424
}
2525

2626
fn make_bar_explicit<T:Bar>(t: &T) -> &Bar {
2727
t as &Bar
28-
//~^ ERROR `Bar` is not object-safe
28+
//~^ ERROR E0038
2929
//~| NOTE the trait cannot require that `Self : Sized`
30+
//~| ERROR E0038
3031
}
3132

3233
fn main() {

src/test/compile-fail/object-safety-sized.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ trait Bar : Sized {
1717

1818
fn make_bar<T:Bar>(t: &T) -> &Bar {
1919
t
20-
//~^ ERROR `Bar` is not object-safe
20+
//~^ ERROR E0038
2121
//~| NOTE the trait cannot require that `Self : Sized`
2222
}
2323

2424
fn make_bar_explicit<T:Bar>(t: &T) -> &Bar {
2525
t as &Bar
26-
//~^ ERROR `Bar` is not object-safe
26+
//~^ ERROR E0038
2727
//~| NOTE the trait cannot require that `Self : Sized`
28+
//~| ERROR E0038
2829
}
2930

3031
fn main() {

src/test/compile-fail/object-safety-supertrait-mentions-Self.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn make_bar<T:Bar<u32>>(t: &T) -> &Bar<u32> {
2424

2525
fn make_baz<T:Baz>(t: &T) -> &Baz {
2626
t
27-
//~^ ERROR `Baz` is not object-safe
27+
//~^ ERROR E0038
2828
//~| NOTE the trait cannot use `Self` as a type parameter in the supertrait listing
2929
}
3030

src/test/run-pass/issue-21058.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ fn main() {
2121
// str
2222
std::intrinsics::type_name::<str>(),
2323
// Trait
24-
std::intrinsics::type_name::<Copy>(),
24+
std::intrinsics::type_name::<Send>(),
2525
// Newtype
2626
std::intrinsics::type_name::<NT>(),
2727
// DST
2828
std::intrinsics::type_name::<DST>()
29-
)}, ("[u8]", "str", "core::marker::Copy + 'static", "NT", "DST"));
29+
)}, ("[u8]", "str", "core::marker::Send + 'static", "NT", "DST"));
3030
}

0 commit comments

Comments
 (0)