Skip to content

Commit 42232ba

Browse files
committed
rustdoc: Add support for associated items even outside the impl itself
Previously, associated items would only be available for linking directly on the `impl Trait for Type`. Now they can be used anywhere. - Make `item` for resolve mandatory - Refactor resolving associated items into a separate function - Remove broken trait_item logic - Don't skip the type namespace for associated items - Only call `variant_field` for `TypeNS` - Add test for associated items - Use exhaustive matches instead of wildcards Wildcards caused several bugs while implementing this.
1 parent a97d65d commit 42232ba

File tree

4 files changed

+284
-89
lines changed

4 files changed

+284
-89
lines changed

src/librustdoc/clean/types.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_hir::lang_items;
2020
use rustc_hir::Mutability;
2121
use rustc_index::vec::IndexVec;
2222
use rustc_middle::middle::stability;
23-
use rustc_middle::ty::TyCtxt;
23+
use rustc_middle::ty::{AssocKind, TyCtxt};
2424
use rustc_span::hygiene::MacroKind;
2525
use rustc_span::source_map::DUMMY_SP;
2626
use rustc_span::symbol::{kw, sym, Ident, Symbol};
@@ -288,6 +288,15 @@ impl ItemEnum {
288288
_ => false,
289289
}
290290
}
291+
292+
pub fn as_assoc_kind(&self) -> Option<AssocKind> {
293+
match *self {
294+
ItemEnum::AssocConstItem(..) => Some(AssocKind::Const),
295+
ItemEnum::AssocTypeItem(..) => Some(AssocKind::Type),
296+
ItemEnum::TyMethodItem(..) | ItemEnum::MethodItem(..) => Some(AssocKind::Fn),
297+
_ => None,
298+
}
299+
}
291300
}
292301

293302
#[derive(Clone, Debug)]

0 commit comments

Comments
 (0)