Skip to content

Commit 77baec6

Browse files
committed
feat: render Object Safety informations non-object safe traits
1 parent 2a4a8c8 commit 77baec6

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

src/librustdoc/clean/types.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,6 +1448,9 @@ impl Trait {
14481448
pub(crate) fn unsafety(&self, tcx: TyCtxt<'_>) -> hir::Unsafety {
14491449
tcx.trait_def(self.def_id).unsafety
14501450
}
1451+
pub(crate) fn is_object_safe(&self, tcx: TyCtxt<'_>) -> bool {
1452+
tcx.check_is_object_safe(self.def_id)
1453+
}
14511454
}
14521455

14531456
#[derive(Clone, Debug)]

src/librustdoc/html/render/print_item.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,20 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
958958
let cloned_shared = Rc::clone(&cx.shared);
959959
let cache = &cloned_shared.cache;
960960
let mut extern_crates = FxHashSet::default();
961+
962+
if !t.is_object_safe(cx.tcx()) {
963+
write_small_section_header(
964+
w,
965+
"object-safety",
966+
"Object Safety",
967+
&format!("<div class=\"object-safety-info\">This trait is <b>not</b> \
968+
<a href=\"{base}/reference/items/traits.html#object-safety\">\
969+
object safe</a>.</div>",
970+
base = crate::clean::utils::DOC_RUST_LANG_ORG_CHANNEL
971+
),
972+
);
973+
}
974+
961975
if let Some(implementors) = cache.implementors.get(&it.item_id.expect_def_id()) {
962976
// The DefId is for the first Type found with that name. The bool is
963977
// if any Types with the same name but different DefId have been found.

src/librustdoc/html/render/sidebar.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ fn sidebar_trait<'a>(
209209
.map(|(id, title, items)| LinkBlock::new(Link::new(id, title), items))
210210
.collect();
211211
sidebar_assoc_items(cx, it, &mut blocks);
212+
213+
if !t.is_object_safe(cx.tcx()) {
214+
blocks.push(LinkBlock::forced(Link::new("object-safety", "Object Safety")));
215+
}
216+
212217
blocks.push(LinkBlock::forced(Link::new("implementors", "Implementors")));
213218
if t.is_auto(cx.tcx()) {
214219
blocks.push(LinkBlock::forced(Link::new("synthetic-implementors", "Auto Implementors")));

0 commit comments

Comments
 (0)