Change:
So that it is easy for user to recognize object-safe traits. <!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOTEND --
for the rustdoc side, just query the doc context with a given traitdef_id.
claim
Can you tell what are the relevant parts of rustdoc that needs to be changed?
sorry for late rely :) Add a field to , its value can be queried with like . Then you can append the object-safety info into the render part here I know little about the render code, could you leave some notes about that?
No, please do not add more fields to Trait. Query at the place it is used. I don't know much about render, may have suggestions.
I'm actually not sure what they want the end result to look like, so I don't know where to tell them to update the code. ;)
maybe it could be a cube icon to the right of the new button? On hover, there would be a tooltip saying or . I'm not sure where you get icons for rustdoc, but have a cube and cube-transparent icon that could be used for object-safe, and object-unsafe traits respectively. The could be reduced to fit in with the rest of the icons in rustdoc. If doesn't want to work on it I'd be happy to give it a go.
Following up from the PR with some UI discussion. I'd prefer not to add more icons up at the top of the page; we're already a bit crowded with icons. And there's no icon that has a broadly understood meaning of "object safe". I like the approach in , to write out "This trait is object-safe." But that PR puts it all the way at the top of the page, which is very high priority - and I would say object safety is more medium priority, so it should be lower on the page. One possibility would be to make an subheading in the top-doc docblock, but that results in using a lot of space for this. Our h2's are big! What about this: Under "Implementors", we could have at the very top "This trait is object safe. References to types that implement this trait can be automatically coerced to ". My reasoning here is that conceptually, is somewhat like an implementor of the trait.
I don't think this is necessarily true, you can have a that doesn't implement . But putting the text under "implementors" seems as good a place as any
Just out of curiosity, how can I have a that doesn’t implement ?
I don't think that's actually true, I misremembered.
We have one on: Would anyone else like to weigh in? Good enough to proceed with implementation?
Any update on this? :)
I'm not sure if it's already been suggested, but what about only showing a note if the trait is not object-safe?
I like suggestion to only show when a trait is not object safe, since that's the more unusual condition. If we do that, it doesn't fit logically under "Implementors" anymore. If we proceed with only marking non-object-safe traits, here are a couple of ideas: Add a section after the top-doc, but before "Implementors", called "Object Safety", and put the text there. Add information to the documentation of any method that causes the trait to be not object-safe.
I think it’s still fine to mention under “Implementors” like “This trait is not object safe: doesn’t implement ”, but I also like the idea of the new section. I see this issue doesn’t have an assignee currently, can I claim this?
You can but since we didn't reach a consensus, any PR would hang around until we reach one.

Discussion:
pub(crate) fn unsafety(&self, tcx: TyCtxt<'_>) -> hir::Unsafety { tcx.trait_def(self.def_id).unsafety } <ins> pub(crate) fn is_object_safe(&self, tcx: TyCtxt<'_>) -> bool { tcx.check_is_object_safe(self.def_id) } </ins> } #[derive(Clone, Debug)]

map.insert("required-associated-consts".into(), 1); map.insert("required-methods".into(), 1); map.insert("provided-methods".into(), 1); <ins> map.insert("object-safety".into(), 1); </ins> map.insert("implementors".into(), 1); map.insert("synthetic-implementors".into(), 1); map.insert("implementations-list".into(), 1);

let cloned_shared = Rc::clone(&cx.shared); let cache = &cloned_shared.cache; let mut extern_crates = FxHashSet::default(); <ins> 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 ), ); } </ins> 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.

.map(|(id, title, items)| LinkBlock::new(Link::new(id, title), "", items)) .collect(); sidebar_assoc_items(cx, it, &mut blocks); <ins> if !t.is_object_safe(cx.tcx()) { blocks.push(LinkBlock::forced( Link::new("object-safety", "Object Safety"), "object-safety-note", )); } </ins> blocks.push(LinkBlock::forced(Link::new("implementors", "Implementors"), "impl")); if t.is_auto(cx.tcx()) { blocks.push(LinkBlock::forced(

// @has - '//*[@class="sidebar-elems"]//section//a' 'Output' // @has - '//div[@class="sidebar-elems"]//h3/a[@href="#provided-associated-types"]' 'Provided Associated Types' // @has - '//*[@class="sidebar-elems"]//section//a' 'Extra' <ins> // @has - '//div[@class="sidebar-elems"]//h3/a[@href="#object-safety"]' 'Object Safety' </ins> pub trait Foo { const FOO: usize; const BAR: u32 = 0;

fn bar() -> Self::Output; } <ins> // @has foo/trait.Safe.html // @!has - '//div[@class="sidebar-elems"]//h3/a[@href="#object-safety"]' '' pub trait Safe { fn access(&self); } </ins> // @has foo/struct.Bar.html // @has - '//div[@class="sidebar-elems"]//h3/a[@href="#fields"]' 'Fields' // @has - '//*[@class="sidebar-elems"]//section//a[@href="#structfield.f"]' 'f'

<ins> #![crate_name = "foo"] // @has 'foo/trait.Unsafe.html' // @has - '//*[@class="object-safety-info"]' 'This trait is not object safe.' // @has - '//*[@id="object-safety"]' 'Object Safety' pub trait Unsafe { fn foo() -> Self; } // @has 'foo/trait.Unsafe2.html' // @has - '//*[@class="object-safety-info"]' 'This trait is not object safe.' // @has - '//*[@id="object-safety"]' 'Object Safety' pub trait Unsafe2<T> { fn foo(i: T); } // @has 'foo/trait.Safe.html' // @!has - '//*[@class="object-safety-info"]' '' // @!has - '//*[@id="object-safety"]' '' pub trait Safe { fn foo(&self); } // @has 'foo/struct.Foo.html' // @!has - '//*[@class="object-safety-info"]' '' // @!has - '//*[@id="object-safety"]' '' pub struct Foo; </ins>