-
Notifications
You must be signed in to change notification settings - Fork 380
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
base: master
Are you sure you want to change the base?
ANN: Add support for E0128 #10313
Conversation
67db6fd
to
b56076f
Compare
b56076f
to
9285e06
Compare
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 | ||
} | ||
} |
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.
Why not path.contextOfType<RsPathType>?.owner?.context as? RsTypeParameter
?
typeParameter.parent.let { | ||
if(it is RsTypeParameterList) { |
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 suppose it would look better without let
:)
|
||
typeParameter.parent.let { | ||
if(it is RsTypeParameterList) { | ||
val parameterIndex = it.typeParameterList.indexOf(typeParameter).takeIf { it != -1 } ?: return |
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.
Let extrect it.typeParameterList
to a variable since it is used twice
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) { |
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.
Seems good! But this code can be further simplified:
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) { |
val resolved = path.reference?.resolve() ?: return | ||
val typeParameter = path.contextOfType<RsPathType>()?.owner?.context as? RsTypeParameter ?: return |
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'd also swapped these lines because the second line will more likely lead to early return
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 |
changelog: Add support for E0128