Skip to content

Extra null check in slice iterator's .next().is_none() #37945

Closed
@bluss

Description

@bluss

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()
}

Metadata

Metadata

Assignees

Labels

A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.I-slowIssue: Problems and improvements with respect to performance of generated code.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions