about summary refs log tree commit diff
path: root/compiler/rustc_span/src
diff options
context:
space:
mode:
authorMichael Howell <michael@notriddle.com>2024-03-29 12:31:34 -0700
committerMichael Howell <michael@notriddle.com>2024-03-29 13:31:35 -0700
commit98642da6a9dda39e711b7f3520b0b6d40c1cd043 (patch)
treebc3834326dc016ab7bb22636218b753f03c8aaf1 /compiler/rustc_span/src
parentd74804636fa57e80d1e213fa9d2d65b27216b515 (diff)
downloadrust-98642da6a9dda39e711b7f3520b0b6d40c1cd043.tar.gz
rust-98642da6a9dda39e711b7f3520b0b6d40c1cd043.zip
rustdoc: point at span in `include_str!`-ed md file
Diffstat (limited to 'compiler/rustc_span/src')
-rw-r--r--compiler/rustc_span/src/source_map.rs14
1 files changed, 11 insertions, 3 deletions
diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs
index df7635e447d..cac4d6064e5 100644
--- a/compiler/rustc_span/src/source_map.rs
+++ b/compiler/rustc_span/src/source_map.rs
@@ -218,7 +218,7 @@ impl SourceMap {
     ///
     /// Unlike `load_file`, guarantees that no normalization like BOM-removal
     /// takes place.
-    pub fn load_binary_file(&self, path: &Path) -> io::Result<Lrc<[u8]>> {
+    pub fn load_binary_file(&self, path: &Path) -> io::Result<(Lrc<[u8]>, Span)> {
         let bytes = self.file_loader.read_binary_file(path)?;
 
         // We need to add file to the `SourceMap`, so that it is present
@@ -227,8 +227,16 @@ impl SourceMap {
         // via `mod`, so we try to use real file contents and not just an
         // empty string.
         let text = std::str::from_utf8(&bytes).unwrap_or("").to_string();
-        self.new_source_file(path.to_owned().into(), text);
-        Ok(bytes)
+        let file = self.new_source_file(path.to_owned().into(), text);
+        Ok((
+            bytes,
+            Span::new(
+                file.start_pos,
+                BytePos(file.start_pos.0 + file.source_len.0),
+                SyntaxContext::root(),
+                None,
+            ),
+        ))
     }
 
     // By returning a `MonotonicVec`, we ensure that consumers cannot invalidate