-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Using &raw const
instead of &raw mut
produces invalid help message
#127562
Comments
I think the current suggestion is suggesting the code like this: let ptr = &mut val; |
oh, the suggestion's code comes from here: I think we should not suggest to change the library code here. |
I have playground link that represents the problem above: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=fee632ddd4f51a0390ac6918ef4eff96 However, when I add that code as a regression tests in error[E0594]: cannot assign to `*ptr`, which is behind a `*const` pointer
--> $DIR/dont_suggest_raw_pointer_syntax-issue-127562.rs:9:9
|
LL | *ptr = 3;
| ^^^^^^^^ `ptr` is a `*const` pointer, so the data it refers to cannot be written
|
help: consider specifying this binding's type
|
LL | let ptr: *mut i32 = std::ptr::addr_of!(val);
| ++++++++++ I don't have any ideas about this differences. |
This is because when run the test UI, the span here is remaped so the here we get an error and didn't continue the code branch: it's weird, maybe another issue need to be fixed. |
Given that |
This is completely invalid syntax so just suggesting nothing instead as a first step would already be a good idea. Suggesting anything that involves references is a really bad idea -- code that uses raw pointers should keep using raw pointers throughout with no intermediate references. |
… r=fee1-dead Remove invalid help diagnostics for const pointer Partially addresses rust-lang#127562
… r=petrochenkov Remove invalid help diagnostics for const pointer Partially addresses rust-lang#127562
Rollup merge of rust-lang#127675 - chenyukang:yukang-fix-127562-addr, r=petrochenkov Remove invalid help diagnostics for const pointer Partially addresses rust-lang#127562
ptr::addr_of!
instead of ptr::addr_of_mut!
produces invalid help message&raw const
instead of &raw mut
produces invalid help message
Code
Current output
Desired output
Rationale and extra context
The current help message is wrong:
gives
whereas the correct syntax would be
&raw mut val
.Other cases
No response
Rust Version
Anything else?
EDIT: updated since
addr_of!
andaddr_of_mut!
diagnostics are not incorrect anymore due to #127675The text was updated successfully, but these errors were encountered: