Skip to content

Commit

Permalink
Rollup merge of rust-lang#119246 - GuillaumeGomez:trait-is_object_saf…
Browse files Browse the repository at this point in the history
…e-json, r=aDotInTheVoid

[rustdoc] Add `is_object_safe` information for traits in JSON output

As asked by `@obi1kenobi` [here](rust-lang#113241 (comment)).

cc `@aDotInTheVoid`
r? `@notriddle`
  • Loading branch information
matthiaskrgr committed Dec 23, 2023
2 parents b136919 + 431ac40 commit 81161a6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/librustdoc/json/conversions.rs
Expand Up @@ -648,10 +648,12 @@ impl FromWithTcx<clean::Trait> for Trait {
fn from_tcx(trait_: clean::Trait, tcx: TyCtxt<'_>) -> Self {
let is_auto = trait_.is_auto(tcx);
let is_unsafe = trait_.unsafety(tcx) == rustc_hir::Unsafety::Unsafe;
let is_object_safe = trait_.is_object_safe(tcx);
let clean::Trait { items, generics, bounds, .. } = trait_;
Trait {
is_auto,
is_unsafe,
is_object_safe,
items: ids(items, tcx),
generics: generics.into_tcx(tcx),
bounds: bounds.into_tcx(tcx),
Expand Down
3 changes: 2 additions & 1 deletion src/rustdoc-json-types/lib.rs
Expand Up @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
use std::path::PathBuf;

/// rustdoc format-version.
pub const FORMAT_VERSION: u32 = 27;
pub const FORMAT_VERSION: u32 = 28;

/// A `Crate` is the root of the emitted JSON blob. It contains all type/documentation information
/// about the language items in the local crate, as well as info about external items to allow
Expand Down Expand Up @@ -634,6 +634,7 @@ pub struct FnDecl {
pub struct Trait {
pub is_auto: bool,
pub is_unsafe: bool,
pub is_object_safe: bool,
pub items: Vec<Id>,
pub generics: Generics,
pub bounds: Vec<GenericBound>,
Expand Down
19 changes: 19 additions & 0 deletions tests/rustdoc-json/traits/is_object_safe.rs
@@ -0,0 +1,19 @@
#![no_std]

// @has "$.index[*][?(@.name=='FooUnsafe')]"
// @is "$.index[*][?(@.name=='FooUnsafe')].inner.trait.is_object_safe" false
pub trait FooUnsafe {
fn foo() -> Self;
}

// @has "$.index[*][?(@.name=='BarUnsafe')]"
// @is "$.index[*][?(@.name=='BarUnsafe')].inner.trait.is_object_safe" false
pub trait BarUnsafe<T> {
fn foo(i: T);
}

// @has "$.index[*][?(@.name=='FooSafe')]"
// @is "$.index[*][?(@.name=='FooSafe')].inner.trait.is_object_safe" true
pub trait FooSafe {
fn foo(&self);
}
4 changes: 2 additions & 2 deletions tests/rustdoc/trait-object-safe.rs
Expand Up @@ -22,6 +22,6 @@ pub trait Safe {
}

// @has 'foo/struct.Foo.html'
// @!has - '//*[@class="object-safety-info"]' ''
// @!has - '//*[@id="object-safety"]' ''
// @count - '//*[@class="object-safety-info"]' 0
// @count - '//*[@id="object-safety"]' 0
pub struct Foo;

0 comments on commit 81161a6

Please sign in to comment.