Skip to content

Commit

Permalink
Use item_name instead of pretty printing
Browse files Browse the repository at this point in the history
Pretty printing would add a `r#` prefix to raw identifiers, which was
not correct. In general I think this change makes sense -
pretty-printing is for showing to the *user*, `item_name` is suitable to
pass to resolve.
  • Loading branch information
jyn514 committed Dec 2, 2020
1 parent 18aa5ee commit 4e7a2dc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/librustdoc/passes/collect_intra_doc_links.rs
Expand Up @@ -847,12 +847,17 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {

// FIXME(jynelson): this shouldn't go through stringification, rustdoc should just use the DefId directly
let self_name = self_id.and_then(|self_id| {
use ty::TyKind;
if matches!(self.cx.tcx.def_kind(self_id), DefKind::Impl) {
// using `ty.to_string()` directly has issues with shortening paths
// using `ty.to_string()` (or any variant) has issues with raw idents
let ty = self.cx.tcx.type_of(self_id);
let name = ty::print::with_crate_prefix(|| ty.to_string());
debug!("using type_of(): {}", name);
Some(name)
let name = match ty.kind() {
TyKind::Adt(def, _) => Some(self.cx.tcx.item_name(def.did).to_string()),
other if other.is_primitive() => Some(ty.to_string()),
_ => None,
};
debug!("using type_of(): {:?}", name);
name
} else {
let name = self.cx.tcx.opt_item_name(self_id).map(|sym| sym.to_string());
debug!("using item_name(): {:?}", name);
Expand Down
13 changes: 13 additions & 0 deletions src/test/rustdoc/intra-doc/raw-ident-self.rs
@@ -0,0 +1,13 @@
#![deny(broken_intra_doc_links)]
pub mod r#impl {
pub struct S;

impl S {
/// See [Self::b].
// @has raw_ident_self/impl/struct.S.html
// @has - '//a[@href="../../raw_ident_self/impl/struct.S.html#method.b"]' 'Self::b'
pub fn a() {}

pub fn b() {}
}
}

0 comments on commit 4e7a2dc

Please sign in to comment.