-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Unhelpful compiler suggestion when trying to dereference a pointer that is not Copy
#126863
Comments
Note that this works: let inner: String = (*p).clone(); It works because I don't think we should suggest |
I didn't know that was possible, thanks for letting me know. I guess that the best approach would then be to change the help: consider cloning the value if the performance cost is acceptable
|
5 - let inner: String = *p;
5 + let inner: String = (*p).clone();
| |
Correct. Also, we could mention |
The relevant section of diagnostic code is here rust/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs Lines 1299 to 1327 in fc555cd
ty::RawPtr suggestion will not be doing things like stripping parentheses, but suggesting adding them if they don't exist.
|
@rustbot claim |
fix: prefer `(*p).clone` to `p.clone` if the `p` is a raw pointer Fixes rust-lang#126863 I wonder if there is a better way to solve the regression problem of this test case: `tests/ui/borrowck/issue-20801.rs`. It's okay to drop the dereference symbol in this scenario. But it's not correct in rust-lang#126863 ``` help: consider removing the dereference here | 5 - let inner: String = *p; 5 + let inner: String = p; ``` I haven't found out how to tell if clone pointer is allowed, i.e. no type mismatch occurs
Rollup merge of rust-lang#127114 - linyihai:issue-126863, r=Nadrieril fix: prefer `(*p).clone` to `p.clone` if the `p` is a raw pointer Fixes rust-lang#126863 I wonder if there is a better way to solve the regression problem of this test case: `tests/ui/borrowck/issue-20801.rs`. It's okay to drop the dereference symbol in this scenario. But it's not correct in rust-lang#126863 ``` help: consider removing the dereference here | 5 - let inner: String = *p; 5 + let inner: String = p; ``` I haven't found out how to tell if clone pointer is allowed, i.e. no type mismatch occurs
Code
Current output
Desired output
Rationale and extra context
Cloning the pointer doesn't make sense in that situation and would cause a type mismatch error. I'm not sure whether any of the two current suggestions should be kept or removed in this case.
Other cases
No response
Rust Version
Anything else?
No response
The text was updated successfully, but these errors were encountered: