Rollup merge of #123204 - notriddle:notriddle/include-str-span, r=pnkfelix
rustdoc: point at span in `include_str!`-ed md file Fixes #118549
This commit is contained in:
commit
ffea7e2a9b
16 changed files with 141 additions and 55 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue