about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAlona Enraght-Moony <code@alona.page>2025-01-20 22:36:58 +0000
committerAlona Enraght-Moony <code@alona.page>2025-01-22 19:29:48 +0000
commit9c0e32bcd2727e95371f20fd7c9b86bc139e478e (patch)
tree6c5fa0d472da94f327c68a59a8c597023da3ed38 /src
parent9f4d9dc102fee5c1fe8adce2c4a58254cae510f4 (diff)
rustdoc-json: Rename `Path::name` to `path`, and give it path (again).
Closes https://github.com/rust-lang/rust/issues/135600

Effectivly reverts https://github.com/rust-lang/rust/pull/134880
Diffstat (limited to 'src')
-rw-r--r--src/librustdoc/json/conversions.rs2
-rw-r--r--src/rustdoc-json-types/lib.rs20
-rw-r--r--src/tools/jsondoclint/src/validator/tests.rs4
3 files changed, 15 insertions, 11 deletions
diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs
index 33166a39574..afe81937495 100644
--- a/src/librustdoc/json/conversions.rs
+++ b/src/librustdoc/json/conversions.rs
@@ -622,7 +622,7 @@ impl FromClean<clean::Type> for Type {
 impl FromClean<clean::Path> for Path {
     fn from_clean(path: clean::Path, renderer: &JsonRenderer<'_>) -> Path {
         Path {
-            name: path.last_opt().map_or(String::from(""), |s| String::from(s.as_str())),
+            path: path.whole_name(),
             id: renderer.id_from_item_default(path.def_id().into()),
             args: path.segments.last().map(|args| Box::new(args.clone().args.into_json(renderer))),
         }
diff --git a/src/rustdoc-json-types/lib.rs b/src/rustdoc-json-types/lib.rs
index 5a99977ded5..3b31bd21ce2 100644
--- a/src/rustdoc-json-types/lib.rs
+++ b/src/rustdoc-json-types/lib.rs
@@ -30,7 +30,7 @@ pub type FxHashMap<K, V> = HashMap<K, V>; // re-export for use in src/librustdoc
 /// This integer is incremented with every breaking change to the API,
 /// and is returned along with the JSON blob as [`Crate::format_version`].
 /// Consuming code should assert that this value matches the format version(s) that it supports.
-pub const FORMAT_VERSION: u32 = 38;
+pub const FORMAT_VERSION: u32 = 39;
 
 /// The root of the emitted JSON blob.
 ///
@@ -1036,16 +1036,20 @@ pub enum Type {
 /// A type that has a simple path to it. This is the kind of type of structs, unions, enums, etc.
 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
 pub struct Path {
-    /// The name of the type as declared, e.g. in
+    /// The path of the type.
+    ///
+    /// This will be the path that is *used* (not where it is defined), so
+    /// multiple `Path`s may have different values for this field even if
+    /// they all refer to the same item. e.g.
     ///
     /// ```rust
-    /// mod foo {
-    ///     struct Bar;
-    /// }
+    /// pub type Vec1 = std::vec::Vec<i32>; // path: "std::vec::Vec"
+    /// pub type Vec2 = Vec<i32>; // path: "Vec"
+    /// pub type Vec3 = std::prelude::v1::Vec<i32>; // path: "std::prelude::v1::Vec"
     /// ```
-    ///
-    /// for `foo::Bar`, this field will be `Bar`.
-    pub name: String,
+    //
+    // Example tested in ./tests/rustdoc-json/path_name.rs
+    pub path: String,
     /// The ID of the type.
     pub id: Id,
     /// Generic arguments to the type.
diff --git a/src/tools/jsondoclint/src/validator/tests.rs b/src/tools/jsondoclint/src/validator/tests.rs
index 7fcb8ffd1f9..a37e6c2eb5c 100644
--- a/src/tools/jsondoclint/src/validator/tests.rs
+++ b/src/tools/jsondoclint/src/validator/tests.rs
@@ -163,7 +163,7 @@ fn errors_on_missing_path() {
                     sig: FunctionSignature {
                         inputs: vec![],
                         output: Some(Type::ResolvedPath(Path {
-                            name: "Bar".to_owned(),
+                            path: "Bar".to_owned(),
                             id: Id(1),
                             args: None,
                         })),
@@ -191,7 +191,7 @@ fn errors_on_missing_path() {
 
     check(&krate, &[Error {
         kind: ErrorKind::Custom(
-            r#"No entry in '$.paths' for Path { name: "Bar", id: Id(1), args: None }"#.to_owned(),
+            r#"No entry in '$.paths' for Path { path: "Bar", id: Id(1), args: None }"#.to_owned(),
         ),
         id: Id(1),
     }]);