Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions src/librustdoc/json/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use rustc_hir_pretty::PpAnn;
use rustc_metadata::rendered_const;
use rustc_middle::ty::{self, TyCtxt};
use rustc_span::def_id::ModId;
use rustc_span::{Pos, Symbol, bug, kw, sym};
use rustc_span::{Pos, RemapPathScopeComponents, Symbol, bug, kw, sym};
use rustdoc_json_types::*;

use crate::clean::{self, ItemId};
Expand Down Expand Up @@ -191,17 +191,14 @@ impl FromClean<clean::Span> for Option<Span> {
fn from_clean(span: &clean::Span, renderer: &JsonRenderer<'_>) -> Self {
match span.filename(renderer.sess()) {
rustc_span::FileName::Real(name) => {
if let Some(local_path) = name.into_local_path() {
let hi = span.hi(renderer.sess());
let lo = span.lo(renderer.sess());
Some(Span {
filename: local_path,
begin: (lo.line, lo.col.to_usize() + 1),
end: (hi.line, hi.col.to_usize() + 1),
})
} else {
None
}
let filename = name.path(RemapPathScopeComponents::DOCUMENTATION);
let hi = span.hi(renderer.sess());
let lo = span.lo(renderer.sess());
Some(Span {
filename: filename.to_path_buf(),
begin: (lo.line, lo.col.to_usize() + 1),
end: (hi.line, hi.col.to_usize() + 1),
})
}
_ => None,
}
Expand Down
7 changes: 7 additions & 0 deletions tests/rustdoc-json/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## `tests/rustdoc-json/remap-path-prefix`

Tests for `--remap-path-prefix` and `--remap-path-scope` with rustdoc JSON:
- `remap-path-prefix`: only uses bare `--remap-path-prefix`, expects remapped paths
- `doc`: pass `--remap-path-prefix` and the `documentation` scope, expects remapped paths
- `object`: pass `--remap-path-prefix` and the `object` scope, expects un-remapped paths
- `debuginfo`: pass `--remap-path-prefix` and the `debuginfo` scope, expects un-remapped paths
5 changes: 5 additions & 0 deletions tests/rustdoc-json/remap-path-prefix/debuginfo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//@ compile-flags: --remap-path-prefix={{src-base}}=/remapped
Comment thread
Urgau marked this conversation as resolved.
//@ compile-flags: --remap-path-scope=debuginfo -Zunstable-options

//@ is "$.index[?(@.name=='StrLike')].span.filename" $FILE
pub trait StrLike {}
5 changes: 5 additions & 0 deletions tests/rustdoc-json/remap-path-prefix/diag.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//@ compile-flags: --remap-path-prefix={{src-base}}=/remapped
//@ compile-flags: --remap-path-scope=diagnostics -Zunstable-options

//@ is "$.index[?(@.name=='StrLike')].span.filename" $FILE
pub trait StrLike {}
6 changes: 6 additions & 0 deletions tests/rustdoc-json/remap-path-prefix/doc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//@ ignore-windows
//@ compile-flags: --remap-path-prefix={{src-base}}=/remapped
//@ compile-flags: --remap-path-scope=documentation -Zunstable-options

//@ is "$.index[?(@.name=='StrLike')].span.filename" \"/remapped/remap-path-prefix/doc.rs\"
pub trait StrLike {}
5 changes: 5 additions & 0 deletions tests/rustdoc-json/remap-path-prefix/object.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//@ compile-flags: --remap-path-prefix={{src-base}}=/remapped
//@ compile-flags: --remap-path-scope=object -Zunstable-options

//@ is "$.index[?(@.name=='StrLike')].span.filename" $FILE
pub trait StrLike {}
5 changes: 5 additions & 0 deletions tests/rustdoc-json/remap-path-prefix/remap-path-prefix.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//@ ignore-windows
//@ compile-flags: --remap-path-prefix={{src-base}}=/remapped

//@ is "$.index[?(@.name=='StrLike')].span.filename" \"/remapped/remap-path-prefix/remap-path-prefix.rs\"
pub trait StrLike {}
Loading