Skip to content

Commit 6d728d0

Browse files
committed
RFC 2027: Add tests that feature gate properly gates
1 parent ed822d2 commit 6d728d0

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Test that the use of the non object-safe trait objects
2+
// are gated by `object_safe_for_dispatch` feature gate.
3+
4+
trait NonObjectSafe1: Sized {}
5+
6+
trait NonObjectSafe2 {
7+
fn static_fn() {}
8+
}
9+
10+
trait NonObjectSafe3 {
11+
fn foo<T>(&self);
12+
}
13+
14+
trait NonObjectSafe4 {
15+
fn foo(&self, &Self);
16+
}
17+
18+
fn takes_non_object_safe_ref<T>(obj: &dyn NonObjectSafe1) {
19+
//~^ ERROR E0038
20+
}
21+
22+
fn return_non_object_safe_ref() -> &'static dyn NonObjectSafe2 {
23+
//~^ ERROR E0038
24+
loop {}
25+
}
26+
27+
fn takes_non_object_safe_box(obj: Box<NonObjectSafe3>) {
28+
//~^ ERROR E0038
29+
}
30+
31+
fn return_non_object_safe_rc() -> std::rc::Rc<NonObjectSafe4> {
32+
//~^ ERROR E0038
33+
loop {}
34+
}
35+
36+
trait Trait {}
37+
38+
impl Trait for NonObjectSafe1 {}
39+
//~^ ERROR E0038
40+
41+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
error[E0038]: the trait `NonObjectSafe1` cannot be made into an object
2+
--> $DIR/feature-gate-object_safe_for_dispatch.rs:18:1
3+
|
4+
LL | fn takes_non_object_safe_ref<T>(obj: &dyn NonObjectSafe1) {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NonObjectSafe1` cannot be made into an object
6+
|
7+
= note: the trait cannot require that `Self : Sized`
8+
9+
error[E0038]: the trait `NonObjectSafe2` cannot be made into an object
10+
--> $DIR/feature-gate-object_safe_for_dispatch.rs:22:1
11+
|
12+
LL | fn return_non_object_safe_ref() -> &'static dyn NonObjectSafe2 {
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NonObjectSafe2` cannot be made into an object
14+
|
15+
= note: method `static_fn` has no receiver
16+
17+
error[E0038]: the trait `NonObjectSafe3` cannot be made into an object
18+
--> $DIR/feature-gate-object_safe_for_dispatch.rs:27:1
19+
|
20+
LL | fn takes_non_object_safe_box(obj: Box<NonObjectSafe3>) {
21+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NonObjectSafe3` cannot be made into an object
22+
|
23+
= note: method `foo` has generic type parameters
24+
25+
error[E0038]: the trait `NonObjectSafe4` cannot be made into an object
26+
--> $DIR/feature-gate-object_safe_for_dispatch.rs:31:1
27+
|
28+
LL | fn return_non_object_safe_rc() -> std::rc::Rc<NonObjectSafe4> {
29+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NonObjectSafe4` cannot be made into an object
30+
|
31+
= note: method `foo` references the `Self` type in its arguments or return type
32+
33+
error[E0038]: the trait `NonObjectSafe1` cannot be made into an object
34+
--> $DIR/feature-gate-object_safe_for_dispatch.rs:38:6
35+
|
36+
LL | impl Trait for NonObjectSafe1 {}
37+
| ^^^^^ the trait `NonObjectSafe1` cannot be made into an object
38+
|
39+
= note: the trait cannot require that `Self : Sized`
40+
41+
error: aborting due to 5 previous errors
42+
43+
For more information about this error, try `rustc --explain E0038`.

0 commit comments

Comments
 (0)