stabilize relaxed_struct_unsize

This commit is contained in:
lcnr 2021-10-30 15:56:02 +02:00
parent 2b643e9871
commit b40aa64e48
6 changed files with 16 additions and 70 deletions

View file

@ -297,6 +297,8 @@ declare_features! (
(accepted, macro_attributes_in_derive_output, "1.57.0", Some(81119), None), (accepted, macro_attributes_in_derive_output, "1.57.0", Some(81119), None),
/// Allows panicking during const eval (producing compile-time errors). /// Allows panicking during const eval (producing compile-time errors).
(accepted, const_panic, "1.57.0", Some(51999), None), (accepted, const_panic, "1.57.0", Some(51999), None),
/// Lessens the requirements for structs to implement `Unsize`.
(accepted, relaxed_struct_unsize, "1.58.0", Some(81793), None),
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// feature-group-end: accepted features // feature-group-end: accepted features

View file

@ -589,9 +589,6 @@ declare_features! (
/// Allows `extern "C-cmse-nonsecure-call" fn()`. /// Allows `extern "C-cmse-nonsecure-call" fn()`.
(active, abi_c_cmse_nonsecure_call, "1.51.0", Some(81391), None), (active, abi_c_cmse_nonsecure_call, "1.51.0", Some(81391), None),
/// Lessens the requirements for structs to implement `Unsize`.
(active, relaxed_struct_unsize, "1.51.0", Some(81793), None),
/// Allows associated types in inherent impls. /// Allows associated types in inherent impls.
(incomplete, inherent_associated_types, "1.52.0", Some(8995), None), (incomplete, inherent_associated_types, "1.52.0", Some(8995), None),

View file

@ -948,7 +948,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let tail_field_ty = tcx.type_of(tail_field.did); let tail_field_ty = tcx.type_of(tail_field.did);
let mut unsizing_params = GrowableBitSet::new_empty(); let mut unsizing_params = GrowableBitSet::new_empty();
if tcx.features().relaxed_struct_unsize {
for arg in tail_field_ty.walk(tcx) { for arg in tail_field_ty.walk(tcx) {
if let Some(i) = maybe_unsizing_param_idx(arg) { if let Some(i) = maybe_unsizing_param_idx(arg) {
unsizing_params.insert(i); unsizing_params.insert(i);
@ -968,33 +967,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
if unsizing_params.is_empty() { if unsizing_params.is_empty() {
return Err(Unimplemented); return Err(Unimplemented);
} }
} else {
let mut found = false;
for arg in tail_field_ty.walk(tcx) {
if let Some(i) = maybe_unsizing_param_idx(arg) {
unsizing_params.insert(i);
found = true;
}
}
if !found {
return Err(Unimplemented);
}
// Ensure none of the other fields mention the parameters used
// in unsizing.
// FIXME(eddyb) cache this (including computing `unsizing_params`)
// by putting it in a query; it would only need the `DefId` as it
// looks at declared field types, not anything substituted.
for field in prefix_fields {
for arg in tcx.type_of(field.did).walk(tcx) {
if let Some(i) = maybe_unsizing_param_idx(arg) {
if unsizing_params.contains(i) {
return Err(Unimplemented);
}
}
}
}
}
// Extract `TailField<T>` and `TailField<U>` from `Struct<T>` and `Struct<U>`. // Extract `TailField<T>` and `TailField<U>` from `Struct<T>` and `Struct<U>`.
let source_tail = tail_field_ty.subst(tcx, substs_a); let source_tail = tail_field_ty.subst(tcx, substs_a);

View file

@ -1,10 +0,0 @@
// Test that we allow unsizing even if there is an unchanged param in the
// field getting unsized.
struct A<T, U: ?Sized + 'static>(T, B<T, U>);
struct B<T, U: ?Sized>(T, U);
fn main() {
let x: A<[u32; 1], [u32; 1]> = A([0; 1], B([0; 1], [0; 1]));
let y: &A<[u32; 1], [u32]> = &x; //~ ERROR mismatched types
assert_eq!(y.1.1.len(), 1);
}

View file

@ -1,14 +0,0 @@
error[E0308]: mismatched types
--> $DIR/feature-gate-relaxed_struct_unsize.rs:8:34
|
LL | let y: &A<[u32; 1], [u32]> = &x;
| ------------------- ^^ expected slice `[u32]`, found array `[u32; 1]`
| |
| expected due to this
|
= note: expected reference `&A<[u32; 1], [u32]>`
found reference `&A<[u32; 1], [u32; 1]>`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.

View file

@ -1,4 +1,3 @@
#![feature(relaxed_struct_unsize)]
// run-pass // run-pass
// Test that we allow unsizing even if there is an unchanged param in the // Test that we allow unsizing even if there is an unchanged param in the
// field getting unsized. // field getting unsized.