-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Make sure casts from other types to fat pointers are illegal #25038
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
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @brson (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see CONTRIBUTING.md for more information. |
This change catches more invalid casts than I intended.. |
r? @pnkfelix |
@@ -14,6 +14,6 @@ fn main() { | |||
let foo: *mut libc::c_void; | |||
let cb: &mut Fn() = unsafe { | |||
&mut *(foo as *mut Fn()) | |||
//~^ ERROR use of possibly uninitialized variable: `foo` | |||
//~^ ERROR illegal cast |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this test case was actually testing the wrong thing. The associated issue is actually just another instance of casting thin <-> fat pointers, and this test case should not have closed that issue. Note that the error is complaining about something completely unrelated to why the code is actually invalid.
It would be great if you could actually fix up this test case to avoid the other reasons why this case is invalid. A corrected test case looks like
fn main() {
let ptr: *mut () = 0 as *mut _;
let _: &mut Fn() = unsafe {
&mut *(ptr as *mut Fn())
};
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
absolutely. Finding this test case was a bit confusing. Thanks for the test code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Fixes ICEs where non-fat pointers and scalars are cast to fat pointers, Fixes rust-lang#21397 Fixes rust-lang#22955 Fixes rust-lang#23237 Fixes rust-lang#24100
Updated the list of issues this should fix (basically lots of the same kinds of fat pointer casts) |
Nice. Thank you! |
typeck: Make sure casts from other types to fat pointers are illegal
Fixes ICEs where non-fat pointers and scalars are cast to fat pointers,
Fixes #21397
Fixes #22955
Fixes #23237
Fixes #24100