Skip to content
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

Properly handle shorthands in destructure patterns when renaming #6552

Merged
merged 4 commits into from
Nov 15, 2020

Conversation

Veykril
Copy link
Member

@Veykril Veykril commented Nov 14, 2020

Fixes #6548 and #6551.

}

#[test]
fn test_struct_field_destructure_into_shorthand() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, should we also check for destructuring in arguments too fn foo()?

Nit: we can also put all rename tests into one snippet to slightly reduce the test count, diff size, etc.

Copy link
Member Author

@Veykril Veykril Nov 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the nit you mean as in merging most of the before_fixtures of the difference cases to reuse them behind a static? Ah nevermind you mean merging the test functions and test multiple things per test.

And yes, testing for parameter destructuring also seems like a good idea

Copy link
Member Author

@Veykril Veykril Nov 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm I don't think we can put the tests together though, as they require slightly different fixtures and/or different <|> cursor positions. Edit: Actually two can be put together as their expected fixture is the same.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, never mind then, I din't think it's worth supporting the multiple caret tests for this case.

crates/ide/src/references/rename.rs Show resolved Hide resolved
@@ -126,6 +126,7 @@ fn source_edit_from_reference(
TextRange::new(reference.file_range.range.end(), reference.file_range.range.end())
}
ReferenceKind::RecordFieldExprOrPat => {
mark::hit!(test_rename_field_expr_pat);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@SomeoneToIgnore
Copy link
Contributor

bors r+

@bors
Copy link
Contributor

bors bot commented Nov 15, 2020

@@ -22,6 +22,18 @@ impl ast::Expr {
_ => false,
}
}

pub fn name_ref(&self) -> Option<ast::NameRef> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same thing here -- this methong is non-primitives -- it's a convenience function which reaches deep into the node. We should have such functions, but not as inherent methods on AST nodes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same -- see my recent comment on another PR :-)

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.

Renaming a struct initializer to match the field name should use shorthand record syntax
3 participants