-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix false positive for unit_arg lint #6601
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can you check the
TypeFlags
to see if the type was resolved from a variable? Maybeexpr_ty(arg).needs_subst()
.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.
Sorry, for the slow response. I missed your comment regarding the type flags. Checking
needs_subst()
does not seem to have the desired effect. The following example passes linting with my implemention, but runningneeds_subst()
on the type for the argument offoo
returnsfalse
:I'm not familiar with the compiler internals. I looked at the definition of the various type flags, but did not really understand many of them. Do you have any suggestions?
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.
Thinking about it some more, I guess you meant type variables (as in the example in issue #6447). I will test that again later today.
Uh oh!
There was an error while loading. Please reload this page.
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.
Yes I'm hoping we can detect type variables by looking at the
TypeFlags
which is readable throughTypeFoldable
(that's whereneeds_subst
is). Another method in there that might be useful ishas_projections
which means a type with<X as Y>::Z
. I am guessing a bit here as I don't completely understand when those different flags apply.I'm afraid this might be even more complicated - we may have to detect "does the type variable reference a type that is defined outside of the impl block?".
Uh oh!
There was an error while loading. Please reload this page.
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 think we need a different approach here. Using the example from issue #6447 I checked all the type flags and they are all
false
. So we might not get any help there.One problem might be that the original lint looks at the type of the expression passed as the argument and not at the type of the argument from the function definition.
I'll investigate this further, but if you have additional ideas I would be grateful.
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.
After thinking on this again, I think we should simply not lint if
matches(arg.kind, ExprKind::Path)
. This will not lint ifarg
is a local variable.It may be bad style to have a variable with unit as the type, but I think that should be linted upon declaration of the variable (not in this lint).
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.
Ok, I changed my implementation to check for
ExprKind::Path
.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.
Sorry to send you for a loop there.