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.
Replace most uses of
pointer::offset
withadd
andsub
#100822New 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
Replace most uses of
pointer::offset
withadd
andsub
#100822Changes from all commits
e4720e1
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Not this PR, but consider following along to use
usize::from(*end_l)
here -- I went off to check that*end_l
wasn't signed, and if it was afrom
then it'd be obvious that it's unsigned (since thefrom
wouldn't compile for signed -> unsigned).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.
Not this PR's problem, but it's interesting that this reads a
u64
and thenoffset
s it without any checking.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.
sneaky:
offset
was{integer}
previously inferred toisize
, now tousize
.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.
Looks like
byte
was previouslyi32
(because unconstrained, as it was alwaysas
ed) and is nowusize
? So it can probably besrc[byte]
too.(It would be nice to have a warning for T-to-T
as
casts...)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 was thinking about linting T2T casts too, while doing these refactorings. It should probably be easy to add 🤔
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.
Hm, there is a clippy lint for that (docs, source), should I open an uplifting issue/pr?
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 guess the problem is if you want to keep it -- say it's there to be resilient to
c_int
widths or something, where it'sc_int as i64
, which might be a nop sometimes.For a clippy lint saying "hey, just allow it" is fine, but for rustc lints we generally want to be able to give a "or write ______ instead to make it obvious why you want to keep it like this" suggestion.
Nothing jumped to mind to me for how to do that, but hopefully you'll come up with something clever to lint only in the valuable places.
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.
Not linting
i64 as c_int
is probably possible by recording in hir (?) thatc_int
is a type alias, but not lintingc_int as i64
I think it impossible, there is simply no way to differentiate a variable of typec_int
with a variable of typei64
I believe (ifc_int
is an alias toi64
)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.
As a second thought, would this still be useful as a allow-by-default lint? 🤔