From f8d4856c08ecbdc05e7766b12e809a90ee7ede22 Mon Sep 17 00:00:00 2001 From: Urgau Date: Tue, 13 Oct 2026 20:47:57 +0200 Subject: [PATCH 1/3] Output remapped paths in rustdoc JSON with the `DOCUMENTATION` scope --- src/librustdoc/json/conversions.rs | 21 ++++++++----------- .../remap-path-prefix/debuginfo.rs | 5 +++++ tests/rustdoc-json/remap-path-prefix/diag.rs | 5 +++++ tests/rustdoc-json/remap-path-prefix/doc.rs | 5 +++++ .../rustdoc-json/remap-path-prefix/object.rs | 5 +++++ .../remap-path-prefix/remap-path-prefix.rs | 4 ++++ 6 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 tests/rustdoc-json/remap-path-prefix/debuginfo.rs create mode 100644 tests/rustdoc-json/remap-path-prefix/diag.rs create mode 100644 tests/rustdoc-json/remap-path-prefix/doc.rs create mode 100644 tests/rustdoc-json/remap-path-prefix/object.rs create mode 100644 tests/rustdoc-json/remap-path-prefix/remap-path-prefix.rs diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index 556a922f7044c..d23e9a8ca456a 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -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}; @@ -191,17 +191,14 @@ impl FromClean for Option { 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, } diff --git a/tests/rustdoc-json/remap-path-prefix/debuginfo.rs b/tests/rustdoc-json/remap-path-prefix/debuginfo.rs new file mode 100644 index 0000000000000..d378dca22be58 --- /dev/null +++ b/tests/rustdoc-json/remap-path-prefix/debuginfo.rs @@ -0,0 +1,5 @@ +//@ compile-flags: --remap-path-prefix={{src-base}}=/remapped +//@ compile-flags: --remap-path-scope=debuginfo -Zunstable-options + +//@ is "$.index[?(@.name=='StrLike')].span.filename" $FILE +pub trait StrLike {} diff --git a/tests/rustdoc-json/remap-path-prefix/diag.rs b/tests/rustdoc-json/remap-path-prefix/diag.rs new file mode 100644 index 0000000000000..79b469c40084e --- /dev/null +++ b/tests/rustdoc-json/remap-path-prefix/diag.rs @@ -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 {} diff --git a/tests/rustdoc-json/remap-path-prefix/doc.rs b/tests/rustdoc-json/remap-path-prefix/doc.rs new file mode 100644 index 0000000000000..11fa449983754 --- /dev/null +++ b/tests/rustdoc-json/remap-path-prefix/doc.rs @@ -0,0 +1,5 @@ +//@ 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 {} diff --git a/tests/rustdoc-json/remap-path-prefix/object.rs b/tests/rustdoc-json/remap-path-prefix/object.rs new file mode 100644 index 0000000000000..052ad7651eeab --- /dev/null +++ b/tests/rustdoc-json/remap-path-prefix/object.rs @@ -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 {} diff --git a/tests/rustdoc-json/remap-path-prefix/remap-path-prefix.rs b/tests/rustdoc-json/remap-path-prefix/remap-path-prefix.rs new file mode 100644 index 0000000000000..1d0a1fa65fad0 --- /dev/null +++ b/tests/rustdoc-json/remap-path-prefix/remap-path-prefix.rs @@ -0,0 +1,4 @@ +//@ 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 {} From 0d0f40400243a926ab26953a5b089252c06035fc Mon Sep 17 00:00:00 2001 From: Urgau Date: Tue, 13 Oct 2026 21:54:04 +0200 Subject: [PATCH 2/3] Add README.md and descriptions for the remap-path-prefix JSON tests --- tests/rustdoc-json/README.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 tests/rustdoc-json/README.md diff --git a/tests/rustdoc-json/README.md b/tests/rustdoc-json/README.md new file mode 100644 index 0000000000000..875a149585010 --- /dev/null +++ b/tests/rustdoc-json/README.md @@ -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 From 7fec32e649049621df4fd758c218e5800f021180 Mon Sep 17 00:00:00 2001 From: Urgau Date: Wed, 14 Oct 2026 23:17:01 +0200 Subject: [PATCH 3/3] Ignore the remap rustdoc-json tests on windows --- tests/rustdoc-json/remap-path-prefix/doc.rs | 1 + tests/rustdoc-json/remap-path-prefix/remap-path-prefix.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/rustdoc-json/remap-path-prefix/doc.rs b/tests/rustdoc-json/remap-path-prefix/doc.rs index 11fa449983754..aa3d13255753e 100644 --- a/tests/rustdoc-json/remap-path-prefix/doc.rs +++ b/tests/rustdoc-json/remap-path-prefix/doc.rs @@ -1,3 +1,4 @@ +//@ ignore-windows //@ compile-flags: --remap-path-prefix={{src-base}}=/remapped //@ compile-flags: --remap-path-scope=documentation -Zunstable-options diff --git a/tests/rustdoc-json/remap-path-prefix/remap-path-prefix.rs b/tests/rustdoc-json/remap-path-prefix/remap-path-prefix.rs index 1d0a1fa65fad0..b3c2001ac5fb2 100644 --- a/tests/rustdoc-json/remap-path-prefix/remap-path-prefix.rs +++ b/tests/rustdoc-json/remap-path-prefix/remap-path-prefix.rs @@ -1,3 +1,4 @@ +//@ ignore-windows //@ compile-flags: --remap-path-prefix={{src-base}}=/remapped //@ is "$.index[?(@.name=='StrLike')].span.filename" \"/remapped/remap-path-prefix/remap-path-prefix.rs\"