diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index bc5bf4c0583..44295fa0cd9 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -1450,7 +1450,7 @@ pub(crate) fn is_notable_trait(&self, tcx: TyCtxt<'_>) -> bool { pub(crate) fn safety(&self, tcx: TyCtxt<'_>) -> hir::Safety { tcx.trait_def(self.def_id).safety } - pub(crate) fn is_object_safe(&self, tcx: TyCtxt<'_>) -> bool { + pub(crate) fn is_dyn_compatible(&self, tcx: TyCtxt<'_>) -> bool { tcx.is_dyn_compatible(self.def_id) } } diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 5dacabd031e..315b7742a4c 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -2002,7 +2002,7 @@ fn init_id_map() -> FxHashMap, usize> { map.insert("required-associated-consts".into(), 1); map.insert("required-methods".into(), 1); map.insert("provided-methods".into(), 1); - map.insert("object-safety".into(), 1); + map.insert("dyn-compatibility".into(), 1); map.insert("implementors".into(), 1); map.insert("synthetic-implementors".into(), 1); map.insert("implementations-list".into(), 1); diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 3c96f873681..5e9cbef99a9 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -934,16 +934,18 @@ fn trait_item(w: &mut Buffer, cx: &mut Context<'_>, m: &clean::Item, t: &clean:: let cache = &cloned_shared.cache; let mut extern_crates = FxIndexSet::default(); - if !t.is_object_safe(cx.tcx()) { + if !t.is_dyn_compatible(cx.tcx()) { + // FIXME(dyn_compat_renaming): Update the URL once the Reference is updated. write_section_heading( w, - "Object Safety", - "object-safety", + "Dyn Compatibility", + "dyn-compatibility", None, &format!( - "
This trait is not \ - \ - object safe.
", + "

This trait is not \ + dyn compatible.

\ +

In older versions of Rust, dyn compatibility was called \"object safety\", \ + so this trait is not object safe.

", base = crate::clean::utils::DOC_RUST_LANG_ORG_CHANNEL ), ); diff --git a/src/librustdoc/html/render/sidebar.rs b/src/librustdoc/html/render/sidebar.rs index e7706e7fdea..6df9486e658 100644 --- a/src/librustdoc/html/render/sidebar.rs +++ b/src/librustdoc/html/render/sidebar.rs @@ -315,10 +315,10 @@ fn filter_items<'a>( ); sidebar_assoc_items(cx, it, blocks); - if !t.is_object_safe(cx.tcx()) { + if !t.is_dyn_compatible(cx.tcx()) { blocks.push(LinkBlock::forced( - Link::new("object-safety", "Object Safety"), - "object-safety-note", + Link::new("dyn-compatibility", "Dyn Compatibility"), + "dyn-compatibility-note", )); } diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index b8791c9918b..77e7d83090b 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -672,7 +672,7 @@ fn from_clean(trait_: clean::Trait, renderer: &JsonRenderer<'_>) -> Self { let tcx = renderer.tcx; let is_auto = trait_.is_auto(tcx); let is_unsafe = trait_.safety(tcx) == rustc_hir::Safety::Unsafe; - let is_object_safe = trait_.is_object_safe(tcx); + let is_object_safe = trait_.is_dyn_compatible(tcx); let clean::Trait { items, generics, bounds, .. } = trait_; Trait { is_auto, diff --git a/tests/rustdoc/dyn-compatibility.rs b/tests/rustdoc/dyn-compatibility.rs new file mode 100644 index 00000000000..9115f93bc3b --- /dev/null +++ b/tests/rustdoc/dyn-compatibility.rs @@ -0,0 +1,27 @@ +#![crate_name = "foo"] + +//@ has 'foo/trait.DynIncompatible.html' +//@ has - '//*[@class="dyn-compatibility-info"]' 'This trait is not dyn compatible.' +//@ has - '//*[@id="dyn-compatibility"]' 'Dyn Compatibility' +pub trait DynIncompatible { + fn foo() -> Self; +} + +//@ has 'foo/trait.DynIncompatible2.html' +//@ has - '//*[@class="dyn-compatibility-info"]' 'This trait is not dyn compatible.' +//@ has - '//*[@id="dyn-compatibility"]' 'Dyn Compatibility' +pub trait DynIncompatible2 { + fn foo(i: T); +} + +//@ has 'foo/trait.DynCompatible.html' +//@ !has - '//*[@class="dyn-compatibility-info"]' '' +//@ !has - '//*[@id="dyn-compatibility"]' '' +pub trait DynCompatible { + fn foo(&self); +} + +//@ has 'foo/struct.Foo.html' +//@ count - '//*[@class="dyn-compatibility-info"]' 0 +//@ count - '//*[@id="dyn-compatibility"]' 0 +pub struct Foo; diff --git a/tests/rustdoc/sidebar/sidebar-items.rs b/tests/rustdoc/sidebar/sidebar-items.rs index f3812143a7d..57c2eee91a9 100644 --- a/tests/rustdoc/sidebar/sidebar-items.rs +++ b/tests/rustdoc/sidebar/sidebar-items.rs @@ -14,7 +14,7 @@ //@ 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' -//@ has - '//div[@class="sidebar-elems"]//h3/a[@href="#object-safety"]' 'Object Safety' +//@ has - '//div[@class="sidebar-elems"]//h3/a[@href="#dyn-compatibility"]' 'Dyn Compatibility' pub trait Foo { const FOO: usize; const BAR: u32 = 0; @@ -25,9 +25,9 @@ fn foo() {} fn bar() -> Self::Output; } -//@ has foo/trait.Safe.html +//@ has foo/trait.DynCompatible.html //@ !has - '//div[@class="sidebar-elems"]//h3/a[@href="#object-safety"]' '' -pub trait Safe { +pub trait DynCompatible { fn access(&self); } diff --git a/tests/rustdoc/trait-object-safe.rs b/tests/rustdoc/trait-object-safe.rs deleted file mode 100644 index b4e986c8f69..00000000000 --- a/tests/rustdoc/trait-object-safe.rs +++ /dev/null @@ -1,27 +0,0 @@ -#![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 { - 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' -//@ count - '//*[@class="object-safety-info"]' 0 -//@ count - '//*[@id="object-safety"]' 0 -pub struct Foo;