diff options
| author | LegionMammal978 <mattlloydhouse@gmail.com> | 2023-05-15 14:31:00 -0400 |
|---|---|---|
| committer | LegionMammal978 <mattlloydhouse@gmail.com> | 2023-05-15 14:31:00 -0400 |
| commit | 77481099ca4be8fd8515d5e5bb873f3674cb7a2b (patch) | |
| tree | 313403bf007a0956918d7315dd8c5fbbe3749eb8 /library/std/src | |
| parent | 63b2ee0fafdb0043cb302a6d2e138122fb2c52bd (diff) | |
| download | rust-77481099ca4be8fd8515d5e5bb873f3674cb7a2b.tar.gz rust-77481099ca4be8fd8515d5e5bb873f3674cb7a2b.zip | |
Mark internal functions and traits unsafe
Diffstat (limited to 'library/std/src')
| -rw-r--r-- | library/std/src/path.rs | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/library/std/src/path.rs b/library/std/src/path.rs index 43203c5824d..febdeb51463 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -733,8 +733,9 @@ impl<'a> Components<'a> { } } - // parse a given byte sequence into the corresponding path component - fn parse_single_component<'b>(&self, comp: &'b [u8]) -> Option<Component<'b>> { + // parse a given byte sequence following the OsStr encoding into the + // corresponding path component + unsafe fn parse_single_component<'b>(&self, comp: &'b [u8]) -> Option<Component<'b>> { match comp { b"." if self.prefix_verbatim() => Some(Component::CurDir), b"." => None, // . components are normalized away, except at @@ -754,7 +755,8 @@ impl<'a> Components<'a> { None => (0, self.path), Some(i) => (1, &self.path[..i]), }; - (comp.len() + extra, self.parse_single_component(comp)) + // SAFETY: `comp` is a valid substring, since it is split on a separator. + (comp.len() + extra, unsafe { self.parse_single_component(comp) }) } // parse a component from the right, saying how many bytes to consume to @@ -766,7 +768,8 @@ impl<'a> Components<'a> { None => (0, &self.path[start..]), Some(i) => (1, &self.path[start + i + 1..]), }; - (comp.len() + extra, self.parse_single_component(comp)) + // SAFETY: `comp` is a valid substring, since it is split on a separator. + (comp.len() + extra, unsafe { self.parse_single_component(comp) }) } // trim away repeated separators (i.e., empty components) on the left |
