Skip to content

InclusiveRange's size_hint can give 1 when empty, despite implementing TrustedLen #42135

Closed
@scottmcm

Description

@scottmcm

Repro:

#![feature(inclusive_range_syntax)]
#![feature(trusted_len)]

use std::iter::TrustedLen;

fn check_size_correctness<T:TrustedLen+ExactSizeIterator>(x: T) {
    let len = x.len();
    assert_eq!(x.count(), len);
}

fn main() {
    check_size_correctness(100...0u8);
}

#42134 will fix this, but I wanted to record it because I think TrustedLen being an unsafe trait means this could be leading to unsoundness.

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions