Skip to content

Commit

Permalink
Rollup merge of rust-lang#131594 - fmease:rustdoc-mv-obj-safe-dyn-com…
Browse files Browse the repository at this point in the history
…pat, r=notriddle

rustdoc: Rename "object safe" to "dyn compatible"

Supersedes rust-lang#126554:

1. In line with [T-lang's latest resolution](rust-lang/lang-team#286 (comment)).
2. More comprehensive: Not only updates user-facing text but also source code.

Part of rust-lang#130852.

Doesn't update rustdoc-JSON (will be filed separately).

r? `@notriddle` (rust-lang/lang-team#286) `@GuillaumeGomez` (for visibility)
  • Loading branch information
matthiaskrgr authored Oct 16, 2024
2 parents c1ed1f1 + 6d82559 commit 7047748
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 42 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
14 changes: 8 additions & 6 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -934,16 +934,18 @@ 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 the URL once the Reference is updated.
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> \
<a href=\"{base}/reference/items/traits.html#object-safety\">\
object safe</a>.</div>",
"<div class=\"dyn-compatibility-info\"><p>This trait is <b>not</b> \
<a href=\"{base}/reference/items/traits.html#object-safety\">dyn compatible</a>.</p>\
<p><i>In older versions of Rust, dyn compatibility was called \"object safety\", \
so this trait is not object safe.</i></p></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
27 changes: 27 additions & 0 deletions tests/rustdoc/dyn-compatibility.rs
Original file line number Diff line number Diff line change
@@ -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<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 7047748

Please sign in to comment.