Skip to content

Commit bdd68ec

Browse files
matthiaskrgrgitbot
authored and
gitbot
committed
Rollup merge of rust-lang#136107 - dingxiangfei2009:coerce-pointee-wellformed, r=compiler-errors
Introduce CoercePointeeWellformed for coherence checks at typeck stage Fix rust-lang#135206 This is the first PR to introduce the "wellformedness" check for `derive(CoercePointee)`. This patch introduces a new error code to cover all the prerequisites of the said macro. The checks that is enforced with this patch is whether the data is indeed `struct` and whether the layout is set to `repr(transparent)`. A following series of patch will arrive later to address the following concern. 1. rust-lang#135217 so that we would only admit one single coercion on one type parameter, and leave the rest for future consideration in tandem of development of other coercion rules. 1. Enforcement of data field requirements. **An open question** is whether there is a good schema to encode the `#[pointee]` as well, so that we could also check if the `#[pointee]` type parameter is indeed `?Sized`. ``@rustbot`` label F-derive_coerce_pointee
2 parents 91e69c8 + e11d62a commit bdd68ec

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

Diff for: core/src/marker.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -1284,8 +1284,22 @@ pub trait FnPtr: Copy + Clone {
12841284
/// }
12851285
/// ```
12861286
#[rustc_builtin_macro(CoercePointee, attributes(pointee))]
1287-
#[allow_internal_unstable(dispatch_from_dyn, coerce_unsized, unsize)]
1287+
#[allow_internal_unstable(dispatch_from_dyn, coerce_unsized, unsize, coerce_pointee_validated)]
12881288
#[unstable(feature = "derive_coerce_pointee", issue = "123430")]
12891289
pub macro CoercePointee($item:item) {
12901290
/* compiler built-in */
12911291
}
1292+
1293+
/// A trait that is implemented for ADTs with `derive(CoercePointee)` so that
1294+
/// the compiler can enforce the derive impls are valid post-expansion, since
1295+
/// the derive has stricter requirements than if the impls were written by hand.
1296+
///
1297+
/// This trait is not intended to be implemented by users or used other than
1298+
/// validation, so it should never be stabilized.
1299+
#[cfg(not(bootstrap))]
1300+
#[lang = "coerce_pointee_validated"]
1301+
#[unstable(feature = "coerce_pointee_validated", issue = "none")]
1302+
#[doc(hidden)]
1303+
pub trait CoercePointeeValidated {
1304+
/* compiler built-in */
1305+
}

0 commit comments

Comments
 (0)