Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracking Issue for relaxed struct unsizing rules #81793

Closed
2 tasks
lcnr opened this issue Feb 5, 2021 · 6 comments · Fixed by #90417
Closed
2 tasks

Tracking Issue for relaxed struct unsizing rules #81793

lcnr opened this issue Feb 5, 2021 · 6 comments · Fixed by #90417
Labels
A-DSTs Area: Dynamically-sized types (DSTs) C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. F-relaxed_struct_unsize `#![feature(relaxed_struct_unsize)]` finished-final-comment-period The final comment period is finished for this PR / Issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@lcnr
Copy link
Contributor

lcnr commented Feb 5, 2021

The feature gate for the issue is #![feature(relaxed_struct_unsize)].

This features changes the when a struct implements Unsize which
is required for unsize coercion.

A generic struct previously implemented Unsize if and only if:

  • the tail field depends on at least one type or const parameter
  • all type and const parameters used in the last field must only be used in the last field
  • the target struct can be created from the source by replacing only the parameters found in the last struct field
  • the tail field implements Unsize from source to target

With this feature gate the requirements are changed to:

  • the tail field depends on at least one type or const parameter not used in any other field
  • the target struct can be created from the source by replacing only the parameters only found in the last struct field
  • the tail field implements Unsize from source to target

About tracking issues

Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.

Steps

Implementation history

This feature has been implemented in #80726

@lcnr lcnr added T-lang Relevant to the language team, which will review and decide on the PR/issue. C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC labels Feb 5, 2021
@jonas-schievink jonas-schievink added the A-DSTs Area: Dynamically-sized types (DSTs) label Feb 5, 2021
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Feb 27, 2021
…sue, r=camelid

update tracking issue for `relaxed_struct_unsize`

forgot to do this before rust-lang#80726 got merged. The tracking issue is rust-lang#81793
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Feb 27, 2021
…sue, r=camelid

update tracking issue for `relaxed_struct_unsize`

forgot to do this before rust-lang#80726 got merged. The tracking issue is rust-lang#81793
@lcnr lcnr added the F-relaxed_struct_unsize `#![feature(relaxed_struct_unsize)]` label Aug 26, 2021
@lcnr
Copy link
Contributor Author

lcnr commented Aug 26, 2021

Nominating this feature for stabilization. I don't see much use in keeping this unstable and consider this change to be a simplification and improvement of our current rules.

The two relevant tests here are https://github.com/rust-lang/rust/blob/master/src/test/ui/unsized/unchanged-param.rs and #88357.

@lcnr
Copy link
Contributor Author

lcnr commented Oct 5, 2021

Stabilization report

This is the stabilization report for #![feature(relaxed_struct_unsize)], which slightly improves the rules for struct unsizing.

Summary and Explanation

A generic struct previously implemented Unsize if and only if:

  • the tail field depends on at least one type or const parameter
  • all type and const parameters used in the last field must only be used in the last field
  • the target struct can be created from the source by replacing only the parameters found in the last struct field
  • the tail field implements Unsize from source to target

With this feature gate the requirements are changed to:

  • the tail field depends on at least one type or const parameter not used in any other field
  • the target struct can be created from the source by replacing only the parameters only found in the last struct field
  • the tail field implements Unsize from source to target

Example

#![feature(relaxed_struct_unsize)]
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]));
    // This previously did not work as the last field of `A` also mentions `T`,
    // as only `U` changes this is now allowed thanks to this feature.
    let _y: &A<[u32; 1], [u32]> = &x;
}

Motivation

This feature changes the existing rules to be more intuitive and more permissive. We also assume it to not cause any future compatibility issues as there is no known sensible improvement to struct unsizing which is prevented by this change.

An example where the current rules are inadequate which is fixed with this feature: playground

// you can unsize `U` without this feature, but
struct A<T, U: ?Sized + 'static>(T, T, U);

// after extracting the last 2 fields, you cannot unsize `U` anymore.
struct A<T, U: ?Sized + 'static>(T, B<T, U>);
struct B<T, U: ?Sized + 'static>(T, U);

Unsizing is a fairly unknown area of Rust where mistakes cause very unhelpful errors. This makes improvements to its rules especially worthwhile.

@pnkfelix
Copy link
Member

@rfcbot fcp merge

@rfcbot
Copy link

rfcbot commented Oct 19, 2021

Team member @pnkfelix has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Oct 19, 2021
@rfcbot rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Oct 19, 2021
@rfcbot
Copy link

rfcbot commented Oct 19, 2021

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Oct 29, 2021
@rfcbot
Copy link

rfcbot commented Oct 29, 2021

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

@rfcbot rfcbot added the to-announce Announce this issue on triage meeting label Oct 29, 2021
@bors bors closed this as completed in bc487f7 Nov 3, 2021
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Nov 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-DSTs Area: Dynamically-sized types (DSTs) C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. F-relaxed_struct_unsize `#![feature(relaxed_struct_unsize)]` finished-final-comment-period The final comment period is finished for this PR / Issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants