-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsA-sliceArea: `[T]`Area: `[T]`E-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.
Description
Location
Somewhere near slices and ranges, maybe in sliceable types as well.
Summary
Currently there doesn't seem to be any documentation on slices (both std::slice
and the primitive type) or ranges for their panic behavior when range indices are out of range (unless I missed it somewhere).
This notably means I cannot find any documentation for the following behavior (playground):
fn main() {
let vec = vec![1, 2, 3];
println!("{:?}", &vec[2..]); // [3]
println!("{:?}", &vec[3..]); // []
println!("{:?}", &vec[4..]); // panic!
}
This behavior is rather non-obvious (although convenient for my current use case), I had expected the second slice to panic or the third one to also return []
for consistency. Either way, changing that would be a breaking change, so I would at least expect it to be documented somewhere.
a1kemist and lolbinarycat
Metadata
Metadata
Assignees
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsA-sliceArea: `[T]`Area: `[T]`E-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.