You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
dlon opened this issue
Feb 2, 2022
· 3 comments
· Fixed by #93675
Assignees
Labels
A-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`C-bugCategory: This is a bug.O-windowsOperating system: WindowsT-libsRelevant to the library team, which will review and decide on the PR/issue.
According to the documentation for strip_prefix, it should either succeed or return Err(StripPrefixError). Instead, it panics due to an out-of-range index:
thread 'main' panicked at 'range start index 2 out of range for slice of length 0', library\std\src\path.rs:716:24
thread 'main' panicked at 'range start index 2 out of range for slice of length 0', library\std\src\path.rs:716:24
stack backtrace:
0: std::panicking::begin_panic_handler
at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b\/library\std\src\panicking.rs:498
1: core::panicking::panic_fmt
at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b\/library\core\src\panicking.rs:107
2: core::slice::index::slice_start_index_len_fail
at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b\/library\core\src\slice\index.rs:34
3: core::slice::index::impl$5::index
at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b\library\core\src\slice\index.rs:324
4: core::slice::index::impl$0::index
at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b\library\core\src\slice\index.rs:15
5: std::path::Components::include_cur_dir
at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b\/library\std\src\path.rs:722
6: std::path::Components::len_before_body
at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b\/library\std\src\path.rs:657
7: std::path::Components::trim_right
at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b\/library\std\src\path.rs:774
8: std::path::Components::as_path
at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b\/library\std\src\path.rs:693
9: std::path::impl$62::_strip_prefix::closure$0
at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b\/library\std\src\path.rs:2242
10: core::option::Option::map
at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b\library\core\src\option.rs:846
11: std::path::Path::_strip_prefix
at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b\/library\std\src\path.rs:2241
12: std::path::Path::strip_prefix<str>
at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b\library\std\src\path.rs:2237
13: test_path_panic::main
at .\src\main.rs:2
14: core::ops::function::FnOnce::call_once<void (*)(),tuple$<> >
at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b\library\core\src\ops\function.rs:227
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
error: process didn't exit successfully: `target\debug\test-path-panic.exe` (exit code: 101)
The text was updated successfully, but these errors were encountered:
I can confirm this. The problem originates in Components. A minimal example:
fnmain(){let path = std::path::Path::new("C:");letmut iter = path.components();
iter.next();
iter.as_path();// panics at 'range start index 2 out of range for slice of length 0'}
A-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`C-bugCategory: This is a bug.O-windowsOperating system: WindowsT-libsRelevant to the library team, which will review and decide on the PR/issue.
This code panics on Windows:
According to the documentation for
strip_prefix
, it should either succeed or returnErr(StripPrefixError)
. Instead, it panics due to an out-of-range index:Meta
rustc --version --verbose
:The bug is also present in nightly.
Backtrace
The text was updated successfully, but these errors were encountered: