-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Arrays as struct members causes panic #15804
Comments
The following simple example is sufficient to reproduce the problem: struct T {
arr: [u8; 16],
} And this one too: type Arr = [char; 16];
struct T {
arr: Arr,
} rust-analyzer version: 0.3.1705-standalone (1087295 2023-10-22) |
I can't reproduce this. Is it reproducible in an empty project on vscode? |
I can reproduce it in an empty project. There is a |
I believe I hit the same issue: #15968 |
Same here in Emacs + rust-analyzer. |
I can't reproduce this on latest |
Hey, I have locally identified and resolved the bug. The issue stems from an error transformation in the code action generate_delegate_trait with PathTransform, similar to #14534, but for some unknown reasons, it cannot be reliably reproduced. Upon investigating generate_delegate_trait, I found numerous implementation issues with this code action, such as lack of support for generic structs and incorrect handling of the Self type. To address these issues, I have rewritten the entire code action and am currently addressing the final few issues. I may submit a pull request within the next day or two. |
Resolve panic in `generate_delegate_methods` Fixes #16276 This PR addresses two issues: 1. When using `PathTransform`, it searches for the node corresponding to the `path` in the `source_scope` during `make::fn_`. Therefore, we need to perform the transform before `make::fn_` (similar to the problem in issue #15804). Otherwise, even though the tokens are the same, their offsets (i.e., `span`) differ, resulting in the error "Can't find CONST_ARG@xxx." 2. As mentioned in the first point, `PathTransform` searches for the node corresponding to the `path` in the `source_scope`. Thus, when transforming paths, we should update nodes from right to left (i.e., use **reverse of preorder** (right -> left -> root) instead of **postorder** (left -> right -> root)). Reasons are as follows: In the red-green tree (rowan), we do not store absolute ranges but instead store the length of each node and dynamically calculate offsets (spans). Therefore, when modifying the left-side node (such as nodes are inserted or deleted), it causes all right-side nodes' spans to change. This, in turn, leads to PathTransform being unable to find nodes with the same paths (due to different spans), resulting in errors.
Example file
ra version: 2023-10-23
rustc: rustc 1.73.0 (cc66ad468 2023-10-03)
Pop_OS, Emacs
Hovering a cursor anywhere over the array literals breaks the LSP.:
The text was updated successfully, but these errors were encountered: