Skip to content
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

Fix debug assertions in Rust 1.78+ #10

Merged
merged 1 commit into from
Jul 26, 2024

Conversation

adierking
Copy link
Contributor

Rust 1.78 introduced unsafe precondition checks when debug assertions are enabled (rust-lang/rust#120594), and they are causing this crate to panic in debug builds:

thread 'tests::drain_filter_complex' panicked at library/core/src/panicking.rs:156:5:
unsafe precondition(s) violated: slice::get_unchecked_mut requires that the index is within the slice

This PR fixes two categories of errors:

  1. get_unchecked_mut() will panic if you try to get a pointer past the last element of the slice. The fix here is to ensure that move_tail_unchecked() always gets called first with a non-zero value.
  2. slice::from_raw_parts() will panic if the slice is unaligned. I'm not sure why as_slices() ever needed to use this, and I don't see any issue with just using an empty slice literal (&[]).

With this I'm able to pass the full test suite on both Rust 1.78 and nightly.

@LiquidityC LiquidityC merged commit 5300503 into LiquidityC:master Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants