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

Make accesses to fields of packed structs unsafe #44884

Merged
merged 10 commits into from
Nov 27, 2017
Merged

Commits on Nov 26, 2017

  1. fix treatment of local types in "remote coherence" mode

    arielb1 authored and Ariel Ben-Yehuda committed Nov 26, 2017
    Configuration menu
    Copy the full SHA
    c48650e View commit details
    Browse the repository at this point in the history
  2. make accesses to fields of packed structs unsafe

    To handle packed structs with destructors (which you'll think are a rare
    case, but the `#[repr(packed)] struct Packed<T>(T);` pattern is
    ever-popular, which requires handling packed structs with destructors to
    avoid monomorphization-time errors), drops of subfields of packed
    structs should drop a local move of the field instead of the original
    one.
    
    cc rust-lang#27060 - this should deal with that issue after codegen of drop glue
    is updated.
    
    The new errors need to be changed to future-compatibility warnings, but
    I'll rather do a crater run first with them as errors to assess the
    impact.
    arielb1 authored and Ariel Ben-Yehuda committed Nov 26, 2017
    Configuration menu
    Copy the full SHA
    bdb72ed View commit details
    Browse the repository at this point in the history
  3. update Cargo.lock & rustdoc

    This is required because the old version depended on tendril 0.3.1,
    which used `repr(packed)` incorrectly - see
    kuchiki-rs/kuchiki#38
    arielb1 authored and Ariel Ben-Yehuda committed Nov 26, 2017
    Configuration menu
    Copy the full SHA
    3801c05 View commit details
    Browse the repository at this point in the history
  4. fix codegen of drops of fields of packed structs

    arielb1 authored and Ariel Ben-Yehuda committed Nov 26, 2017
    Configuration menu
    Copy the full SHA
    06eb5a6 View commit details
    Browse the repository at this point in the history
  5. make accessing packed fields a future-compat warning

    arielb1 authored and Ariel Ben-Yehuda committed Nov 26, 2017
    Configuration menu
    Copy the full SHA
    1a2d443 View commit details
    Browse the repository at this point in the history
  6. fix #[derive] implementation for repr(packed) structs

    Fix the derive implementation for repr(packed) structs to move the
    fields out instead of calling functions on references to each subfield.
    
    That's it, `#[derive(PartialEq)]` on a packed struct now does:
    ```Rust
    fn eq(&self, other: &Self) {
        let field_0 = self.0;
        let other_field_0 = other.0;
        &field_0 == &other_field_0
    }
    ```
    
    Instead of
    ```Rust
    fn eq(&self, other: &Self) {
        let ref field_0 = self.0;
        let ref other_field_0 = other.0;
        &*field_0 == &*other_field_0
    }
    ```
    
    Taking (unaligned) references to each subfield is undefined, unsound and
    is an error with MIR effectck, so it had to be prevented. This causes
    a borrowck error when a `repr(packed)` struct has a non-Copy field (and
    therefore is a [breaking-change]), but I don't see a sound way to avoid
    that error.
    arielb1 authored and Ariel Ben-Yehuda committed Nov 26, 2017
    Configuration menu
    Copy the full SHA
    dee8a71 View commit details
    Browse the repository at this point in the history
  7. limit packed copy-out to non-generic Copy structs

    arielb1 authored and Ariel Ben-Yehuda committed Nov 26, 2017
    Configuration menu
    Copy the full SHA
    617b413 View commit details
    Browse the repository at this point in the history
  8. fix NetBSD

    arielb1 authored and Ariel Ben-Yehuda committed Nov 26, 2017
    Configuration menu
    Copy the full SHA
    7dbbbf6 View commit details
    Browse the repository at this point in the history
  9. mark rustfmt as broken

    There's a trailing whitespace problem in one of the tests. @nrc said
    he'll go fix it quickly, but until then I'll like to land this PR.
    
    I suspect this happened because one of the dependencies in the
    Cargo.lock I updated had changed the format of the XML they emit, but
    that has to be investigated.
    arielb1 authored and Ariel Ben-Yehuda committed Nov 26, 2017
    Configuration menu
    Copy the full SHA
    47d53e8 View commit details
    Browse the repository at this point in the history
  10. improve error messages

    Ariel Ben-Yehuda committed Nov 26, 2017
    Configuration menu
    Copy the full SHA
    f3b2d7f View commit details
    Browse the repository at this point in the history