-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix extract_struct_from_enum_variant not updating record references #6514
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
Conversation
| let (segment, expr) = if let Some(path_expr) = | ||
| find_node_at_offset::<ast::PathExpr>(source_file.syntax(), offset) | ||
| { | ||
| // tuple variant | ||
| (path_expr.path()?.segment()?, path_expr.syntax().parent()?.clone()) | ||
| } else if let Some(record_expr) = | ||
| find_node_at_offset::<ast::RecordExpr>(source_file.syntax(), offset) | ||
| { | ||
| // record variant | ||
| (record_expr.path()?.segment()?, record_expr.syntax().clone()) | ||
| } else { | ||
| return None; | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this'll work correctly for ast::RecordExpr nested into an ast::CallExpr for a different tuple struct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean something like this?
enum A { <|>One { a: u32, b: u32 } }
struct B(A);
fn foo() {
let _ = B(A::One { a: 1, b: 2 });
}This seems to work properly as I get
struct One{ pub a: u32, pub b: u32 }
enum A { One(One) }
struct B(A);
fn foo() {
let _ = B(A::One(One { a: 1, b: 2 }));
}which seems correct to me. Though I would've expected this to fail as well now that you say it.
Will definitely add this as a test if anything.
Edit: Ah the ast::PathExpr in the ast::CallExpr is a neighbor of the arg_list node containing the record which is why this still works, since find_node_at_offset considers ancestors only so this shouldn't be a problem.
crates/assists/src/handlers/extract_struct_from_enum_variant.rs
Outdated
Show resolved
Hide resolved
crates/assists/src/handlers/extract_struct_from_enum_variant.rs
Outdated
Show resolved
Hide resolved
245b3dc to
3d84c74
Compare
crates/assists/src/handlers/extract_struct_from_enum_variant.rs
Outdated
Show resolved
Hide resolved
3d84c74 to
ccdcd52
Compare
|
Mixed it up with how visibility works since children can always see their parents. bors r+ |
Related to #6510