Skip to content

Improve panic messages for Vec methods #70524

Closed
@IgorPerikov

Description

@IgorPerikov

I've spotted, that remove() panic message could've provided details on what values led to this panic, instead of mentioning condition only. Generally speaking this and some other assert!s in Vec could've been more detailed. If it's okay to step in, I'd like to offer my help.

In case of remove I'd suggest calling this instead

assert!(index < len, "removal index {} should be less than length {}", index, len); 

I find this more informative than assertion failed: index < len

Candidates for improval:

aforementioned remove:

assert!(index < len);

insert:

assert!(index <= len);

drain:

rust/src/liballoc/vec.rs

Lines 1292 to 1293 in 5f13820

assert!(start <= end);
assert!(end <= len);

split_off:

assert!(at <= self.len(), "`at` out of bounds");

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-collectionsArea: `std::collections`C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-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