[rustdoc] Add new example disambiguator for intra-doc links by GuillaumeGomez · Pull Request #132792 · rust-lang/rust (original) (raw)

diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index fc0f73df799..553cfb0f2a1 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -506,13 +506,23 @@ pub(crate) fn links(&self, cx: &Context<'_>) -> Vec { } None }

@@ -1141,6 +1151,8 @@ pub(crate) enum ItemLinkKind { Example { /// The path of the example file. file_path: String,

diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index b7de93d08c2..6a1b39ba1ec 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -14,7 +14,7 @@ use rustc_errors::{Applicability, Diag, DiagMessage}; use rustc_hir::def::Namespace::*; use rustc_hir::def::{DefKind, Namespace, PerNS}; -use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LOCAL_CRATE}; +use rustc_hir::def_id::{CRATE_DEF_ID, CrateNum, DefId, LOCAL_CRATE}; use rustc_hir::{Mutability, Safety}; use rustc_middle::ty::{Ty, TyCtxt}; use rustc_middle::{bug, span_bug, ty}; @@ -68,7 +68,7 @@ fn filter_assoc_items_by_name_and_namespace<'a>( pub(crate) enum Res { Def(DefKind, DefId), Primitive(PrimitiveType),

}

type ResolveRes = rustc_hir::def::Res<rustc_ast::NodeId>; @@ -78,7 +78,7 @@ fn descr(&self) -> &'static str { match self { Res::Def(kind, id) => ResolveRes::Def(*kind, *id).descr(), Res::Primitive(_) => "primitive type",

@@ -86,7 +86,7 @@ fn article(&self) -> &'static str { match self { Res::Def(kind, id) => ResolveRes::Def(*kind, *id).article(), Res::Primitive(_) => "a",

@@ -94,7 +94,7 @@ fn name(&self, tcx: TyCtxt<'>) -> Symbol { match self { Res::Def(, id) => tcx.item_name(*id), Res::Primitive(prim) => prim.as_sym(),

@@ -102,7 +102,7 @@ fn def_id(&self, tcx: TyCtxt<'>) -> Option { match self { Res::Def(, id) => Some(*id), Res::Primitive(prim) => PrimitiveType::primitive_locations(tcx).get(prim).copied(),

@@ -114,7 +114,7 @@ fn from_def_id(tcx: TyCtxt<'>, def_id: DefId) -> Res { fn disambiguator_suggestion(&self) -> Suggestion { let kind = match self { Res::Primitive() => return Suggestion::Prefix("prim"),

@@ -1177,7 +1177,7 @@ pub(crate) fn resolve_ambiguities(&mut self) { info.resolved.retain(|(res, )| match res { Res::Def(, def_id) => self.validate_link(*def_id), // Primitive types and examples are always valid.

@@ -1313,11 +1313,11 @@ fn compute_link( kind: ItemLinkKind::Item { page_id }, }) }

@@ -1497,7 +1498,7 @@ fn get_example_file( && let Some(files) = self.cx.render_options.examples_files.get(crate_name) && let Some(file_path) = files.get(path_str) {

@@ -1528,7 +1529,7 @@ fn resolve_with_disambiguator( let module_id = key.module_id;

     if matches!(disambiguator, Some(Disambiguator::Example)) {

@@ -2077,7 +2078,7 @@ fn resolution_failure( partial_res.as_ref().expect("None case was handled by last_found_module"); let kind_did = match res { Res::Def(kind, did) => Some((kind, did)),