Skip to content

Improve panic messages for Vec methods #70524

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");

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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-api[DEPRECATED; DO NOT USE]

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions