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

Shared reference to a fixed length vector in a struct can be cast to a *mut directly #14845

Closed
huonw opened this issue Jun 12, 2014 · 4 comments
Milestone

Comments

@huonw
Copy link
Member

huonw commented Jun 12, 2014

struct X { a: [u8, .. 1], b: u8 }

fn main() { 
    let x = X { a: [0], b: 0 };

    let _fixed = &x.a as *mut u8;

    // let _other = &x.b as *mut _;
    // let local_fixed = [0u8]; let _v = &local_fixed as *mut _;
}

compiles without error. Uncommenting the two similar lines gives the errors I was expecting for _fixed:

<anon>:8:19: 8:23 error: mismatched types: expected `*mut <generic #12>` but found `&u8` (values differ in mutability)
<anon>:8      let _other = &x.b as *mut _;
                           ^~~~
<anon>:9:40: 9:52 error: mismatched types: expected `*mut <generic #14>` but found `&[u8, .. 1]` (values differ in mutability)
<anon>:9      let local_fixed = [0u8]; let _v = &local_fixed as *mut _;
                                                ^~~~~~~~~~~~
@huonw huonw added the I-wrong label Jun 12, 2014
@alexcrichton
Copy link
Member

Sounds... interesting? Nominating.

@nikomatsakis
Copy link
Contributor

cc me.

@pnkfelix
Copy link
Member

Assigning P-backcompat-lang, 1.0.

(If someone does some investigation and determines this is trickier to fix than hypothesized, we can revisit.)

@pcwalton
Copy link
Contributor

Fixed in #14856.

bors added a commit to rust-lang-ci/rust that referenced this issue Jun 5, 2023
Add layout info for enum variant and locals

The size of enum variant is what rustdoc shows (rust-lang#86263). I also added layout info for locals since it helps finding size of unnameable types like closures inside other structs or impl traits.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants