Skip to content

Commit 54333ff

Browse files
committed
Auto merge of #156835 - yotamofek:pr/positive-dyn-compatible, r=fmease
Also emit "Dyn Compatibility" section for traits that *are* dyn compatible I was using the std docs to check if a trait was dyn compatible, and was very confused that it had no info about dyn compatibility. I had to go look at a trait that I knew for certain was *not* dyn compatible (`Clone`) to verify that we still had the dyn compatibility section, and that its omission meant a trait *was* compatible. (also removed the "..., so this trait is not object safe" text because it seemed pretty redundant) r? @fmease
2 parents b52edc2 + 877d57c commit 54333ff

2 files changed

Lines changed: 17 additions & 19 deletions

File tree

src/librustdoc/html/render/print_item.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -946,24 +946,22 @@ fn item_trait(cx: &Context<'_>, it: &clean::Item, t: &clean::Trait) -> impl fmt:
946946

947947
let mut extern_crates = FxIndexSet::default();
948948

949-
if !t.is_dyn_compatible(cx.tcx()) {
950-
write!(
951-
w,
952-
"{}",
953-
write_section_heading(
954-
"Dyn Compatibility",
955-
"dyn-compatibility",
956-
None,
957-
format!(
958-
"<div class=\"dyn-compatibility-info\"><p>This trait is <b>not</b> \
959-
<a href=\"{base}/reference/items/traits.html#dyn-compatibility\">dyn compatible</a>.</p>\
960-
<p><i>In older versions of Rust, dyn compatibility was called \"object safety\", \
961-
so this trait is not object safe.</i></p></div>",
962-
base = crate::clean::utils::DOC_RUST_LANG_ORG_VERSION
963-
),
949+
write!(
950+
w,
951+
"{}",
952+
write_section_heading(
953+
"Dyn Compatibility",
954+
"dyn-compatibility",
955+
None,
956+
format!(
957+
"<div class=\"dyn-compatibility-info\"><p>This trait {} \
958+
<a href=\"{base}/reference/items/traits.html#dyn-compatibility\">dyn compatible</a>.</p>\
959+
<p><i>In older versions of Rust, dyn compatibility was called \"object safety\".</i></p></div>",
960+
if t.is_dyn_compatible(cx.tcx()) { "<b>is</b>" } else { "is <b>not</b>" },
961+
base = crate::clean::utils::DOC_RUST_LANG_ORG_VERSION
964962
),
965-
)?;
966-
}
963+
),
964+
)?;
967965

968966
if let Some(implementors) = cx.shared.cache.implementors.get(&it.item_id.expect_def_id()) {
969967
// The DefId is for the first Type found with that name. The bool is

tests/rustdoc-html/dyn-compatibility.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ pub trait DynIncompatible2<T> {
1515
}
1616

1717
//@ has 'foo/trait.DynCompatible.html'
18-
//@ !has - '//*[@class="dyn-compatibility-info"]' ''
19-
//@ !has - '//*[@id="dyn-compatibility"]' ''
18+
//@ has - '//*[@class="dyn-compatibility-info"]' 'This trait is dyn compatible.'
19+
//@ has - '//*[@id="dyn-compatibility"]' 'Dyn Compatibility'
2020
pub trait DynCompatible {
2121
fn foo(&self);
2222
}

0 commit comments

Comments
 (0)