-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Improve unused_unsafe
lint
#93678
Merged
Merged
Improve unused_unsafe
lint
#93678
Changes from all commits
Commits
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 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 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 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 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 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
Oops, something went wrong.
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.
It isn't entirely clear to me that lower HirId necessarily means that its an eariler use (within a block). Could you add a note to the comment here that this relationship holds?
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.
okay
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 kind-of derived that by reading this part in the original implementation
I don’t know how true it is that HirId really corresponds in this way to source order. In any case note that the only usage of this
HirId
here is for providing one instance of where theunsafe_op_in_unsafe_fn
lint level was defined for one of the unsafe operations in the block. (Typically, it’s going to be the same source for all usages anyways.) There is no strict need for it to be the first one, it’s more about being consistent and not providing more information than necessary, so arbitrarily choosing the first one seems like a decent approach. (In particular, changing theunsafe_op_in_unsafe_fn
lint level for any of the operations would already make theunused_unsafe
warning disappear).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 mean, just for sanity, it might make sense to somehow determine (i.e. ask somebody) whether or not
HirId
order does actually correspond (to some degree) to order of appearance in the source code. Or to order of appearance in some other immediate representation, e.g. of the AST, in case that makes a difference.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.
Well, the code above
is sorting the spans of the HIR node, not the HirIds themselves, and those do have direct relationship with the appearance order in the source code.
It might be better if in the code below, where the comparison and logic for this invariant is implemented (that is
*entry = cmp::min(*entry, new_usage);
), the spans were compared as well?Though my understanding of your explanation that it doesn't actually matter that this HirId actually refers to the first
unsafe
use in the source-order, is that correct? I think its okay too and the adjusted comment is clear enough, I guess, what the “first” here really means.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.
Oh… I don’t know how I missed that. Perhaps misreading it once, or even misremembering and then never double-checking.
Maybe the more systematic approach would then be to just take the first one appearing in MIR (i.e. just the first one we come across in the MIR traversal)? 🤔
Indeed it doesn’t really matter, I would appreciate reproducible compilation results (in terms of the set of warnings) though, even in the rare edge cases where this logic actually matters, so some sort of systematic approach is good.
Right, I think I’ll change it to first appearance in MIR then, this is particularly straightforward as it’s just going to be keeping the first operation that’s encountered, making it the cheapest option, too.
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’ve changed it now