Skip to content

Listing 19-6: use ptr.add instead of ptr.offset #2042

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

Closed
SuperSamus opened this issue Jul 27, 2019 · 0 comments · Fixed by #2201
Closed

Listing 19-6: use ptr.add instead of ptr.offset #2042

SuperSamus opened this issue Jul 27, 2019 · 0 comments · Fixed by #2201
Labels

Comments

@SuperSamus
Copy link
Contributor

In Chapter 19.1 (Unsafe Rust), the line from listing 19-6 slice::from_raw_parts_mut(ptr.offset(mid as isize), len - mid)) should use ptr.add instead (beacause it asks for an usize, avoiding the conversion), just like the official implementation does.
Also, Clippy complains:

use of offset with a usize casted to an isize

note: #[warn(clippy::ptr_offset_with_cast)] on by default
help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_offset_with_cast
help: try: ptr.add(mid)clippy(clippy::ptr_offset_with_cast)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants