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

Implement unsized unions #47650

Closed
wants to merge 13 commits into from
Closed

Commits on Mar 2, 2018

  1. allow the last field of a union to be ?Sized

    - theoretically any single field of the union could be ?Sized, but it's easier to implement this way
    - still have to allow/implement the unsize cast for unions
    mikeyhew committed Mar 2, 2018
    Configuration menu
    Copy the full SHA
    4d74572 View commit details
    Browse the repository at this point in the history
  2. Get unsized unions working

    this supports unsized unions, where the last field may be unsized.
    Theoretically, any number of fields of a union could be unsized, as
    long as the unsized type is the same for all of them, but this is the
    simplest way to get ManuallyDrop<T: ?Sized> working.
    mikeyhew committed Mar 2, 2018
    Configuration menu
    Copy the full SHA
    74ce9fb View commit details
    Browse the repository at this point in the history
  3. update union-unsized compile-fail test

    this now only fails if the unsized field is not the last field
    mikeyhew committed Mar 2, 2018
    Configuration menu
    Copy the full SHA
    06cc03c View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    43fa327 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    7645490 View commit details
    Browse the repository at this point in the history

Commits on Mar 10, 2018

  1. Configuration menu
    Copy the full SHA
    6d474ae View commit details
    Browse the repository at this point in the history
  2. Update union-sized-field ui test

    Adds an extra field to the unsized union, so that there will be an
    error about the union needing to only have a single field
    mikeyhew committed Mar 10, 2018
    Configuration menu
    Copy the full SHA
    cedec2b View commit details
    Browse the repository at this point in the history

Commits on Mar 13, 2018

  1. Configuration menu
    Copy the full SHA
    6cb99d1 View commit details
    Browse the repository at this point in the history
  2. refactor FnCtxt::check_type_defn to handle unsized unions

    - the old implementation had an `all_sized: bool` parameter which was
    true iff the type was a struct, and allowed the last field to be
    unsized in that case.
    - Because of unsized unions, things are more complicated, and will
    become more complicated in the future if we get multiple unsized union
    fields or enum variants
    - this implementation gets rid of the `all_sized` parameter, and just
    checks directly in the function whether the type is a struct, enum or
    union, handling each case independently
    mikeyhew committed Mar 13, 2018
    Configuration menu
    Copy the full SHA
    e2bb126 View commit details
    Browse the repository at this point in the history
  3. Fix underflow bug

    The expression `slice.len()-1` underflows when the slice is empty,
    which caused an out-of-bounds array access. At least Rust panics in
    that case!
    
    I wish there was a more idiomatic way to get a sub-slice with
    everything but the last element. This way is evidently pretty bug-prone
    mikeyhew committed Mar 13, 2018
    Configuration menu
    Copy the full SHA
    55f0967 View commit details
    Browse the repository at this point in the history
  4. upgrade unreachable!() to a span_bug!()

    This should output a better error message if check_type_defn ever gets
    called with something that’s not a struct, enum or union
    mikeyhew committed Mar 13, 2018
    Configuration menu
    Copy the full SHA
    42b84f9 View commit details
    Browse the repository at this point in the history
  5. Update union-specific tests

    - update the comments on the `U6` test case, to make it more clear what
    to do when non-`Copy` unions are stabilized
    - add a crucial `~` that caused a test to pass that wasn’t supposed to
    - update stderr of some tests to reflect changes in the actual tests
    and compiler error messages
    mikeyhew committed Mar 13, 2018
    Configuration menu
    Copy the full SHA
    de2ff7f View commit details
    Browse the repository at this point in the history

Commits on Mar 18, 2018

  1. eemit a feature-gate error for unsized unions

    - unsized unions require the untagged_unions feature
    - prececedence is given to other error messages for the untagged_unions feature gate. For example, if there is already going to be an error about non-`Copy` unions being unstable, we do not also emit an error about unsized unions being unstable
    mikeyhew committed Mar 18, 2018
    Configuration menu
    Copy the full SHA
    d27141c View commit details
    Browse the repository at this point in the history