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

*mut T should coerce to *const T #16926

Closed
petrochenkov opened this issue Sep 1, 2014 · 1 comment
Closed

*mut T should coerce to *const T #16926

petrochenkov opened this issue Sep 1, 2014 · 1 comment

Comments

@petrochenkov
Copy link
Contributor

Currently only the last line in the example below doesn't compile.

fn fref(_: &u8) {}
fn fptr(_: *const u8) {}

let mut v = 0u8;
fref(&v);
fref(&mut v);
fptr(&v as *const u8);
fptr(&mut v as *mut u8); // error: mismatched types: expected `*const u8`, found `*mut u8` (values differ in mutability)

The conversion *mut T -> *const T is safe and consistent both with Rust references (&mut T coerces to &T) and C pointers (T* is implicitly convertible to const T*). I don't see the reasons why it is not allowed.

@petrochenkov
Copy link
Contributor Author

Resolved by #19766

bors added a commit to rust-lang-ci/rust that referenced this issue Mar 31, 2024
fix: Rename `func_like` to `FuncLike`

Should fix rust-lang#16926. Please check the issue for more information.
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

No branches or pull requests

1 participant