Rename feature object_safe_for_dispatch to dyn_compatible_for_dispatch
This commit is contained in:
parent
62b24ea7c5
commit
2e7a52b22f
42 changed files with 130 additions and 124 deletions
|
@ -154,6 +154,10 @@ declare_features! (
|
||||||
/// then removed. But there was no utility storing it separately, so now
|
/// then removed. But there was no utility storing it separately, so now
|
||||||
/// it's in this list.
|
/// it's in this list.
|
||||||
(removed, no_stack_check, "1.0.0", None, None),
|
(removed, no_stack_check, "1.0.0", None, None),
|
||||||
|
/// Allows making `dyn Trait` well-formed even if `Trait` is not dyn-compatible (object safe).
|
||||||
|
/// Renamed to `dyn_compatible_for_dispatch`.
|
||||||
|
(removed, object_safe_for_dispatch, "CURRENT_RUSTC_VERSION", Some(43561),
|
||||||
|
Some("renamed to `dyn_compatible_for_dispatch`")),
|
||||||
/// Allows using `#[on_unimplemented(..)]` on traits.
|
/// Allows using `#[on_unimplemented(..)]` on traits.
|
||||||
/// (Moved to `rustc_attrs`.)
|
/// (Moved to `rustc_attrs`.)
|
||||||
(removed, on_unimplemented, "1.40.0", None, None),
|
(removed, on_unimplemented, "1.40.0", None, None),
|
||||||
|
|
|
@ -259,6 +259,14 @@ declare_features! (
|
||||||
(unstable, doc_notable_trait, "1.52.0", Some(45040)),
|
(unstable, doc_notable_trait, "1.52.0", Some(45040)),
|
||||||
/// Allows using the `may_dangle` attribute (RFC 1327).
|
/// Allows using the `may_dangle` attribute (RFC 1327).
|
||||||
(unstable, dropck_eyepatch, "1.10.0", Some(34761)),
|
(unstable, dropck_eyepatch, "1.10.0", Some(34761)),
|
||||||
|
/// Allows making `dyn Trait` well-formed even if `Trait` is not dyn-compatible[^1].
|
||||||
|
/// In that case, `dyn Trait: Trait` does not hold. Moreover, coercions and
|
||||||
|
/// casts in safe Rust to `dyn Trait` for such a `Trait` is also forbidden.
|
||||||
|
///
|
||||||
|
/// Renamed from `object_safe_for_dispatch`.
|
||||||
|
///
|
||||||
|
/// [^1]: Formerly known as "object safe".
|
||||||
|
(unstable, dyn_compatible_for_dispatch, "CURRENT_RUSTC_VERSION", Some(43561)),
|
||||||
/// Allows using the `#[fundamental]` attribute.
|
/// Allows using the `#[fundamental]` attribute.
|
||||||
(unstable, fundamental, "1.0.0", Some(29635)),
|
(unstable, fundamental, "1.0.0", Some(29635)),
|
||||||
/// Allows using `#[link_name="llvm.*"]`.
|
/// Allows using `#[link_name="llvm.*"]`.
|
||||||
|
@ -544,13 +552,6 @@ declare_features! (
|
||||||
(unstable, non_exhaustive_omitted_patterns_lint, "1.57.0", Some(89554)),
|
(unstable, non_exhaustive_omitted_patterns_lint, "1.57.0", Some(89554)),
|
||||||
/// Allows `for<T>` binders in where-clauses
|
/// Allows `for<T>` binders in where-clauses
|
||||||
(incomplete, non_lifetime_binders, "1.69.0", Some(108185)),
|
(incomplete, non_lifetime_binders, "1.69.0", Some(108185)),
|
||||||
/// Allows making `dyn Trait` well-formed even if `Trait` is not dyn-compatible[^1].
|
|
||||||
/// In that case, `dyn Trait: Trait` does not hold. Moreover, coercions and
|
|
||||||
/// casts in safe Rust to `dyn Trait` for such a `Trait` is also forbidden.
|
|
||||||
///
|
|
||||||
/// [^1]: Formerly known as "object safe".
|
|
||||||
// FIXME(dyn_compat_renaming): Rename feature.
|
|
||||||
(unstable, object_safe_for_dispatch, "1.40.0", Some(43561)),
|
|
||||||
/// Allows using enums in offset_of!
|
/// Allows using enums in offset_of!
|
||||||
(unstable, offset_of_enum, "1.75.0", Some(120141)),
|
(unstable, offset_of_enum, "1.75.0", Some(120141)),
|
||||||
/// Allows using fields with slice type in offset_of!
|
/// Allows using fields with slice type in offset_of!
|
||||||
|
|
|
@ -199,7 +199,7 @@ fn check_object_overlap<'tcx>(
|
||||||
for component_def_id in component_def_ids {
|
for component_def_id in component_def_ids {
|
||||||
if !tcx.is_dyn_compatible(component_def_id) {
|
if !tcx.is_dyn_compatible(component_def_id) {
|
||||||
// FIXME(dyn_compat_renaming): Rename test and update comment.
|
// FIXME(dyn_compat_renaming): Rename test and update comment.
|
||||||
// Without the 'object_safe_for_dispatch' feature this is an error
|
// Without the 'dyn_compatible_for_dispatch' feature this is an error
|
||||||
// which will be reported by wfcheck. Ignore it here.
|
// which will be reported by wfcheck. Ignore it here.
|
||||||
// This is tested by `coherence-impl-trait-for-trait-object-safe.rs`.
|
// This is tested by `coherence-impl-trait-for-trait-object-safe.rs`.
|
||||||
// With the feature enabled, the trait is not implemented automatically,
|
// With the feature enabled, the trait is not implemented automatically,
|
||||||
|
|
|
@ -776,6 +776,7 @@ symbols! {
|
||||||
dropck_eyepatch,
|
dropck_eyepatch,
|
||||||
dropck_parametricity,
|
dropck_parametricity,
|
||||||
dylib,
|
dylib,
|
||||||
|
dyn_compatible_for_dispatch,
|
||||||
dyn_metadata,
|
dyn_metadata,
|
||||||
dyn_star,
|
dyn_star,
|
||||||
dyn_trait,
|
dyn_trait,
|
||||||
|
|
|
@ -639,8 +639,8 @@ fn object_ty_for_trait<'tcx>(
|
||||||
/// contained by the trait object, because the object that needs to be coerced is behind
|
/// contained by the trait object, because the object that needs to be coerced is behind
|
||||||
/// a pointer.
|
/// a pointer.
|
||||||
///
|
///
|
||||||
/// In practice, we cannot use `dyn Trait` explicitly in the obligation because it would result
|
/// In practice, we cannot use `dyn Trait` explicitly in the obligation because it would result in
|
||||||
/// in a new check that `Trait` is dyn-compatible, creating a cycle (until object_safe_for_dispatch
|
/// a new check that `Trait` is dyn-compatible, creating a cycle (until dyn_compatible_for_dispatch
|
||||||
/// is stabilized, see tracking issue <https://github.com/rust-lang/rust/issues/43561>).
|
/// is stabilized, see tracking issue <https://github.com/rust-lang/rust/issues/43561>).
|
||||||
/// Instead, we fudge a little by introducing a new type parameter `U` such that
|
/// Instead, we fudge a little by introducing a new type parameter `U` such that
|
||||||
/// `Self: Unsize<U>` and `U: Trait + ?Sized`, and use `U` in place of `dyn Trait`.
|
/// `Self: Unsize<U>` and `U: Trait + ?Sized`, and use `U` in place of `dyn Trait`.
|
||||||
|
@ -674,7 +674,7 @@ fn receiver_is_dispatchable<'tcx>(
|
||||||
|
|
||||||
// the type `U` in the query
|
// the type `U` in the query
|
||||||
// use a bogus type parameter to mimic a forall(U) query using u32::MAX for now.
|
// use a bogus type parameter to mimic a forall(U) query using u32::MAX for now.
|
||||||
// FIXME(mikeyhew) this is a total hack. Once object_safe_for_dispatch is stabilized, we can
|
// FIXME(mikeyhew) this is a total hack. Once dyn_compatible_for_dispatch is stabilized, we can
|
||||||
// replace this with `dyn Trait`
|
// replace this with `dyn Trait`
|
||||||
let unsized_self_ty: Ty<'tcx> =
|
let unsized_self_ty: Ty<'tcx> =
|
||||||
Ty::new_param(tcx, u32::MAX, Symbol::intern("RustaceansAreAwesome"));
|
Ty::new_param(tcx, u32::MAX, Symbol::intern("RustaceansAreAwesome"));
|
||||||
|
|
|
@ -881,7 +881,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(principal) = data.principal() {
|
if let Some(principal) = data.principal() {
|
||||||
if !self.infcx.tcx.features().object_safe_for_dispatch {
|
if !self.infcx.tcx.features().dyn_compatible_for_dispatch {
|
||||||
principal.with_self_ty(self.tcx(), self_ty)
|
principal.with_self_ty(self.tcx(), self_ty)
|
||||||
} else if self.tcx().is_dyn_compatible(principal.def_id()) {
|
} else if self.tcx().is_dyn_compatible(principal.def_id()) {
|
||||||
principal.with_self_ty(self.tcx(), self_ty)
|
principal.with_self_ty(self.tcx(), self_ty)
|
||||||
|
|
|
@ -829,7 +829,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
|
||||||
// obligations that don't refer to Self and
|
// obligations that don't refer to Self and
|
||||||
// checking those
|
// checking those
|
||||||
|
|
||||||
let defer_to_coercion = tcx.features().object_safe_for_dispatch;
|
let defer_to_coercion = tcx.features().dyn_compatible_for_dispatch;
|
||||||
|
|
||||||
if !defer_to_coercion {
|
if !defer_to_coercion {
|
||||||
if let Some(principal) = data.principal_def_id() {
|
if let Some(principal) = data.principal_def_id() {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//@ known-bug: #120241
|
//@ known-bug: #120241
|
||||||
//@ edition:2021
|
//@ edition:2021
|
||||||
#![feature(object_safe_for_dispatch)]
|
#![feature(dyn_compatible_for_dispatch)]
|
||||||
#![feature(unsized_fn_params)]
|
#![feature(unsized_fn_params)]
|
||||||
|
|
||||||
fn guard(_s: Copy) -> bool {
|
fn guard(_s: Copy) -> bool {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//@ known-bug: #120241
|
//@ known-bug: #120241
|
||||||
//@ edition:2021
|
//@ edition:2021
|
||||||
#![feature(object_safe_for_dispatch)]
|
#![feature(dyn_compatible_for_dispatch)]
|
||||||
|
|
||||||
trait B {
|
trait B {
|
||||||
fn f(a: A) -> A;
|
fn f(a: A) -> A;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//@ known-bug: #120482
|
//@ known-bug: #120482
|
||||||
//@ edition:2021
|
//@ edition:2021
|
||||||
#![feature(object_safe_for_dispatch)]
|
#![feature(dyn_compatible_for_dispatch)]
|
||||||
|
|
||||||
trait B {
|
trait B {
|
||||||
fn bar(&self, x: &Self);
|
fn bar(&self, x: &Self);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//@ known-bug: rust-lang/rust#125512
|
//@ known-bug: rust-lang/rust#125512
|
||||||
//@ edition:2021
|
//@ edition:2021
|
||||||
#![feature(object_safe_for_dispatch)]
|
#![feature(dyn_compatible_for_dispatch)]
|
||||||
trait B {
|
trait B {
|
||||||
fn f(a: A) -> A;
|
fn f(a: A) -> A;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//@ known-bug: rust-lang/rust#128176
|
//@ known-bug: rust-lang/rust#128176
|
||||||
|
|
||||||
#![feature(generic_const_exprs)]
|
#![feature(generic_const_exprs)]
|
||||||
#![feature(object_safe_for_dispatch)]
|
#![feature(dyn_compatible_for_dispatch)]
|
||||||
trait X {
|
trait X {
|
||||||
type Y<const N: i16>;
|
type Y<const N: i16>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//@ known-bug: #130521
|
//@ known-bug: #130521
|
||||||
|
|
||||||
#![feature(object_safe_for_dispatch)]
|
#![feature(dyn_compatible_for_dispatch)]
|
||||||
struct Vtable(dyn Cap);
|
struct Vtable(dyn Cap);
|
||||||
|
|
||||||
trait Cap<'a> {}
|
trait Cap<'a> {}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Check that unsafe trait object do not implement themselves
|
// Check that unsafe trait object do not implement themselves
|
||||||
// automatically
|
// automatically
|
||||||
|
|
||||||
#![feature(object_safe_for_dispatch)]
|
#![feature(dyn_compatible_for_dispatch)]
|
||||||
|
|
||||||
trait Trait: Sized {
|
trait Trait: Sized {
|
||||||
fn call(&self);
|
fn call(&self);
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
// Test that the use of the dyn-incompatible trait objects
|
||||||
|
// are gated by the `dyn_compatible_for_dispatch` feature gate.
|
||||||
|
|
||||||
|
trait DynIncompatible1: Sized {}
|
||||||
|
|
||||||
|
trait DynIncompatible2 {
|
||||||
|
fn static_fn() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
trait DynIncompatible3 {
|
||||||
|
fn foo<T>(&self);
|
||||||
|
}
|
||||||
|
|
||||||
|
trait DynIncompatible4 {
|
||||||
|
fn foo(&self, s: &Self);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn takes_non_object_safe_ref<T>(obj: &dyn DynIncompatible1) {
|
||||||
|
//~^ ERROR E0038
|
||||||
|
}
|
||||||
|
|
||||||
|
fn return_non_object_safe_ref() -> &'static dyn DynIncompatible2 {
|
||||||
|
//~^ ERROR E0038
|
||||||
|
loop {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn takes_non_object_safe_box(obj: Box<dyn DynIncompatible3>) {
|
||||||
|
//~^ ERROR E0038
|
||||||
|
}
|
||||||
|
|
||||||
|
fn return_non_object_safe_rc() -> std::rc::Rc<dyn DynIncompatible4> {
|
||||||
|
//~^ ERROR E0038
|
||||||
|
loop {}
|
||||||
|
}
|
||||||
|
|
||||||
|
trait Trait {}
|
||||||
|
|
||||||
|
impl Trait for dyn DynIncompatible1 {}
|
||||||
|
//~^ ERROR E0038
|
||||||
|
|
||||||
|
fn main() {}
|
|
@ -1,28 +1,28 @@
|
||||||
error[E0038]: the trait `NonObjectSafe1` cannot be made into an object
|
error[E0038]: the trait `DynIncompatible1` cannot be made into an object
|
||||||
--> $DIR/feature-gate-object_safe_for_dispatch.rs:18:39
|
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:18:39
|
||||||
|
|
|
|
||||||
LL | fn takes_non_object_safe_ref<T>(obj: &dyn NonObjectSafe1) {
|
LL | fn takes_non_object_safe_ref<T>(obj: &dyn DynIncompatible1) {
|
||||||
| ^^^^^^^^^^^^^^^^^^ `NonObjectSafe1` cannot be made into an object
|
| ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible1` cannot be made into an object
|
||||||
|
|
|
|
||||||
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
|
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
|
||||||
--> $DIR/feature-gate-object_safe_for_dispatch.rs:4:23
|
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:4:25
|
||||||
|
|
|
|
||||||
LL | trait NonObjectSafe1: Sized {}
|
LL | trait DynIncompatible1: Sized {}
|
||||||
| -------------- ^^^^^ ...because it requires `Self: Sized`
|
| ---------------- ^^^^^ ...because it requires `Self: Sized`
|
||||||
| |
|
| |
|
||||||
| this trait cannot be made into an object...
|
| this trait cannot be made into an object...
|
||||||
|
|
||||||
error[E0038]: the trait `NonObjectSafe2` cannot be made into an object
|
error[E0038]: the trait `DynIncompatible2` cannot be made into an object
|
||||||
--> $DIR/feature-gate-object_safe_for_dispatch.rs:22:45
|
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:22:45
|
||||||
|
|
|
|
||||||
LL | fn return_non_object_safe_ref() -> &'static dyn NonObjectSafe2 {
|
LL | fn return_non_object_safe_ref() -> &'static dyn DynIncompatible2 {
|
||||||
| ^^^^^^^^^^^^^^^^^^ `NonObjectSafe2` cannot be made into an object
|
| ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible2` cannot be made into an object
|
||||||
|
|
|
|
||||||
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
|
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
|
||||||
--> $DIR/feature-gate-object_safe_for_dispatch.rs:7:8
|
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:7:8
|
||||||
|
|
|
|
||||||
LL | trait NonObjectSafe2 {
|
LL | trait DynIncompatible2 {
|
||||||
| -------------- this trait cannot be made into an object...
|
| ---------------- this trait cannot be made into an object...
|
||||||
LL | fn static_fn() {}
|
LL | fn static_fn() {}
|
||||||
| ^^^^^^^^^ ...because associated function `static_fn` has no `self` parameter
|
| ^^^^^^^^^ ...because associated function `static_fn` has no `self` parameter
|
||||||
help: consider turning `static_fn` into a method by giving it a `&self` argument
|
help: consider turning `static_fn` into a method by giving it a `&self` argument
|
||||||
|
@ -34,47 +34,47 @@ help: alternatively, consider constraining `static_fn` so it does not apply to t
|
||||||
LL | fn static_fn() where Self: Sized {}
|
LL | fn static_fn() where Self: Sized {}
|
||||||
| +++++++++++++++++
|
| +++++++++++++++++
|
||||||
|
|
||||||
error[E0038]: the trait `NonObjectSafe3` cannot be made into an object
|
error[E0038]: the trait `DynIncompatible3` cannot be made into an object
|
||||||
--> $DIR/feature-gate-object_safe_for_dispatch.rs:27:39
|
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:27:39
|
||||||
|
|
|
|
||||||
LL | fn takes_non_object_safe_box(obj: Box<dyn NonObjectSafe3>) {
|
LL | fn takes_non_object_safe_box(obj: Box<dyn DynIncompatible3>) {
|
||||||
| ^^^^^^^^^^^^^^^^^^ `NonObjectSafe3` cannot be made into an object
|
| ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible3` cannot be made into an object
|
||||||
|
|
|
|
||||||
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
|
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
|
||||||
--> $DIR/feature-gate-object_safe_for_dispatch.rs:11:8
|
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:11:8
|
||||||
|
|
|
|
||||||
LL | trait NonObjectSafe3 {
|
LL | trait DynIncompatible3 {
|
||||||
| -------------- this trait cannot be made into an object...
|
| ---------------- this trait cannot be made into an object...
|
||||||
LL | fn foo<T>(&self);
|
LL | fn foo<T>(&self);
|
||||||
| ^^^ ...because method `foo` has generic type parameters
|
| ^^^ ...because method `foo` has generic type parameters
|
||||||
= help: consider moving `foo` to another trait
|
= help: consider moving `foo` to another trait
|
||||||
|
|
||||||
error[E0038]: the trait `NonObjectSafe4` cannot be made into an object
|
error[E0038]: the trait `DynIncompatible4` cannot be made into an object
|
||||||
--> $DIR/feature-gate-object_safe_for_dispatch.rs:31:47
|
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:31:47
|
||||||
|
|
|
|
||||||
LL | fn return_non_object_safe_rc() -> std::rc::Rc<dyn NonObjectSafe4> {
|
LL | fn return_non_object_safe_rc() -> std::rc::Rc<dyn DynIncompatible4> {
|
||||||
| ^^^^^^^^^^^^^^^^^^ `NonObjectSafe4` cannot be made into an object
|
| ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible4` cannot be made into an object
|
||||||
|
|
|
|
||||||
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
|
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
|
||||||
--> $DIR/feature-gate-object_safe_for_dispatch.rs:15:22
|
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:15:22
|
||||||
|
|
|
|
||||||
LL | trait NonObjectSafe4 {
|
LL | trait DynIncompatible4 {
|
||||||
| -------------- this trait cannot be made into an object...
|
| ---------------- this trait cannot be made into an object...
|
||||||
LL | fn foo(&self, s: &Self);
|
LL | fn foo(&self, s: &Self);
|
||||||
| ^^^^^ ...because method `foo` references the `Self` type in this parameter
|
| ^^^^^ ...because method `foo` references the `Self` type in this parameter
|
||||||
= help: consider moving `foo` to another trait
|
= help: consider moving `foo` to another trait
|
||||||
|
|
||||||
error[E0038]: the trait `NonObjectSafe1` cannot be made into an object
|
error[E0038]: the trait `DynIncompatible1` cannot be made into an object
|
||||||
--> $DIR/feature-gate-object_safe_for_dispatch.rs:38:16
|
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:38:16
|
||||||
|
|
|
|
||||||
LL | impl Trait for dyn NonObjectSafe1 {}
|
LL | impl Trait for dyn DynIncompatible1 {}
|
||||||
| ^^^^^^^^^^^^^^^^^^ `NonObjectSafe1` cannot be made into an object
|
| ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible1` cannot be made into an object
|
||||||
|
|
|
|
||||||
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
|
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
|
||||||
--> $DIR/feature-gate-object_safe_for_dispatch.rs:4:23
|
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:4:25
|
||||||
|
|
|
|
||||||
LL | trait NonObjectSafe1: Sized {}
|
LL | trait DynIncompatible1: Sized {}
|
||||||
| -------------- ^^^^^ ...because it requires `Self: Sized`
|
| ---------------- ^^^^^ ...because it requires `Self: Sized`
|
||||||
| |
|
| |
|
||||||
| this trait cannot be made into an object...
|
| this trait cannot be made into an object...
|
||||||
|
|
|
@ -1,41 +0,0 @@
|
||||||
// Test that the use of the non object-safe trait objects
|
|
||||||
// are gated by `object_safe_for_dispatch` feature gate.
|
|
||||||
|
|
||||||
trait NonObjectSafe1: Sized {}
|
|
||||||
|
|
||||||
trait NonObjectSafe2 {
|
|
||||||
fn static_fn() {}
|
|
||||||
}
|
|
||||||
|
|
||||||
trait NonObjectSafe3 {
|
|
||||||
fn foo<T>(&self);
|
|
||||||
}
|
|
||||||
|
|
||||||
trait NonObjectSafe4 {
|
|
||||||
fn foo(&self, s: &Self);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn takes_non_object_safe_ref<T>(obj: &dyn NonObjectSafe1) {
|
|
||||||
//~^ ERROR E0038
|
|
||||||
}
|
|
||||||
|
|
||||||
fn return_non_object_safe_ref() -> &'static dyn NonObjectSafe2 {
|
|
||||||
//~^ ERROR E0038
|
|
||||||
loop {}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn takes_non_object_safe_box(obj: Box<dyn NonObjectSafe3>) {
|
|
||||||
//~^ ERROR E0038
|
|
||||||
}
|
|
||||||
|
|
||||||
fn return_non_object_safe_rc() -> std::rc::Rc<dyn NonObjectSafe4> {
|
|
||||||
//~^ ERROR E0038
|
|
||||||
loop {}
|
|
||||||
}
|
|
||||||
|
|
||||||
trait Trait {}
|
|
||||||
|
|
||||||
impl Trait for dyn NonObjectSafe1 {}
|
|
||||||
//~^ ERROR E0038
|
|
||||||
|
|
||||||
fn main() {}
|
|
|
@ -1,8 +1,8 @@
|
||||||
// Test that Copy bounds inherited by trait are checked.
|
// Test that Copy bounds inherited by trait are checked.
|
||||||
//
|
//
|
||||||
//@ revisions: curr object_safe_for_dispatch
|
//@ revisions: curr dyn_compatible_for_dispatch
|
||||||
|
|
||||||
#![cfg_attr(object_safe_for_dispatch, feature(object_safe_for_dispatch))]
|
#![cfg_attr(dyn_compatible_for_dispatch, feature(dyn_compatible_for_dispatch))]
|
||||||
|
|
||||||
|
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
|
@ -19,7 +19,7 @@ fn take_param<T:Foo>(foo: &T) { }
|
||||||
fn a() {
|
fn a() {
|
||||||
let x: Box<_> = Box::new(3);
|
let x: Box<_> = Box::new(3);
|
||||||
take_param(&x); //[curr]~ ERROR E0277
|
take_param(&x); //[curr]~ ERROR E0277
|
||||||
//[object_safe_for_dispatch]~^ ERROR E0277
|
//[dyn_compatible_for_dispatch]~^ ERROR E0277
|
||||||
}
|
}
|
||||||
|
|
||||||
fn b() {
|
fn b() {
|
||||||
|
@ -28,7 +28,7 @@ fn b() {
|
||||||
let z = &x as &dyn Foo;
|
let z = &x as &dyn Foo;
|
||||||
//[curr]~^ ERROR E0038
|
//[curr]~^ ERROR E0038
|
||||||
//[curr]~| ERROR E0038
|
//[curr]~| ERROR E0038
|
||||||
//[object_safe_for_dispatch]~^^^ ERROR E0038
|
//[dyn_compatible_for_dispatch]~^^^ ERROR E0038
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() { }
|
fn main() { }
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
// Check that we correctly prevent users from making trait objects
|
// Check that we correctly prevent users from making trait objects
|
||||||
// from traits with associated consts.
|
// from traits with associated consts.
|
||||||
//
|
//
|
||||||
//@ revisions: curr object_safe_for_dispatch
|
//@ revisions: curr dyn_compatible_for_dispatch
|
||||||
|
|
||||||
#![cfg_attr(object_safe_for_dispatch, feature(object_safe_for_dispatch))]
|
#![cfg_attr(dyn_compatible_for_dispatch, feature(dyn_compatible_for_dispatch))]
|
||||||
|
|
||||||
trait Bar {
|
trait Bar {
|
||||||
const X: usize;
|
const X: usize;
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
// Check that we correctly prevent users from making trait objects
|
// Check that we correctly prevent users from making trait objects
|
||||||
// from traits with generic methods, unless `where Self : Sized` is
|
// from traits with generic methods, unless `where Self : Sized` is
|
||||||
// present.
|
// present.
|
||||||
//@ revisions: curr object_safe_for_dispatch
|
//@ revisions: curr dyn_compatible_for_dispatch
|
||||||
|
|
||||||
#![cfg_attr(object_safe_for_dispatch, feature(object_safe_for_dispatch))]
|
#![cfg_attr(dyn_compatible_for_dispatch, feature(dyn_compatible_for_dispatch))]
|
||||||
|
|
||||||
|
|
||||||
trait Bar {
|
trait Bar {
|
||||||
|
@ -18,14 +18,14 @@ trait Quux {
|
||||||
fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
|
fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
|
||||||
//[curr]~^ ERROR E0038
|
//[curr]~^ ERROR E0038
|
||||||
t
|
t
|
||||||
//[object_safe_for_dispatch]~^ ERROR E0038
|
//[dyn_compatible_for_dispatch]~^ ERROR E0038
|
||||||
//[curr]~^^ ERROR E0038
|
//[curr]~^^ ERROR E0038
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_bar_explicit<T:Bar>(t: &T) -> &dyn Bar {
|
fn make_bar_explicit<T:Bar>(t: &T) -> &dyn Bar {
|
||||||
//[curr]~^ ERROR E0038
|
//[curr]~^ ERROR E0038
|
||||||
t as &dyn Bar
|
t as &dyn Bar
|
||||||
//[object_safe_for_dispatch]~^ ERROR E0038
|
//[dyn_compatible_for_dispatch]~^ ERROR E0038
|
||||||
//[curr]~^^ ERROR E0038
|
//[curr]~^^ ERROR E0038
|
||||||
//[curr]~| ERROR E0038
|
//[curr]~| ERROR E0038
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
// form traits that make use of `Self` in an argument or return
|
// form traits that make use of `Self` in an argument or return
|
||||||
// position, unless `where Self : Sized` is present..
|
// position, unless `where Self : Sized` is present..
|
||||||
//
|
//
|
||||||
//@ revisions: curr object_safe_for_dispatch
|
//@ revisions: curr dyn_compatible_for_dispatch
|
||||||
|
|
||||||
#![cfg_attr(object_safe_for_dispatch, feature(object_safe_for_dispatch))]
|
#![cfg_attr(dyn_compatible_for_dispatch, feature(dyn_compatible_for_dispatch))]
|
||||||
|
|
||||||
|
|
||||||
trait Bar {
|
trait Bar {
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
// Check that we correctly prevent users from making trait objects
|
// Check that we correctly prevent users from making trait objects
|
||||||
// from traits with static methods.
|
// from traits with static methods.
|
||||||
//
|
//
|
||||||
//@ revisions: curr object_safe_for_dispatch
|
//@ revisions: curr dyn_compatible_for_dispatch
|
||||||
|
|
||||||
#![cfg_attr(object_safe_for_dispatch, feature(object_safe_for_dispatch))]
|
#![cfg_attr(dyn_compatible_for_dispatch, feature(dyn_compatible_for_dispatch))]
|
||||||
|
|
||||||
trait Foo {
|
trait Foo {
|
||||||
fn foo() {}
|
fn foo() {}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
// Check that we correctly prevent users from making trait objects
|
// Check that we correctly prevent users from making trait objects
|
||||||
// from traits where `Self : Sized`.
|
// from traits where `Self : Sized`.
|
||||||
//
|
//
|
||||||
//@ revisions: curr object_safe_for_dispatch
|
//@ revisions: curr dyn_compatible_for_dispatch
|
||||||
|
|
||||||
#![cfg_attr(object_safe_for_dispatch, feature(object_safe_for_dispatch))]
|
#![cfg_attr(dyn_compatible_for_dispatch, feature(dyn_compatible_for_dispatch))]
|
||||||
|
|
||||||
trait Bar
|
trait Bar
|
||||||
where Self : Sized
|
where Self : Sized
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
// Check that we correctly prevent users from making trait objects
|
// Check that we correctly prevent users from making trait objects
|
||||||
// from traits where `Self : Sized`.
|
// from traits where `Self : Sized`.
|
||||||
//
|
//
|
||||||
//@ revisions: curr object_safe_for_dispatch
|
//@ revisions: curr dyn_compatible_for_dispatch
|
||||||
|
|
||||||
#![cfg_attr(object_safe_for_dispatch, feature(object_safe_for_dispatch))]
|
#![cfg_attr(dyn_compatible_for_dispatch, feature(dyn_compatible_for_dispatch))]
|
||||||
|
|
||||||
trait Bar: Sized {
|
trait Bar: Sized {
|
||||||
fn bar<T>(&self, t: T);
|
fn bar<T>(&self, t: T);
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
//
|
//
|
||||||
//@ check-pass
|
//@ check-pass
|
||||||
|
|
||||||
#![feature(object_safe_for_dispatch)]
|
#![feature(dyn_compatible_for_dispatch)]
|
||||||
|
|
||||||
trait Trait: Sized {}
|
trait Trait: Sized {}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
//@[next] compile-flags: -Znext-solver
|
//@[next] compile-flags: -Znext-solver
|
||||||
//@ run-pass
|
//@ run-pass
|
||||||
|
|
||||||
#![feature(object_safe_for_dispatch)]
|
#![feature(dyn_compatible_for_dispatch)]
|
||||||
|
|
||||||
trait Bad {
|
trait Bad {
|
||||||
fn stat() -> char {
|
fn stat() -> char {
|
|
@ -3,7 +3,7 @@
|
||||||
//
|
//
|
||||||
//@ check-pass
|
//@ check-pass
|
||||||
|
|
||||||
#![feature(object_safe_for_dispatch)]
|
#![feature(dyn_compatible_for_dispatch)]
|
||||||
|
|
||||||
trait Statics {
|
trait Statics {
|
||||||
fn plain() {}
|
fn plain() {}
|
|
@ -1,6 +1,6 @@
|
||||||
//@ revisions: curr object_safe_for_dispatch
|
//@ revisions: curr dyn_compatible_for_dispatch
|
||||||
|
|
||||||
#![cfg_attr(object_safe_for_dispatch, feature(object_safe_for_dispatch))]
|
#![cfg_attr(dyn_compatible_for_dispatch, feature(dyn_compatible_for_dispatch))]
|
||||||
|
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ fn make_foo() {
|
||||||
let x = Rc::new(5usize) as Rc<dyn Foo>;
|
let x = Rc::new(5usize) as Rc<dyn Foo>;
|
||||||
//[curr]~^ ERROR E0038
|
//[curr]~^ ERROR E0038
|
||||||
//[curr]~| ERROR E0038
|
//[curr]~| ERROR E0038
|
||||||
//[object_safe_for_dispatch]~^^^ ERROR E0038
|
//[dyn_compatible_for_dispatch]~^^^ ERROR E0038
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_bar() {
|
fn make_bar() {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#![feature(object_safe_for_dispatch)]
|
#![feature(dyn_compatible_for_dispatch)]
|
||||||
|
|
||||||
trait Foo {
|
trait Foo {
|
||||||
fn f() {}
|
fn f() {}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Check that we do not allow casts or coercions
|
// Check that we do not allow casts or coercions
|
||||||
// to object unsafe trait objects inside a Box
|
// to object unsafe trait objects inside a Box
|
||||||
|
|
||||||
#![feature(object_safe_for_dispatch)]
|
#![feature(dyn_compatible_for_dispatch)]
|
||||||
|
|
||||||
trait Trait: Sized {}
|
trait Trait: Sized {}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Check that we do not allow casts or coercions
|
// Check that we do not allow casts or coercions
|
||||||
// to object unsafe trait objects by ref
|
// to object unsafe trait objects by ref
|
||||||
|
|
||||||
#![feature(object_safe_for_dispatch)]
|
#![feature(dyn_compatible_for_dispatch)]
|
||||||
|
|
||||||
trait Trait: Sized {}
|
trait Trait: Sized {}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Check that we do not allow coercions to object
|
// Check that we do not allow coercions to object
|
||||||
// unsafe trait objects in match arms
|
// unsafe trait objects in match arms
|
||||||
|
|
||||||
#![feature(object_safe_for_dispatch)]
|
#![feature(dyn_compatible_for_dispatch)]
|
||||||
|
|
||||||
trait Trait: Sized {}
|
trait Trait: Sized {}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue