about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2024-04-18 22:17:10 +0200
committerRalf Jung <post@ralfj.de>2024-04-18 22:27:07 +0200
commit5067dd21b6e89fe74e588b8a11a0c8d3dd127029 (patch)
treee62ce352fcff9dca93cb871830dbed8579736220
parent1ce64e717f01ac40aae6c2321114d293993841bd (diff)
downloadrust-5067dd21b6e89fe74e588b8a11a0c8d3dd127029.tar.gz
rust-5067dd21b6e89fe74e588b8a11a0c8d3dd127029.zip
comment clarification and typo fix
-rw-r--r--src/tools/miri/src/shims/os_str.rs18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/tools/miri/src/shims/os_str.rs b/src/tools/miri/src/shims/os_str.rs
index 0409e31d65a..925a35beb62 100644
--- a/src/tools/miri/src/shims/os_str.rs
+++ b/src/tools/miri/src/shims/os_str.rs
@@ -260,6 +260,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
         let this = self.eval_context_ref();
         let target_os = &this.tcx.sess.target.os;
 
+        // Below we assume that everything non-Windows works like Unix, at least
+        // when it comes to file system path conventions.
         #[cfg(windows)]
         return if target_os == "windows" {
             // Windows-on-Windows, all fine.
@@ -297,6 +299,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
                     {
                         converted.remove(0);
                     }
+                    // If the path starts with `\\`, it is a magic Windows path. Conveniently, paths
+                    // starting with `//` on Unix are also magic where the first component can have
+                    // "application-specific" meaning, which is reflected e.g. by `path::absolute`
+                    // leaving leading `//` alone (but normalizing leading `///` to `/`). So we
+                    // don't have to do anything, the magic Windows path should work mostly fine as
+                    // a magic Unix path.
                 }
             }
             Cow::Owned(OsString::from_wide(&converted))
@@ -324,13 +332,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
                     {
                         converted.remove(0);
                     }
-                    // If this start withs a `\` but not a `\\`, then for Windows this is a relative
-                    // path. But the host path is absolute as it started with `/`. We add `\\?` so
-                    // it starts with `\\?\` which is some magic path on Windows that *is*
-                    // considered absolute.
+                    // If this starts withs a `\` but not a `\\`, then for Windows this is a
+                    // relative path (relative to "the root of the current directory", e.g. the
+                    // drive letter). But the host path on Unix is absolute as it starts with `/`.
                     else if converted.get(0).copied() == Some(b'\\')
                         && converted.get(1).copied() != Some(b'\\')
                     {
+                        // We add `\\?` so it starts with `\\?\` which is some magic path on Windows
+                        // that *is* considered absolute. This way we store the absolute host path
+                        // in something that looks like an absolute path to the (Windows) target.
                         converted.splice(0..0, b"\\\\?".iter().copied());
                     }
                 }