Skip to content

Conversation

@Veykril
Copy link
Member

@Veykril Veykril commented Nov 9, 2020

Related to #6510

Comment on lines +207 to +223
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;
};
Copy link
Contributor

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?

Copy link
Member Author

@Veykril Veykril Nov 12, 2020

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.

@Veykril Veykril force-pushed the extract-record branch 2 times, most recently from 245b3dc to 3d84c74 Compare November 12, 2020 17:33
@Veykril
Copy link
Member Author

Veykril commented Nov 12, 2020

Mixed it up with how visibility works since children can always see their parents.

bors r+

@bors
Copy link
Contributor

bors bot commented Nov 12, 2020

@bors bors bot merged commit cf73b68 into rust-lang:master Nov 12, 2020
@Veykril Veykril deleted the extract-record branch November 18, 2020 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants