diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-04-12 17:41:32 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-12 17:41:32 +0200 |
| commit | ffea7e2a9b5c3e4f3b3edcef2aa859ff1b298da2 (patch) | |
| tree | f830507a3d981670cb1a775c7c649ce2b7273f66 /compiler/rustc_span/src | |
| parent | bd71213cf0a765705e7d72a099151bd4eb465ccb (diff) | |
| parent | 1c41dd6320f1729e799171d98f5ff384246ddcd5 (diff) | |
| download | rust-ffea7e2a9b5c3e4f3b3edcef2aa859ff1b298da2.tar.gz rust-ffea7e2a9b5c3e4f3b3edcef2aa859ff1b298da2.zip | |
Rollup merge of #123204 - notriddle:notriddle/include-str-span, r=pnkfelix
rustdoc: point at span in `include_str!`-ed md file Fixes #118549
Diffstat (limited to 'compiler/rustc_span/src')
| -rw-r--r-- | compiler/rustc_span/src/source_map.rs | 14 |
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 f721a04d6b9..93d5f06a167 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 |
