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

ANN: Add support for E0128 #10313

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

ANN: Add support for E0128 #10313

wants to merge 1 commit into from

Conversation

konrad-sz
Copy link
Collaborator

changelog: Add support for E0128

Comment on lines 1979 to 1990
private fun findTypeParameterOwner(path: RsPath): RsTypeParameter? {
var parent = path.parent
while (parent is RsTypeArgumentList || parent is RsPathType || parent is RsPath) {
parent = parent.parent
}

return if (parent is RsTypeParameter) {
parent
} else {
null
}
}
Copy link
Member

@vlad20012 vlad20012 May 1, 2023

Choose a reason for hiding this comment

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

Why not path.contextOfType<RsPathType>?.owner?.context as? RsTypeParameter ?

Comment on lines 1607 to 1608
typeParameter.parent.let {
if(it is RsTypeParameterList) {
Copy link
Member

Choose a reason for hiding this comment

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

I suppose it would look better without let :)


typeParameter.parent.let {
if(it is RsTypeParameterList) {
val parameterIndex = it.typeParameterList.indexOf(typeParameter).takeIf { it != -1 } ?: return
Copy link
Member

Choose a reason for hiding this comment

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

Let extrect it.typeParameterList to a variable since it is used twice

Comment on lines +1607 to +1547
val typeParameterList = (typeParameter.parent as? RsTypeParameterList)?.typeParameterList ?: return

val parameterIndex = typeParameterList.indexOf(typeParameter).takeIf { it != -1 } ?: return
val referencedParameterIndex = typeParameterList.indexOf(resolved).takeIf { it != -1 } ?: return
if (parameterIndex < referencedParameterIndex) {
Copy link
Member

Choose a reason for hiding this comment

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

Seems good! But this code can be further simplified:

Suggested change
val typeParameterList = (typeParameter.parent as? RsTypeParameterList)?.typeParameterList ?: return
val parameterIndex = typeParameterList.indexOf(typeParameter).takeIf { it != -1 } ?: return
val referencedParameterIndex = typeParameterList.indexOf(resolved).takeIf { it != -1 } ?: return
if (parameterIndex < referencedParameterIndex) {
if (resolved in typeParameter.rightSiblings) {

Comment on lines 1605 to 1541
val resolved = path.reference?.resolve() ?: return
val typeParameter = path.contextOfType<RsPathType>()?.owner?.context as? RsTypeParameter ?: return
Copy link
Member

Choose a reason for hiding this comment

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

I'd also swapped these lines because the second line will more likely lead to early return

Suggested change
val resolved = path.reference?.resolve() ?: return
val typeParameter = path.contextOfType<RsPathType>()?.owner?.context as? RsTypeParameter ?: return
val typeParameter = path.contextOfType<RsPathType>()?.owner?.context as? RsTypeParameter ?: return
val resolved = path.reference?.resolve() ?: return

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
To test
  
In Progress
Development

Successfully merging this pull request may close these issues.

None yet

2 participants