Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8148053
Add supporting infrastructure for `run-make` V2 tests
jieyouxu Jan 20, 2024
e1826bf
Point to stage1-std when in stage2 rustc
jieyouxu Feb 2, 2024
6b2a824
Remove dead args from functions
compiler-errors Feb 2, 2024
c2a0d11
Fix incorrect stage std paths
jieyouxu Feb 2, 2024
0bfcafd
std::thread::available_parallelism merging linux/android/freebsd version
devnexen Feb 2, 2024
0ac1195
Invert diagnostic lints.
nnethercote Feb 5, 2024
ad3d04c
A drive-by rewrite of give_region_a_name()
amandasystems Feb 6, 2024
cd21b1d
No need to take ImplTraitContext by ref
compiler-errors Feb 7, 2024
0e4b55b
Reorder the diagnostic API methods.
nnethercote Feb 8, 2024
d1920a7
Fix inconsistencies in the diagnostic API methods.
nnethercote Feb 8, 2024
795be51
Make `RegionName` `Copy` by (transitively) interning the few string v…
amandasystems Feb 7, 2024
f676c3d
Remove myself from review rotation.
m-ou-se Feb 8, 2024
9224387
Correctly generate path for non-local items in source code pages
GuillaumeGomez Feb 2, 2024
41f9b57
Add regression test for non local items link generation
GuillaumeGomez Feb 3, 2024
11bd2ea
Unify item relative path computation in one function
GuillaumeGomez Feb 3, 2024
9293bbc
Rollup merge of #113026 - jieyouxu:run-make-v2, r=bjorn3
matthiaskrgr Feb 8, 2024
8038608
Rollup merge of #120589 - devnexen:cpuaff_fbsd_upd, r=m-ou-se
matthiaskrgr Feb 8, 2024
75070dc
Rollup merge of #120590 - compiler-errors:dead, r=Nilstrieb
matthiaskrgr Feb 8, 2024
c800a6f
Rollup merge of #120596 - GuillaumeGomez:jump-to-def-non-local-link, …
matthiaskrgr Feb 8, 2024
a85ca7a
Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davi…
matthiaskrgr Feb 8, 2024
e719ecf
Rollup merge of #120704 - amandasystems:silly-region-name-rewrite, r=…
matthiaskrgr Feb 8, 2024
0b6d175
Rollup merge of #120750 - compiler-errors:itctx-by-val, r=cjgillot
matthiaskrgr Feb 8, 2024
8c2f143
Rollup merge of #120765 - nnethercote:reorder-diag-API, r=compiler-er…
matthiaskrgr Feb 8, 2024
4c4d04f
Rollup merge of #120772 - m-ou-se:review, r=Nilstrieb
matthiaskrgr Feb 8, 2024
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
Prev Previous commit
Next Next commit
Unify item relative path computation in one function
  • Loading branch information
GuillaumeGomez committed Feb 8, 2024
commit 11bd2ea9397391acd3232f9f765dec36c24d289c
19 changes: 16 additions & 3 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,20 @@ pub(crate) fn load_attrs<'hir>(cx: &DocContext<'hir>, did: DefId) -> &'hir [ast:
cx.tcx.get_attrs_unchecked(did)
}

pub(crate) fn item_relative_path(tcx: TyCtxt<'_>, def_id: DefId) -> Vec<Symbol> {
tcx.def_path(def_id)
.data
.into_iter()
.filter_map(|elem| {
// extern blocks (and a few others things) have an empty name.
match elem.data.get_opt_name() {
Some(s) if !s.is_empty() => Some(s),
_ => None,
}
})
.collect()
}

