Closed
Description
This is an interesting codegen bug (Note that this reproduces in a special case setting and in many regular contexts, this problem does not exist).
Expected behavior:
This code should just be a pointer comparison (ptr == end
leads to None
being returned)
use std::slice::Iter;
pub fn is_empty_1(xs: Iter<f32>) -> bool {
{xs}.next().is_none()
}
Actual behavior:
It compiles to the equivalent of ptr == end || ptr.is_null()
.
Playground link. Use release mode.
version: rustc 1.15.0-nightly (0bd2ce6 2016-11-19)
Additional notes:
This version has the expected codegen, without the null check.
pub fn is_empty_2(xs: Iter<f32>) -> bool {
xs.map(|&x| x).next().is_none()
}