Skip to content

Commit

Permalink
feat: render Object Safety informations non-object safe traits
Browse files Browse the repository at this point in the history
  • Loading branch information
poliorcetics committed Oct 29, 2023
1 parent ec2b311 commit 13b166a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,9 @@ impl Trait {
pub(crate) fn unsafety(&self, tcx: TyCtxt<'_>) -> hir::Unsafety {
tcx.trait_def(self.def_id).unsafety
}
pub(crate) fn is_object_safe(&self, tcx: TyCtxt<'_>) -> bool {
tcx.check_is_object_safe(self.def_id)
}
}

#[derive(Clone, Debug)]
Expand Down
14 changes: 14 additions & 0 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,20 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
let cloned_shared = Rc::clone(&cx.shared);
let cache = &cloned_shared.cache;
let mut extern_crates = FxHashSet::default();

if !t.is_object_safe(cx.tcx()) {
write_small_section_header(
w,
"object-safety",
"Object Safety",
&format!("<div class=\"object-safety-info\">This trait is <b>not</b> \
<a href=\"{base}/reference/items/traits.html#object-safety\">\
object safe</a>.</div>",
base = crate::clean::utils::DOC_RUST_LANG_ORG_CHANNEL
),
);
}

if let Some(implementors) = cache.implementors.get(&it.item_id.expect_def_id()) {
// The DefId is for the first Type found with that name. The bool is
// if any Types with the same name but different DefId have been found.
Expand Down
5 changes: 5 additions & 0 deletions src/librustdoc/html/render/sidebar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ fn sidebar_trait<'a>(
.map(|(id, title, items)| LinkBlock::new(Link::new(id, title), "", items))
.collect();
sidebar_assoc_items(cx, it, &mut blocks);

if !t.is_object_safe(cx.tcx()) {
blocks.push(LinkBlock::forced(Link::new("object-safety", "Object Safety"), "object-safety-note"));
}

blocks.push(LinkBlock::forced(Link::new("implementors", "Implementors"), "impl"));
if t.is_auto(cx.tcx()) {
blocks.push(LinkBlock::forced(
Expand Down

0 comments on commit 13b166a

Please sign in to comment.