diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 28b2eded7cc3e..5a9bc5fe2e2b3 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -497,6 +497,13 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra // Output the trait definition wrap_into_docblock(w, |w| { + if let Some(def_id) = it.def_id.as_def_id() { + write!( + w, + "
This trait is {}object safe.
", + if cx.tcx().is_object_safe(def_id) { "" } else { "not " } + ); + } wrap_item(w, "trait", |w| { render_attributes_in_pre(w, it, ""); write!( diff --git a/src/test/rustdoc/trait-object-safe.rs b/src/test/rustdoc/trait-object-safe.rs new file mode 100644 index 0000000000000..3485ff1056270 --- /dev/null +++ b/src/test/rustdoc/trait-object-safe.rs @@ -0,0 +1,23 @@ +#![crate_name = "foo"] + +// @has 'foo/trait.Safe.html' +// @has - '//*[@class="obj-info"]' 'This trait is object safe.' +pub trait Safe { + fn foo(&self); +} + +// @has 'foo/trait.Unsafe.html' +// @has - '//*[@class="obj-info"]' 'This trait is not object safe.' +pub trait Unsafe { + fn foo() -> Self; +} + +// @has 'foo/trait.Unsafe2.html' +// @has - '//*[@class="obj-info"]' 'This trait is not object safe.' +pub trait Unsafe2 { + fn foo(i: T); +} + +// @has 'foo/struct.Foo.html' +// @!has - '//*[@class="obj-info"]' +pub struct Foo;