-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
does not offer a suggestion fix
#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
…=jieyouxu rustc_borrowck: Stop suggesting the invalid syntax `&mut raw const` A legitimate suggestion would be to change from &raw const val to &raw mut val But until we have figured out how to make that happen we should at least stop suggesting invalid syntax. I recommend review commit-by-commit. Part of rust-lang#127562
…=jieyouxu rustc_borrowck: Stop suggesting the invalid syntax `&mut raw const` A legitimate suggestion would be to change from &raw const val to &raw mut val But until we have figured out how to make that happen we should at least stop suggesting invalid syntax. I recommend review commit-by-commit. Part of rust-lang#127562
…=jieyouxu rustc_borrowck: Stop suggesting the invalid syntax `&mut raw const` A legitimate suggestion would be to change from &raw const val to &raw mut val But until we have figured out how to make that happen we should at least stop suggesting invalid syntax. I recommend review commit-by-commit. Part of rust-lang#127562
Rollup merge of rust-lang#134244 - Enselic:no-mut-hint-for-raw-ref, r=jieyouxu rustc_borrowck: Stop suggesting the invalid syntax `&mut raw const` A legitimate suggestion would be to change from &raw const val to &raw mut val But until we have figured out how to make that happen we should at least stop suggesting invalid syntax. I recommend review commit-by-commit. Part of rust-lang#127562
With #134244 we now at least don't suggest invalid syntax. But it would be even nicer to suggest changing |
&raw const
instead of &raw mut
produces invalid help message&raw const
instead of &raw mut
does not offer a suggestion fix
@rustbot label: -D-invalid-suggestion |
rustc_borrowck: Suggest changing `&raw const` to `&raw mut` if applicable Closes rust-lang#127562 For reference, here is the diff compared to the original error reported in that issue before rust-lang#134244 stopped suggesting the invalid syntax: ``` diff --git a/tests/ui/borrowck/no-invalid-mut-suggestion-for-raw-pointer-issue-127562.stderr b/tests/ui/borrowck/no-invalid-mut-suggestion-for-raw-pointer-issue-127562.stderr index 0da5d15cf7f..dbe834b6b78 100644 --- a/tests/ui/borrowck/no-invalid-mut-suggestion-for-raw-pointer-issue-127562.stderr +++ b/tests/ui/borrowck/no-invalid-mut-suggestion-for-raw-pointer-issue-127562.stderr `@@` -6,8 +6,8 `@@` LL | unsafe { *ptr = 3; } | help: consider changing this to be a mutable pointer | -LL | let ptr = &mut raw const val; - | +++ +LL | let ptr = &raw mut val; + | ~~~ error: aborting due to 1 previous error ```
Rollup merge of rust-lang#134397 - Enselic:raw-mut, r=compiler-errors rustc_borrowck: Suggest changing `&raw const` to `&raw mut` if applicable Closes rust-lang#127562 For reference, here is the diff compared to the original error reported in that issue before rust-lang#134244 stopped suggesting the invalid syntax: ``` diff --git a/tests/ui/borrowck/no-invalid-mut-suggestion-for-raw-pointer-issue-127562.stderr b/tests/ui/borrowck/no-invalid-mut-suggestion-for-raw-pointer-issue-127562.stderr index 0da5d15cf7f..dbe834b6b78 100644 --- a/tests/ui/borrowck/no-invalid-mut-suggestion-for-raw-pointer-issue-127562.stderr +++ b/tests/ui/borrowck/no-invalid-mut-suggestion-for-raw-pointer-issue-127562.stderr ``@@`` -6,8 +6,8 ``@@`` LL | unsafe { *ptr = 3; } | help: consider changing this to be a mutable pointer | -LL | let ptr = &mut raw const val; - | +++ +LL | let ptr = &raw mut val; + | ~~~ error: aborting due to 1 previous error ```
Code
Current output
Desired output
Rationale and extra context
The current error message does not include a suggestion for how to fix it.
Other cases
No response
Rust Version
Anything else?
EDIT 1: updated since
addr_of!
andaddr_of_mut!
diagnostics are not incorrect anymore due to #127675EDIT 2: updated as #134224 removed the invalid suggestion
The text was updated successfully, but these errors were encountered: