Skip to content

Commit d548b3b

Browse files
committed
Wip
1 parent 9f4d9dc commit d548b3b

File tree

4 files changed

+44
-12
lines changed

4 files changed

+44
-12
lines changed

src/librustdoc/json/conversions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ impl FromClean<clean::Type> for Type {
622622
impl FromClean<clean::Path> for Path {
623623
fn from_clean(path: clean::Path, renderer: &JsonRenderer<'_>) -> Path {
624624
Path {
625-
name: path.last_opt().map_or(String::from(""), |s| String::from(s.as_str())),
625+
name: path.whole_name(),
626626
id: renderer.id_from_item_default(path.def_id().into()),
627627
args: path.segments.last().map(|args| Box::new(args.clone().args.into_json(renderer))),
628628
}

src/rustdoc-json-types/lib.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub type FxHashMap<K, V> = HashMap<K, V>; // re-export for use in src/librustdoc
3030
/// This integer is incremented with every breaking change to the API,
3131
/// and is returned along with the JSON blob as [`Crate::format_version`].
3232
/// Consuming code should assert that this value matches the format version(s) that it supports.
33-
pub const FORMAT_VERSION: u32 = 38;
33+
pub const FORMAT_VERSION: u32 = 39;
3434

3535
/// The root of the emitted JSON blob.
3636
///
@@ -1036,15 +1036,7 @@ pub enum Type {
10361036
/// A type that has a simple path to it. This is the kind of type of structs, unions, enums, etc.
10371037
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
10381038
pub struct Path {
1039-
/// The name of the type as declared, e.g. in
1040-
///
1041-
/// ```rust
1042-
/// mod foo {
1043-
/// struct Bar;
1044-
/// }
1045-
/// ```
1046-
///
1047-
/// for `foo::Bar`, this field will be `Bar`.
1039+
/// The name of the type.
10481040
pub name: String,
10491041
/// The ID of the type.
10501042
pub id: Id,

tests/rustdoc-json/path_name.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Test for the Path::name field within a single crate.
2+
//
3+
// See https://github.com/rust-lang/rust/issues/135600
4+
// and https://github.com/rust-lang/rust/pull/134880#issuecomment-2596386111
5+
6+
mod priv_mod {
7+
pub struct InPrivMod;
8+
}
9+
10+
pub mod pub_mod {
11+
pub struct InPubMod;
12+
}
13+
14+
use priv_mod::InPrivMod as InPrivMod3;
15+
pub use priv_mod::{InPrivMod, InPrivMod as InPrivMod2};
16+
use pub_mod::InPubMod as InPubMod3;
17+
pub use pub_mod::{InPubMod, InPubMod as InPubMod2};
18+
19+
//@ is "$.index[*][?(@.name=='T0')].inner.type_alias.type.resolved_path.name" '"priv_mod::InPrivMod"'
20+
pub type T0 = priv_mod::InPrivMod;
21+
//@ is "$.index[*][?(@.name=='T1')].inner.type_alias.type.resolved_path.name" '"InPrivMod"'
22+
pub type T1 = InPrivMod;
23+
//@ is "$.index[*][?(@.name=='T2')].inner.type_alias.type.resolved_path.name" '"InPrivMod2"'
24+
pub type T2 = InPrivMod2;
25+
//@ is "$.index[*][?(@.name=='T3')].inner.type_alias.type.resolved_path.name" '"priv_mod::InPrivMod"'
26+
pub type T3 = InPrivMod3;
27+
28+
//@ is "$.index[*][?(@.name=='U0')].inner.type_alias.type.resolved_path.name" '"pub_mod::InPubMod"'
29+
pub type U0 = pub_mod::InPubMod;
30+
//@ is "$.index[*][?(@.name=='U1')].inner.type_alias.type.resolved_path.name" '"InPubMod"'
31+
pub type U1 = InPubMod;
32+
//@ is "$.index[*][?(@.name=='U2')].inner.type_alias.type.resolved_path.name" '"InPubMod2"'
33+
pub type U2 = InPubMod2;
34+
//@ is "$.index[*][?(@.name=='U3')].inner.type_alias.type.resolved_path.name" '"pub_mod::InPubMod"'
35+
pub type U3 = InPubMod3;
36+
37+
// Check we only have paths for structs at there origonal path
38+
//@ ismany "$.paths[*][?(@.crate_id==0 && @.kind=='struct')].path" '["path_name", "priv_mod", "InPrivMod"]' '["path_name", "pub_mod", "InPubMod"]'

tests/rustdoc-json/return_private.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
// ignore-tidy-linelength
33

44
mod secret {
5+
//@ set struct_secret = "$.index[*][?(@.name == 'Secret' && @.inner.struct)].id"
56
pub struct Secret;
67
}
78

89
//@ has "$.index[*][?(@.name=='get_secret')].inner.function"
9-
//@ is "$.index[*][?(@.name=='get_secret')].inner.function.sig.output.resolved_path.name" \"Secret\"
10+
//@ is "$.index[*][?(@.name=='get_secret')].inner.function.sig.output.resolved_path.name" '"secret::Secret"'
11+
//@ is "$.index[*][?(@.name=='get_secret')].inner.function.sig.output.resolved_path.id" $struct_secret
1012
pub fn get_secret() -> secret::Secret {
1113
secret::Secret
1214
}

0 commit comments

Comments
 (0)