diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-10-31 19:03:20 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-31 19:03:20 +0100 |
| commit | 51b275bff8dca91d819ddf38e50debffd3feeb39 (patch) | |
| tree | 94aeef14e620b5981c3d8d1b28506664c250fc73 /src/librustdoc/html/render | |
| parent | d7d9f15be205b45d44700e7ac33b4f79b91f9680 (diff) | |
| parent | a119158eb39a5e251d0d309a261c11743b996ce0 (diff) | |
| download | rust-51b275bff8dca91d819ddf38e50debffd3feeb39.tar.gz rust-51b275bff8dca91d819ddf38e50debffd3feeb39.zip | |
Rollup merge of #113241 - poliorcetics:85138-doc-object-safety, r=GuillaumeGomez
rustdoc: Document lack of object safety on affected traits Closes #85138 I saw the issue didn't have any recent activity, if there is another MR for it I missed it. I want the issue to move forward so here is my proposition. It takes some space just before the "Implementors" section and only if the trait is **not** object safe since it is the only case where special care must be taken in some cases and this has the benefit of avoiding generation of HTML in (I hope) the common case.
Diffstat (limited to 'src/librustdoc/html/render')
| -rw-r--r-- | src/librustdoc/html/render/print_item.rs | 15 | ||||
| -rw-r--r-- | src/librustdoc/html/render/sidebar.rs | 8 |
2 files changed, 23 insertions, 0 deletions
diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 1c5a1dc99ad..65e7c08d521 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -954,6 +954,21 @@ 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. diff --git a/src/librustdoc/html/render/sidebar.rs b/src/librustdoc/html/render/sidebar.rs index 4e8d88c55b6..ba4aaaff5a7 100644 --- a/src/librustdoc/html/render/sidebar.rs +++ b/src/librustdoc/html/render/sidebar.rs @@ -218,6 +218,14 @@ 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( |
