-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Allow as
in match statements
#1009
Comments
Perhaps type ascription is a better choice here? That RFC actually says
So there may already be existing discussion about this. |
@kballard Type ascription asserts that the expression has the provided type, but it doesn't apply in this case: That said, I think it is better to allow int ↔︎ raw pointer casting in CTFE to allow: const INVALID_MMAP: *mut c_void = (-1usize) as *mut c_void;
match mmap(...) {
INVALID_MMAP => ...
p => ...
} |
Oh you're right, for some reason I was thinking that integral literals could be used where pointers are expected, but no, you need the explicit
Huh, that seems a bit surprising that it doesn't work. Is there an issue that tracks this? If not, one should be filed. |
I think that with https://rust-lang.github.io/rfcs/2920-inline-const.html this will be doable as let ptr = match mmap(...) {
const { -1 as *mut c_void } => panic!(),
p => p,
} So I'll close this and people can follow rust-lang/rust#76001. |
As in
This is very useful for FFI and
#![no_std]
, I don't think it takes anything away, and it shouldn't be too difficult to add.Possibilities right now include
or
Another possible idea, one that I doubt many people would like, is to allow
*const
and*mut
pointers to be integrals. Then you could just do the C thing ofThe text was updated successfully, but these errors were encountered: