Fix path_trailing_sep methods for Windows verbatim paths - #162643
Conversation
|
rustbot has assigned @Mark-Simulacrum. Use Why was this reviewer chosen?The reviewer was selected based on:
|
| if self.has_trailing_sep() && (!self.has_root() || self.parent().is_some()) { | ||
| let mut bytes = self.inner.as_encoded_bytes(); | ||
| while let Some((last, init)) = bytes.split_last() | ||
| && is_sep_byte(*last) |
There was a problem hiding this comment.
Should we rename is_sep_byte to something less easy to reach for? It seems like in most (all?) cases code should be using path.components().is_sep_byte(...) instead? Should we document this on std::path::is_separator? I'm not 100% sure if all the existing usages are doing the right thing...
There was a problem hiding this comment.
To be honest I'd like to rewrite our path handling a fair bit. Trying to be maximally generic over all possible path types on all platforms ends up being overly complicated and easy to mess up because you have to be on guard all the time. I think it'd be better if we, at the very least, had system specific sys::Path types even if all they do is implement a few lowish level methods that the higher level std::path::Path can build on.
|
I think it's fine to merge this as is but I do agree we should have an issue for improving this. I'll write something up. @bors r=Mark-Simulacrum rollup |
… r=Mark-Simulacrum Fix `path_trailing_sep` methods for Windows verbatim paths Normally on Windows the path separator is either `\` or `/` but for verbatim paths it is only `\`. Currently the unstable `path_trailing_sep` methods (rust-lang#142503) do not take that into account and just use the general `is_sep_byte` method. This PR changes it to use the internal `Components::is_sep(self, b)` method that takes into account verbatim paths.
Rollup of 7 pull requests Successful merges: - #160911 (Remove d32 feature from 32-bit Arm targets) - #162771 (Filter do_not_recommend impls before handling a single candidate) - #162779 (rustdoc: Revert "fix bare urls split text") - #161612 (std: make a lot of items crate private) - #162372 (Clean up `test/rustdoc-html` folder by moving tests where appropriate) - #162643 (Fix `path_trailing_sep` methods for Windows verbatim paths) - #162784 (AGENTS.md: Permit local experimentation, per the online policy.)
… r=Mark-Simulacrum Fix `path_trailing_sep` methods for Windows verbatim paths Normally on Windows the path separator is either `\` or `/` but for verbatim paths it is only `\`. Currently the unstable `path_trailing_sep` methods (rust-lang#142503) do not take that into account and just use the general `is_sep_byte` method. This PR changes it to use the internal `Components::is_sep(self, b)` method that takes into account verbatim paths.
Rollup of 10 pull requests Successful merges: - #160911 (Remove d32 feature from 32-bit Arm targets) - #162771 (Filter do_not_recommend impls before handling a single candidate) - #162779 (rustdoc: Revert "fix bare urls split text") - #161548 (hir_typeck: Don't ICE on closures without drop location in closure capture lint) - #161612 (std: make a lot of items crate private) - #162204 (Suggest keyword order for `extern "C" const unsafe fn`) - #162372 (Clean up `test/rustdoc-html` folder by moving tests where appropriate) - #162638 (dont suggest changing the mutability of a borrow that comes from a macro) - #162643 (Fix `path_trailing_sep` methods for Windows verbatim paths) - #162784 (AGENTS.md: Permit local experimentation, per the online policy.)
Rollup of 10 pull requests Successful merges: - #160911 (Remove d32 feature from 32-bit Arm targets) - #162771 (Filter do_not_recommend impls before handling a single candidate) - #162779 (rustdoc: Revert "fix bare urls split text") - #161548 (hir_typeck: Don't ICE on closures without drop location in closure capture lint) - #161612 (std: make a lot of items crate private) - #162204 (Suggest keyword order for `extern "C" const unsafe fn`) - #162372 (Clean up `test/rustdoc-html` folder by moving tests where appropriate) - #162638 (dont suggest changing the mutability of a borrow that comes from a macro) - #162643 (Fix `path_trailing_sep` methods for Windows verbatim paths) - #162784 (AGENTS.md: Permit local experimentation, per the online policy.)
…uwer Rollup of 12 pull requests Successful merges: - #160911 (Remove d32 feature from 32-bit Arm targets) - #161868 (libtest: never iterate over all tests in `--exact` mode) - #162771 (Filter do_not_recommend impls before handling a single candidate) - #162779 (rustdoc: Revert "fix bare urls split text") - #161548 (hir_typeck: Don't ICE on closures without drop location in closure capture lint) - #161612 (std: make a lot of items crate private) - #162204 (Suggest keyword order for `extern "C" const unsafe fn`) - #162372 (Clean up `test/rustdoc-html` folder by moving tests where appropriate) - #162638 (dont suggest changing the mutability of a borrow that comes from a macro) - #162643 (Fix `path_trailing_sep` methods for Windows verbatim paths) - #162654 (Improve Armv7-R documentation) - #162784 (AGENTS.md: Permit local experimentation, per the online policy.)
Rollup merge of #162643 - ChrisDenton:trailing-sep-verbatim, r=Mark-Simulacrum Fix `path_trailing_sep` methods for Windows verbatim paths Normally on Windows the path separator is either `\` or `/` but for verbatim paths it is only `\`. Currently the unstable `path_trailing_sep` methods (#142503) do not take that into account and just use the general `is_sep_byte` method. This PR changes it to use the internal `Components::is_sep(self, b)` method that takes into account verbatim paths.
…uwer Rollup of 12 pull requests Successful merges: - rust-lang/rust#160911 (Remove d32 feature from 32-bit Arm targets) - rust-lang/rust#161868 (libtest: never iterate over all tests in `--exact` mode) - rust-lang/rust#162771 (Filter do_not_recommend impls before handling a single candidate) - rust-lang/rust#162779 (rustdoc: Revert "fix bare urls split text") - rust-lang/rust#161548 (hir_typeck: Don't ICE on closures without drop location in closure capture lint) - rust-lang/rust#161612 (std: make a lot of items crate private) - rust-lang/rust#162204 (Suggest keyword order for `extern "C" const unsafe fn`) - rust-lang/rust#162372 (Clean up `test/rustdoc-html` folder by moving tests where appropriate) - rust-lang/rust#162638 (dont suggest changing the mutability of a borrow that comes from a macro) - rust-lang/rust#162643 (Fix `path_trailing_sep` methods for Windows verbatim paths) - rust-lang/rust#162654 (Improve Armv7-R documentation) - rust-lang/rust#162784 (AGENTS.md: Permit local experimentation, per the online policy.)
Normally on Windows the path separator is either
\or/but for verbatim paths it is only\. Currently the unstablepath_trailing_sepmethods (#142503) do not take that into account and just use the generalis_sep_bytemethod.This PR changes it to use the internal
Components::is_sep(self, b)method that takes into account verbatim paths.