Skip to content

Commit fc4ca55

Browse files
committed
Add from_def_id_and_kind reducing duplication in rustdoc
- Add `Item::from_hir_id_and_kind` convenience wrapper - Make name parameter mandatory `tcx.opt_item_name` doesn't handle renames, so this is necessary for any item that could be renamed, which is almost all of them. - Override visibilities to be `Inherited` for enum variants `tcx.visibility` returns the effective visibility, not the visibility that was written in the source code. `pub enum E { A, B }` always has public variants `A` and `B`, so there's no sense printing `pub` again. - Don't duplicate handling of `Visibility::Crate` Instead, represent it as just another `Restricted` path.
1 parent c9a17b1 commit fc4ca55

File tree

5 files changed

+193
-260
lines changed

5 files changed

+193
-260
lines changed

src/librustdoc/clean/inline.rs

+8-20
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,8 @@ crate fn try_inline(
124124
let attrs = merge_attrs(cx, Some(parent_module), target_attrs, attrs_clone);
125125

126126
cx.renderinfo.borrow_mut().inlined.insert(did);
127-
ret.push(clean::Item {
128-
source: cx.tcx.def_span(did).clean(cx),
129-
name: Some(name.clean(cx)),
130-
attrs,
131-
kind,
132-
visibility: clean::Public,
133-
stability: cx.tcx.lookup_stability(did).cloned(),
134-
deprecation: cx.tcx.lookup_deprecation(did).clean(cx),
135-
def_id: did,
136-
});
127+
let what_rustc_thinks = clean::Item::from_def_id_and_parts(did, Some(name), kind, cx);
128+
ret.push(clean::Item { attrs, ..what_rustc_thinks });
137129
Some(ret)
138130
}
139131

@@ -443,8 +435,10 @@ crate fn build_impl(
443435

444436
debug!("build_impl: impl {:?} for {:?}", trait_.def_id(), for_.def_id());
445437

446-
ret.push(clean::Item {
447-
kind: clean::ImplItem(clean::Impl {
438+
ret.push(clean::Item::from_def_id_and_parts(
439+
did,
440+
None,
441+
clean::ImplItem(clean::Impl {
448442
unsafety: hir::Unsafety::Normal,
449443
generics,
450444
provided_trait_methods: provided,
@@ -455,14 +449,8 @@ crate fn build_impl(
455449
synthetic: false,
456450
blanket_impl: None,
457451
}),
458-
source: tcx.def_span(did).clean(cx),
459-
name: None,
460-
attrs,
461-
visibility: clean::Inherited,
462-
stability: tcx.lookup_stability(did).cloned(),
463-
deprecation: tcx.lookup_deprecation(did).clean(cx),
464-
def_id: did,
465-
});
452+
cx,
453+
));
466454
}
467455

468456
fn build_module(cx: &DocContext<'_>, did: DefId, visited: &mut FxHashSet<DefId>) -> clean::Module {

0 commit comments

Comments
 (0)