feat: render Object Safety informations non-object safe traits

This commit is contained in:
Alexis (Poliorcetics) Bourget 2023-07-01 19:13:00 +02:00
parent ec2b311914
commit 51e22be682
3 changed files with 25 additions and 0 deletions

View File

@ -1455,6 +1455,9 @@ pub(crate) fn is_notable_trait(&self, tcx: TyCtxt<'_>) -> bool {
pub(crate) fn unsafety(&self, tcx: TyCtxt<'_>) -> hir::Unsafety { pub(crate) fn unsafety(&self, tcx: TyCtxt<'_>) -> hir::Unsafety {
tcx.trait_def(self.def_id).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)] #[derive(Clone, Debug)]

View File

@ -959,6 +959,20 @@ fn trait_item(w: &mut Buffer, cx: &mut Context<'_>, m: &clean::Item, t: &clean::
let cloned_shared = Rc::clone(&cx.shared); let cloned_shared = Rc::clone(&cx.shared);
let cache = &cloned_shared.cache; let cache = &cloned_shared.cache;
let mut extern_crates = FxHashSet::default(); 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()) { 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 // 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. // if any Types with the same name but different DefId have been found.

View File

@ -218,6 +218,14 @@ fn filter_items<'a>(
.map(|(id, title, items)| LinkBlock::new(Link::new(id, title), "", items)) .map(|(id, title, items)| LinkBlock::new(Link::new(id, title), "", items))
.collect(); .collect();
sidebar_assoc_items(cx, it, &mut blocks); 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")); blocks.push(LinkBlock::forced(Link::new("implementors", "Implementors"), "impl"));
if t.is_auto(cx.tcx()) { if t.is_auto(cx.tcx()) {
blocks.push(LinkBlock::forced( blocks.push(LinkBlock::forced(