Skip to content

Commit 51e22be

Browse files
committed
feat: render Object Safety informations non-object safe traits
1 parent ec2b311 commit 51e22be

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

src/librustdoc/clean/types.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1455,6 +1455,9 @@ impl Trait {
14551455
pub(crate) fn unsafety(&self, tcx: TyCtxt<'_>) -> hir::Unsafety {
14561456
tcx.trait_def(self.def_id).unsafety
14571457
}
1458+
pub(crate) fn is_object_safe(&self, tcx: TyCtxt<'_>) -> bool {
1459+
tcx.check_is_object_safe(self.def_id)
1460+
}
14581461
}
14591462

14601463
#[derive(Clone, Debug)]

src/librustdoc/html/render/print_item.rs

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

src/librustdoc/html/render/sidebar.rs

+8
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,14 @@ fn sidebar_trait<'a>(
218218
.map(|(id, title, items)| LinkBlock::new(Link::new(id, title), "", items))
219219
.collect();
220220
sidebar_assoc_items(cx, it, &mut blocks);
221+
222+
if !t.is_object_safe(cx.tcx()) {
223+
blocks.push(LinkBlock::forced(
224+
Link::new("object-safety", "Object Safety"),
225+
"object-safety-note",
226+
));
227+
}
228+
221229
blocks.push(LinkBlock::forced(Link::new("implementors", "Implementors"), "impl"));
222230
if t.is_auto(cx.tcx()) {
223231
blocks.push(LinkBlock::forced(

0 commit comments

Comments
 (0)