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

&[T, ..N] casts to *T instead of *[T, ..N] in structs #14893

Closed
mahkoh opened this issue Jun 14, 2014 · 4 comments · Fixed by #15164
Closed

&[T, ..N] casts to *T instead of *[T, ..N] in structs #14893

mahkoh opened this issue Jun 14, 2014 · 4 comments · Fixed by #15164
Milestone

Comments

@mahkoh
Copy link
Contributor

mahkoh commented Jun 14, 2014

Consider the following code:

struct X {
    y: [u8, ..2],
}

fn main() {
    let x1 = X { y: [0, 0] };

    let p1: *u8 = &x1.y as *_;
    let t1: *[u8, ..2] = &x1.y as *_;
    let h1: *[u8, ..2] = &x1.y as *[u8, ..2];
}

The second cast is an error. The other casts work.

Consider the following code:

fn main() {
    let mut x1 = X { y: [0, 0] };

    let p1: *mut u8 = &mut x1.y as *mut _;
    let t1: *mut [u8, ..2] = &mut x1.y as *mut _;
    let h1: *mut [u8, ..2] = &mut x1.y as *mut [u8, ..2];
}

The first cast is an error. The other casts work.

@huonw
Copy link
Member

huonw commented Jun 14, 2014

There's a comment seeming to imply that &[T, ..n] as *T is explicitly ok, so it's weird that it doesn't work with *mut.

Nominating.

@jdm
Copy link
Contributor

jdm commented Jun 15, 2014

I'm pretty sure this was caused by #14856.

@brson brson added this to the 1.0 milestone Jun 19, 2014
@brson
Copy link
Contributor

brson commented Jun 19, 2014

1.0, P-backcompat-lang

@nikomatsakis
Copy link
Contributor

This is related to how we do coercions. Right now we must do this "eagerly", I'd prefer to leverage a lazy approach like trait matching does. I'm going to try and write this up somewhere, perhaps an RFC.

pcwalton added a commit to pcwalton/rust that referenced this issue Jun 25, 2014
vector-reference-to-unsafe-pointer-to-element cast if the type to be
casted to is not fully specified.

This is a conservative change to fix the user-visible symptoms of the
issue. A more flexible treatment would delay cast checks to after
function typechecking.

This can break code that did:

    let x: *u8 = &([0, 0]) as *_;

Change this code to:

    let x: *u8 = &([0, 0]) as *u8;

Closes rust-lang#14893.

[breaking-change]
bors added a commit that referenced this issue Jun 25, 2014
…chton

vector-reference-to-unsafe-pointer-to-element cast if the type to be
casted to is not fully specified.

This is a conservative change to fix the user-visible symptoms of the
issue. A more flexible treatment would delay cast checks to after
function typechecking.

This can break code that did:

    let x: *u8 = &([0, 0]) as *_;

Change this code to:

    let x: *u8 = &([0, 0]) as *u8;

Closes #14893.

[breaking-change]

r? @alexcrichton
bors added a commit to rust-lang-ci/rust that referenced this issue Jun 5, 2023
Fix `need-mut` false positive in closure capture of match scrutinee

Fix `need-mut` false positive on self.
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