Skip to content

Commit b57bd84

Browse files
committed
RFC 2027: Add revisions to some existing object safety tests
1 parent 441ac11 commit b57bd84

25 files changed

+221
-48
lines changed

src/test/ui/arbitrary-self-types-not-object-safe.stderr src/test/ui/arbitrary-self-types-not-object-safe.curr.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error[E0038]: the trait `Foo` cannot be made into an object
2-
--> $DIR/arbitrary-self-types-not-object-safe.rs:31:32
2+
--> $DIR/arbitrary-self-types-not-object-safe.rs:34:32
33
|
44
LL | let x = Rc::new(5usize) as Rc<Foo>;
55
| ^^^^^^^ the trait `Foo` cannot be made into an object
66
|
77
= note: method `foo`'s receiver cannot be dispatched on
88

99
error[E0038]: the trait `Foo` cannot be made into an object
10-
--> $DIR/arbitrary-self-types-not-object-safe.rs:31:13
10+
--> $DIR/arbitrary-self-types-not-object-safe.rs:34:13
1111
|
1212
LL | let x = Rc::new(5usize) as Rc<Foo>;
1313
| ^^^^^^^^^^^^^^^ the trait `Foo` cannot be made into an object
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0038]: the trait `Foo` cannot be made into an object
2+
--> $DIR/arbitrary-self-types-not-object-safe.rs:34:32
3+
|
4+
LL | let x = Rc::new(5usize) as Rc<Foo>;
5+
| ^^^^^^^ the trait `Foo` cannot be made into an object
6+
|
7+
= note: method `foo`'s receiver cannot be dispatched on
8+
= note: required by cast to type 'std::rc::Rc<dyn Foo>'
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0038`.

src/test/ui/arbitrary-self-types-not-object-safe.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// revisions: curr object_safe_for_dispatch
2+
3+
#![cfg_attr(object_safe_for_dispatch, feature(object_safe_for_dispatch))]
14
#![feature(arbitrary_self_types)]
25

36
use std::rc::Rc;
@@ -29,8 +32,9 @@ impl Bar for usize {
2932

3033
fn make_foo() {
3134
let x = Rc::new(5usize) as Rc<Foo>;
32-
//~^ ERROR E0038
33-
//~| ERROR E0038
35+
//[curr]~^ ERROR E0038
36+
//[curr]~| ERROR E0038
37+
//[object_safe_for_dispatch]~^^^ ERROR E0038
3438
}
3539

3640
fn make_bar() {

src/test/ui/kindck/kindck-inherited-copy-bound.stderr src/test/ui/kindck/kindck-inherited-copy-bound.curr.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
error[E0277]: the trait bound `std::boxed::Box<{integer}>: std::marker::Copy` is not satisfied
2-
--> $DIR/kindck-inherited-copy-bound.rs:18:5
2+
--> $DIR/kindck-inherited-copy-bound.rs:21:5
33
|
4-
LL | take_param(&x); //~ ERROR E0277
4+
LL | take_param(&x); //[curr]~ ERROR E0277
55
| ^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `std::boxed::Box<{integer}>`
66
|
77
= note: required because of the requirements on the impl of `Foo` for `std::boxed::Box<{integer}>`
88
note: required by `take_param`
9-
--> $DIR/kindck-inherited-copy-bound.rs:14:1
9+
--> $DIR/kindck-inherited-copy-bound.rs:17:1
1010
|
1111
LL | fn take_param<T:Foo>(foo: &T) { }
1212
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1313

1414
error[E0038]: the trait `Foo` cannot be made into an object
15-
--> $DIR/kindck-inherited-copy-bound.rs:24:19
15+
--> $DIR/kindck-inherited-copy-bound.rs:28:19
1616
|
1717
LL | let z = &x as &Foo;
1818
| ^^^^ the trait `Foo` cannot be made into an object
1919
|
2020
= note: the trait cannot require that `Self : Sized`
2121

2222
error[E0038]: the trait `Foo` cannot be made into an object
23-
--> $DIR/kindck-inherited-copy-bound.rs:24:13
23+
--> $DIR/kindck-inherited-copy-bound.rs:28:13
2424
|
2525
LL | let z = &x as &Foo;
2626
| ^^ the trait `Foo` cannot be made into an object
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error[E0277]: the trait bound `std::boxed::Box<{integer}>: std::marker::Copy` is not satisfied
2+
--> $DIR/kindck-inherited-copy-bound.rs:21:5
3+
|
4+
LL | take_param(&x); //[curr]~ ERROR E0277
5+
| ^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `std::boxed::Box<{integer}>`
6+
|
7+
= note: required because of the requirements on the impl of `Foo` for `std::boxed::Box<{integer}>`
8+
note: required by `take_param`
9+
--> $DIR/kindck-inherited-copy-bound.rs:17:1
10+
|
11+
LL | fn take_param<T:Foo>(foo: &T) { }
12+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13+
14+
error[E0038]: the trait `Foo` cannot be made into an object
15+
--> $DIR/kindck-inherited-copy-bound.rs:28:19
16+
|
17+
LL | let z = &x as &Foo;
18+
| ^^^^ the trait `Foo` cannot be made into an object
19+
|
20+
= note: the trait cannot require that `Self : Sized`
21+
= note: required by cast to type '&dyn Foo'
22+
23+
error: aborting due to 2 previous errors
24+
25+
Some errors occurred: E0038, E0277.
26+
For more information about an error, try `rustc --explain E0038`.

src/test/ui/kindck/kindck-inherited-copy-bound.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// Test that Copy bounds inherited by trait are checked.
2+
//
3+
// revisions: curr object_safe_for_dispatch
24

5+
#![cfg_attr(object_safe_for_dispatch, feature(object_safe_for_dispatch))]
36
#![feature(box_syntax)]
47

58
use std::any::Any;
@@ -15,15 +18,17 @@ fn take_param<T:Foo>(foo: &T) { }
1518

1619
fn a() {
1720
let x: Box<_> = box 3;
18-
take_param(&x); //~ ERROR E0277
21+
take_param(&x); //[curr]~ ERROR E0277
22+
//[object_safe_for_dispatch]~^ ERROR E0277
1923
}
2024

2125
fn b() {
2226
let x: Box<_> = box 3;
2327
let y = &x;
2428
let z = &x as &Foo;
25-
//~^ ERROR E0038
26-
//~| ERROR E0038
29+
//[curr]~^ ERROR E0038
30+
//[curr]~| ERROR E0038
31+
//[object_safe_for_dispatch]~^^^ ERROR E0038
2732
}
2833

2934
fn main() { }

src/test/ui/object-safety/object-safety-associated-consts.stderr src/test/ui/object-safety/object-safety-associated-consts.curr.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0038]: the trait `Bar` cannot be made into an object
2-
--> $DIR/object-safety-associated-consts.rs:9:1
2+
--> $DIR/object-safety-associated-consts.rs:12:1
33
|
44
LL | fn make_bar<T:Bar>(t: &T) -> &Bar {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Bar` cannot be made into an object
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0038]: the trait `Bar` cannot be made into an object
2+
--> $DIR/object-safety-associated-consts.rs:14:5
3+
|
4+
LL | t
5+
| ^ the trait `Bar` cannot be made into an object
6+
|
7+
= note: the trait cannot contain associated consts like `X`
8+
= note: required when trying to coerce from type `&T` to type '&dyn Bar`
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0038`.

src/test/ui/object-safety/object-safety-associated-consts.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
// Check that we correctly prevent users from making trait objects
22
// from traits with associated consts.
3+
//
4+
// revisions: curr object_safe_for_dispatch
35

6+
#![cfg_attr(object_safe_for_dispatch, feature(object_safe_for_dispatch))]
47

58
trait Bar {
69
const X: usize;
710
}
811

912
fn make_bar<T:Bar>(t: &T) -> &Bar {
10-
//~^ ERROR E0038
13+
//[curr]~^ ERROR E0038
1114
t
15+
//[object_safe_for_dispatch]~^ ERROR E0038
1216
}
1317

1418
fn main() {

src/test/ui/object-safety/object-safety-generics.stderr src/test/ui/object-safety/object-safety-generics.curr.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error[E0038]: the trait `Bar` cannot be made into an object
2-
--> $DIR/object-safety-generics.rs:14:1
2+
--> $DIR/object-safety-generics.rs:18:1
33
|
44
LL | fn make_bar<T:Bar>(t: &T) -> &Bar {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Bar` cannot be made into an object
66
|
77
= note: method `bar` has generic type parameters
88

99
error[E0038]: the trait `Bar` cannot be made into an object
10-
--> $DIR/object-safety-generics.rs:19:1
10+
--> $DIR/object-safety-generics.rs:24:1
1111
|
1212
LL | fn make_bar_explicit<T:Bar>(t: &T) -> &Bar {
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Bar` cannot be made into an object
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0038]: the trait `Bar` cannot be made into an object
2+
--> $DIR/object-safety-generics.rs:20:5
3+
|
4+
LL | t
5+
| ^ the trait `Bar` cannot be made into an object
6+
|
7+
= note: method `bar` has generic type parameters
8+
= note: required when trying to coerce from type `&T` to type '&dyn Bar`
9+
10+
error[E0038]: the trait `Bar` cannot be made into an object
11+
--> $DIR/object-safety-generics.rs:26:10
12+
|
13+
LL | t as &Bar
14+
| ^^^^ the trait `Bar` cannot be made into an object
15+
|
16+
= note: method `bar` has generic type parameters
17+
= note: required by cast to type '&dyn Bar'
18+
19+
error: aborting due to 2 previous errors
20+
21+
For more information about this error, try `rustc --explain E0038`.

src/test/ui/object-safety/object-safety-generics.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Check that we correctly prevent users from making trait objects
22
// from traits with generic methods, unless `where Self : Sized` is
33
// present.
4+
// revisions: curr object_safe_for_dispatch
5+
6+
#![cfg_attr(object_safe_for_dispatch, feature(object_safe_for_dispatch))]
7+
48

59
trait Bar {
610
fn bar<T>(&self, t: T);
@@ -12,13 +16,15 @@ trait Quux {
1216
}
1317

1418
fn make_bar<T:Bar>(t: &T) -> &Bar {
15-
//~^ ERROR E0038
19+
//[curr]~^ ERROR E0038
1620
t
21+
//[object_safe_for_dispatch]~^ ERROR E0038
1722
}
1823

1924
fn make_bar_explicit<T:Bar>(t: &T) -> &Bar {
20-
//~^ ERROR E0038
25+
//[curr]~^ ERROR E0038
2126
t as &Bar
27+
//[object_safe_for_dispatch]~^ ERROR E0038
2228
}
2329

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

src/test/ui/object-safety/object-safety-mentions-Self.stderr src/test/ui/object-safety/object-safety-mentions-Self.curr.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
error[E0038]: the trait `Bar` cannot be made into an object
2-
--> $DIR/object-safety-mentions-Self.rs:17:1
2+
--> $DIR/object-safety-mentions-Self.rs:22:1
33
|
44
LL | fn make_bar<T:Bar>(t: &T) -> &Bar {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Bar` cannot be made into an object
66
|
77
= note: method `bar` references the `Self` type in its arguments or return type
88

99
error[E0038]: the trait `Baz` cannot be made into an object
10-
--> $DIR/object-safety-mentions-Self.rs:22:1
10+
--> $DIR/object-safety-mentions-Self.rs:28:1
1111
|
1212
LL | fn make_baz<T:Baz>(t: &T) -> &Baz {
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Baz` cannot be made into an object
1414
|
15-
= note: method `bar` references the `Self` type in its arguments or return type
15+
= note: method `baz` references the `Self` type in its arguments or return type
1616

1717
error: aborting due to 2 previous errors
1818

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0038]: the trait `Bar` cannot be made into an object
2+
--> $DIR/object-safety-mentions-Self.rs:24:5
3+
|
4+
LL | t
5+
| ^ the trait `Bar` cannot be made into an object
6+
|
7+
= note: method `bar` references the `Self` type in its arguments or return type
8+
= note: required when trying to coerce from type `&T` to type '&dyn Bar`
9+
10+
error[E0038]: the trait `Baz` cannot be made into an object
11+
--> $DIR/object-safety-mentions-Self.rs:30:5
12+
|
13+
LL | t
14+
| ^ the trait `Baz` cannot be made into an object
15+
|
16+
= note: method `baz` references the `Self` type in its arguments or return type
17+
= note: required when trying to coerce from type `&T` to type '&dyn Baz`
18+
19+
error: aborting due to 2 previous errors
20+
21+
For more information about this error, try `rustc --explain E0038`.
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,42 @@
11
// Check that we correctly prevent users from making trait objects
22
// form traits that make use of `Self` in an argument or return
33
// position, unless `where Self : Sized` is present..
4+
//
5+
// revisions: curr object_safe_for_dispatch
6+
7+
#![cfg_attr(object_safe_for_dispatch, feature(object_safe_for_dispatch))]
8+
49

510
trait Bar {
611
fn bar(&self, x: &Self);
712
}
813

914
trait Baz {
10-
fn bar(&self) -> Self;
15+
fn baz(&self) -> Self;
1116
}
1217

1318
trait Quux {
14-
fn get(&self, s: &Self) -> Self where Self : Sized;
19+
fn quux(&self, s: &Self) -> Self where Self : Sized;
1520
}
1621

1722
fn make_bar<T:Bar>(t: &T) -> &Bar {
18-
//~^ ERROR E0038
19-
loop { }
23+
//[curr]~^ ERROR E0038
24+
t
25+
//[object_safe_for_dispatch]~^ ERROR E0038
2026
}
2127

2228
fn make_baz<T:Baz>(t: &T) -> &Baz {
23-
//~^ ERROR E0038
29+
//[curr]~^ ERROR E0038
2430
t
31+
//[object_safe_for_dispatch]~^ ERROR E0038
2532
}
2633

2734
fn make_quux<T:Quux>(t: &T) -> &Quux {
2835
t
2936
}
3037

3138
fn make_quux_explicit<T:Quux>(t: &T) -> &Quux {
32-
t as &Quux
39+
t as &dyn Quux
3340
}
3441

35-
fn main() {
36-
}
42+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0038]: the trait `Foo` cannot be made into an object
2+
--> $DIR/object-safety-no-static.rs:12:1
3+
|
4+
LL | fn diverges() -> Box<dyn Foo> {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` cannot be made into an object
6+
|
7+
= note: method `foo` has no receiver
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0038`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0038]: the trait `Foo` cannot be made into an object
2+
--> $DIR/object-safety-no-static.rs:22:27
3+
|
4+
LL | let b: Box<dyn Foo> = Box::new(Bar);
5+
| ^^^^^^^^^^^^^ the trait `Foo` cannot be made into an object
6+
|
7+
= note: method `foo` has no receiver
8+
= note: required when trying to coerce from type `std::boxed::Box<Bar>` to type 'std::boxed::Box<dyn Foo>`
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0038`.
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
// Check that we correctly prevent users from making trait objects
22
// from traits with static methods.
3+
//
4+
// revisions: curr object_safe_for_dispatch
5+
6+
#![cfg_attr(object_safe_for_dispatch, feature(object_safe_for_dispatch))]
37

48
trait Foo {
5-
fn foo();
9+
fn foo() {}
610
}
711

8-
fn foo_implicit<T:Foo+'static>(b: Box<T>) -> Box<Foo+'static> {
9-
//~^ ERROR E0038
12+
fn diverges() -> Box<dyn Foo> {
13+
//[curr]~^ ERROR E0038
1014
loop { }
1115
}
1216

17+
struct Bar;
18+
19+
impl Foo for Bar {}
20+
1321
fn main() {
22+
let b: Box<dyn Foo> = Box::new(Bar);
23+
//[object_safe_for_dispatch]~^ ERROR E0038
1424
}

0 commit comments

Comments
 (0)