Skip to content

Add trait object safety information on trait documentation page #89553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
@@ -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,
"<div class=\"obj-info\">This trait is <b>{}object safe</b>.</div>",
if cx.tcx().is_object_safe(def_id) { "" } else { "not " }
);
}
wrap_item(w, "trait", |w| {
render_attributes_in_pre(w, it, "");
write!(
23 changes: 23 additions & 0 deletions src/test/rustdoc/trait-object-safe.rs
Original file line number Diff line number Diff line change
@@ -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<T> {
fn foo(i: T);
}

// @has 'foo/struct.Foo.html'
// @!has - '//*[@class="obj-info"]'
pub struct Foo;