Skip to content

Commit 4e7a2dc

Browse files
committed
Use item_name instead of pretty printing
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.
1 parent 18aa5ee commit 4e7a2dc

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -847,12 +847,17 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
847847

848848
// FIXME(jynelson): this shouldn't go through stringification, rustdoc should just use the DefId directly
849849
let self_name = self_id.and_then(|self_id| {
850+
use ty::TyKind;
850851
if matches!(self.cx.tcx.def_kind(self_id), DefKind::Impl) {
851-
// using `ty.to_string()` directly has issues with shortening paths
852+
// using `ty.to_string()` (or any variant) has issues with raw idents
852853
let ty = self.cx.tcx.type_of(self_id);
853-
let name = ty::print::with_crate_prefix(|| ty.to_string());
854-
debug!("using type_of(): {}", name);
855-
Some(name)
854+
let name = match ty.kind() {
855+
TyKind::Adt(def, _) => Some(self.cx.tcx.item_name(def.did).to_string()),
856+
other if other.is_primitive() => Some(ty.to_string()),
857+
_ => None,
858+
};
859+
debug!("using type_of(): {:?}", name);
860+
name
856861
} else {
857862
let name = self.cx.tcx.opt_item_name(self_id).map(|sym| sym.to_string());
858863
debug!("using item_name(): {:?}", name);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![deny(broken_intra_doc_links)]
2+
pub mod r#impl {
3+
pub struct S;
4+
5+
impl S {
6+
/// See [Self::b].
7+
// @has raw_ident_self/impl/struct.S.html
8+
// @has - '//a[@href="../../raw_ident_self/impl/struct.S.html#method.b"]' 'Self::b'
9+
pub fn a() {}
10+
11+
pub fn b() {}
12+
}
13+
}

0 commit comments

Comments
 (0)