Skip to content

Commit

Permalink
rustdoc: Rename "object safe" to "dyn compatible"
Browse files Browse the repository at this point in the history
  • Loading branch information
fmease committed Oct 12, 2024
1 parent fb20e4d commit 41751a4
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1450,7 +1450,7 @@ impl Trait {
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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2002,7 +2002,7 @@ fn init_id_map() -> FxHashMap<Cow<'static, str>, 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);
Expand Down
11 changes: 6 additions & 5 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -934,16 +934,17 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &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 URL once the Reference is updated and hits stable.
write_section_heading(
w,
"Object Safety",
"object-safety",
"Dyn Compatibility",
"dyn-compatibility",
None,
&format!(
"<div class=\"object-safety-info\">This trait is <b>not</b> \
"<div class=\"dyn-compatibility-info\">This trait is <b>not</b> \
<a href=\"{base}/reference/items/traits.html#object-safety\">\
object safe</a>.</div>",
dyn compatible</a> (formerly known as object safe).</div>",
base = crate::clean::utils::DOC_RUST_LANG_ORG_CHANNEL
),
);
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/html/render/sidebar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,10 @@ fn sidebar_trait<'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",
));
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/json/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ impl FromClean<clean::Trait> for Trait {
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,
Expand Down
29 changes: 29 additions & 0 deletions tests/rustdoc/dyn-compatibility.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#![crate_name = "foo"]

//@ has 'foo/trait.DynIncompatible.html'
//@ has - '//*[@class="dyn-compatibility-info"]' \
// 'This trait is not dyn compatible (formerly known as object safe).'
//@ 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 (formerly known as object safe).'
//@ has - '//*[@id="dyn-compatibility"]' 'Dyn Compatibility'
pub trait DynIncompatible2<T> {
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;
6 changes: 3 additions & 3 deletions tests/rustdoc/sidebar/sidebar-items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,9 +25,9 @@ pub trait 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);
}

Expand Down
27 changes: 0 additions & 27 deletions tests/rustdoc/trait-object-safe.rs

This file was deleted.

0 comments on commit 41751a4

Please sign in to comment.