/// Record an external fully qualified name in the external_paths cache.
///
/// These names are used later on by HTML rendering to generate things like
Expand All @@ -206,8 +220,7 @@ pub(crate) fn record_extern_fqn(cx: &mut DocContext<'_>, did: DefId, kind: ItemT

let crate_name = cx.tcx.crate_name(did.krate);

let relative =
cx.tcx.def_path(did).data.into_iter().filter_map(|elem| elem.data.get_opt_name());
let relative = item_relative_path(cx.tcx, did);
let fqn = if let ItemType::Macro = kind {
// Check to see if it is a macro 2.0 or built-in macro
if matches!(
Expand All @@ -218,7 +231,7 @@ pub(crate) fn record_extern_fqn(cx: &mut DocContext<'_>, did: DefId, kind: ItemT
) {
once(crate_name).chain(relative).collect()
} else {
vec![crate_name, relative.last().expect("relative was empty")]
vec![crate_name, *relative.last().expect("relative was empty")]
}
} else {
once(crate_name).chain(relative).collect()
Expand Down
26 changes: 2 additions & 24 deletions src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,18 +586,7 @@ fn generate_macro_def_id_path(
let crate_name = tcx.crate_name(def_id.krate);
let cache = cx.cache();

let fqp: Vec<Symbol> = tcx
.def_path(def_id)
.data
.into_iter()
.filter_map(|elem| {
// extern blocks (and a few others things) have an empty name.
match elem.data.get_opt_name() {
Some(s) if !s.is_empty() => Some(s),
_ => None,
}
})
.collect();
let fqp = clean::inline::item_relative_path(tcx, def_id);
let mut relative = fqp.iter().copied();
let cstore = CStore::from_tcx(tcx);
// We need this to prevent a `panic` when this function is used from intra doc links...
Expand Down Expand Up @@ -680,18 +669,7 @@ fn generate_item_def_id_path(
.unwrap_or(def_id);
}

let relative: Vec<Symbol> = tcx
.def_path(def_id)
.data
.into_iter()
.filter_map(|elem| {
// extern blocks (and a few others things) have an empty name.
match elem.data.get_opt_name() {
Some(s) if !s.is_empty() => Some(s),
_ => None,
}
})
.collect();
let relative = clean::inline::item_relative_path(tcx, def_id);
let fqp: Vec<Symbol> = once(crate_name).chain(relative).collect();

let def_kind = tcx.def_kind(def_id);
Expand Down
41 changes: 37 additions & 4 deletions tests/rustdoc/jump-to-non-local-method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,47 @@

#![crate_name = "foo"]

// @has 'src/foo/jump-to-non-local-method.rs.html'

// @has - '//a[@href="https://doc.rust-lang.org/nightly/core/sync/atomic/struct.AtomicIsize.html"]' 'std::sync::atomic::AtomicIsize'
use std::sync::atomic::AtomicIsize;
// @has - '//a[@href="https://doc.rust-lang.org/nightly/std/io/trait.Read.html"]' 'std::io::Read'
use std::io::Read;
// @has - '//a[@href="https://doc.rust-lang.org/nightly/std/io/index.html"]' 'std::io'
use std::io;
// @has - '//a[@href="https://doc.rust-lang.org/nightly/std/process/fn.exit.html"]' 'std::process::exit'
use std::process::exit;
use std::cmp::Ordering;
use std::marker::PhantomData;

// @has 'src/foo/jump-to-non-local-method.rs.html'
// @has - '//a[@href="https://doc.rust-lang.org/nightly/core/sync/atomic/struct.AtomicIsize.html#method.new"]' 'AtomicIsize::new'
pub fn bar2<T: Read>(readable: T) {
// @has - '//a[@href="https://doc.rust-lang.org/nightly/std/io/trait.Read.html#tymethod.read"]' 'read'
let _ = readable.read(&mut []);
}

pub fn bar() {
// @has - '//a[@href="https://doc.rust-lang.org/nightly/core/sync/atomic/struct.AtomicIsize.html#method.new"]' 'AtomicIsize::new'
let _ = AtomicIsize::new(0);
b();
// @has - '//a[@href="#48"]' 'local_private'
local_private();
}

pub fn extern_call() {
// @has - '//a[@href="https://doc.rust-lang.org/nightly/std/process/fn.exit.html"]' 'exit'
exit(0);
}

pub fn macro_call() -> Result<(), ()> {
// @has - '//a[@href="https://doc.rust-lang.org/nightly/core/macro.try.html"]' 'try!'
try!(Err(()));
Ok(())
}

pub fn variant() {
// @has - '//a[@href="https://doc.rust-lang.org/nightly/core/cmp/enum.Ordering.html#variant.Less"]' 'Ordering::Less'
let _ = Ordering::Less;
// @has - '//a[@href="https://doc.rust-lang.org/nightly/core/marker/struct.PhantomData.html"]' 'PhantomData'
let _: PhantomData::<usize> = PhantomData;
}

fn b() {}
fn local_private() {}