Open
Description
I tried this code:
use std::hint::black_box;
pub fn demo(data: &[u8]) {
assert!(!data.is_empty());
let mut chunks = data.chunks_exact(1024);
let last_block = if chunks.remainder().is_empty() {
chunks.next_back().expect("this is impossible")
} else {
chunks.remainder()
};
black_box(last_block);
}
When compiled with optimizations enabled and viewing the assembly code, I expected to not see a reference to the string "this is impossible"
. Since there's an assert that the input data is non-empty, then either there will be a remainder, there will be at least one chunk, or both.
Instead, the assembly contains a reference to the expect
string and there's a conditional call to expect_failed
.
Meta
- 1.79.0
- 1.81.0-nightly (2024-07-12 c6727fc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Metadata
Assignees
Labels
Category: An issue highlighting optimization opportunities or PRs implementing suchIssue: Problems and improvements with respect to binary size of generated code.Issue: Problems and improvements with respect to performance of generated code.Relevant to the compiler team, which will review and decide on the PR/issue.