Skip to content

jsondocck: Replace jsonpath_lib with jsonpath-rust #138763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 60 additions & 8 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1925,7 +1925,7 @@ version = "0.1.0"
dependencies = [
"fs-err",
"getopts",
"jsonpath_lib",
"jsonpath-rust",
"regex",
"serde_json",
"shlex",
Expand All @@ -1945,14 +1945,16 @@ dependencies = [
]

[[package]]
name = "jsonpath_lib"
version = "0.3.0"
name = "jsonpath-rust"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eaa63191d68230cccb81c5aa23abd53ed64d83337cacbb25a7b8c7979523774f"
checksum = "9b0231bb404a6cd6c8f0ab41b907049063a089fc02aa7636cc5cd9a4d87364c9"
dependencies = [
"log",
"serde",
"pest",
"pest_derive",
"regex",
"serde_json",
"thiserror 2.0.11",
]

[[package]]
Expand Down Expand Up @@ -2021,7 +2023,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34"
dependencies = [
"cfg-if",
"windows-targets 0.48.5",
"windows-targets 0.52.6",
]

[[package]]
Expand Down Expand Up @@ -2645,6 +2647,51 @@ dependencies = [
"libc",
]

[[package]]
name = "pest"
version = "2.7.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b7cafe60d6cf8e62e1b9b2ea516a089c008945bb5a275416789e7db0bc199dc"
dependencies = [
"memchr",
"thiserror 2.0.11",
"ucd-trie",
]

[[package]]
name = "pest_derive"
version = "2.7.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "816518421cfc6887a0d62bf441b6ffb4536fcc926395a69e1a85852d4363f57e"
dependencies = [
"pest",
"pest_generator",
]

[[package]]
name = "pest_generator"
version = "2.7.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d1396fd3a870fc7838768d171b4616d5c91f6cc25e377b673d714567d99377b"
dependencies = [
"pest",
"pest_meta",
"proc-macro2",
"quote",
"syn 2.0.96",
]

[[package]]
name = "pest_meta"
version = "2.7.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1e58089ea25d717bfd31fb534e4f3afcc2cc569c70de3e239778991ea3b7dea"
dependencies = [
"once_cell",
"pest",
"sha2",
]

[[package]]
name = "phf"
version = "0.11.3"
Expand Down Expand Up @@ -4780,7 +4827,6 @@ version = "1.0.135"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b0d7ba2887406110130a978386c4e1befb98c674b4fba677954e4db976630d9"
dependencies = [
"indexmap",
"itoa",
"memchr",
"ryu",
Expand Down Expand Up @@ -5486,6 +5532,12 @@ dependencies = [
"regex-lite",
]

[[package]]
name = "ucd-trie"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971"

[[package]]
name = "ui_test"
version = "0.26.5"
Expand Down
15 changes: 15 additions & 0 deletions src/bootstrap/src/utils/proc_macro_deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,43 @@ pub static CRATES: &[&str] = &[
"annotate-snippets",
"anstyle",
"basic-toml",
"block-buffer",
"bumpalo",
"cfg-if",
"cpufeatures",
"crypto-common",
"darling",
"darling_core",
"derive_builder_core",
"digest",
"fluent-bundle",
"fluent-langneg",
"fluent-syntax",
"fnv",
"generic-array",
"heck",
"ident_case",
"intl-memoizer",
"intl_pluralrules",
"libc",
"log",
"memchr",
"mime",
"mime_guess",
"minimal-lexical",
"nom",
"num-conv",
"once_cell",
"pest",
"pest_generator",
"pest_meta",
"proc-macro2",
"quote",
"rinja_parser",
"rustc-hash",
"self_cell",
"serde",
"sha2",
"smallvec",
"stable_deref_trait",
"strsim",
Expand All @@ -40,12 +52,15 @@ pub static CRATES: &[&str] = &[
"time-core",
"tinystr",
"type-map",
"typenum",
"ucd-trie",
"unic-langid",
"unic-langid-impl",
"unic-langid-macros",
"unicase",
"unicode-ident",
"unicode-width",
"version_check",
"wasm-bindgen-backend",
"wasm-bindgen-macro-support",
"wasm-bindgen-shared",
Expand Down
2 changes: 1 addition & 1 deletion src/tools/jsondocck/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
jsonpath_lib = "0.3"
jsonpath-rust = "1.0.0"
getopts = "0.2"
regex = "1.4"
shlex = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion src/tools/jsondocck/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ impl Cache {

// FIXME: Make this failible, so jsonpath syntax error has line number.
pub fn select(&self, path: &str) -> Vec<&Value> {
jsonpath_lib::select(&self.value, path).unwrap()
jsonpath_rust::query::js_path_vals(path, &self.value).unwrap()
}
}
24 changes: 12 additions & 12 deletions tests/rustdoc-json/assoc_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,32 @@
pub struct Simple;

impl Simple {
//@ has "$.index[*][?(@.name=='CONSTANT')].inner.assoc_const"
//@ has "$.index[?(@.name=='CONSTANT')].inner.assoc_const"
pub const CONSTANT: usize = 0;
}

pub trait EasyToImpl {
//@ has "$.index[*][?(@.docs=='ToDeclare trait')].inner.assoc_type"
//@ is "$.index[*][?(@.docs=='ToDeclare trait')].inner.assoc_type.type" null
//@ is "$.index[*][?(@.docs=='ToDeclare trait')].inner.assoc_type.bounds" []
//@ has "$.index[?(@.docs=='ToDeclare trait')].inner.assoc_type"
//@ is "$.index[?(@.docs=='ToDeclare trait')].inner.assoc_type.type" null
//@ is "$.index[?(@.docs=='ToDeclare trait')].inner.assoc_type.bounds" []
/// ToDeclare trait
type ToDeclare;
//@ has "$.index[*][?(@.docs=='AN_ATTRIBUTE trait')].inner.assoc_const"
//@ is "$.index[*][?(@.docs=='AN_ATTRIBUTE trait')].inner.assoc_const.value" null
//@ is "$.index[*][?(@.docs=='AN_ATTRIBUTE trait')].inner.assoc_const.type.primitive" '"usize"'
//@ has "$.index[?(@.docs=='AN_ATTRIBUTE trait')].inner.assoc_const"
//@ is "$.index[?(@.docs=='AN_ATTRIBUTE trait')].inner.assoc_const.value" null
//@ is "$.index[?(@.docs=='AN_ATTRIBUTE trait')].inner.assoc_const.type.primitive" '"usize"'
/// AN_ATTRIBUTE trait
const AN_ATTRIBUTE: usize;
}

impl EasyToImpl for Simple {
//@ has "$.index[*][?(@.docs=='ToDeclare impl')].inner.assoc_type"
//@ is "$.index[*][?(@.docs=='ToDeclare impl')].inner.assoc_type.type.primitive" \"usize\"
//@ has "$.index[?(@.docs=='ToDeclare impl')].inner.assoc_type"
//@ is "$.index[?(@.docs=='ToDeclare impl')].inner.assoc_type.type.primitive" \"usize\"
/// ToDeclare impl
type ToDeclare = usize;

//@ has "$.index[*][?(@.docs=='AN_ATTRIBUTE impl')].inner.assoc_const"
//@ is "$.index[*][?(@.docs=='AN_ATTRIBUTE impl')].inner.assoc_const.type.primitive" \"usize\"
//@ is "$.index[*][?(@.docs=='AN_ATTRIBUTE impl')].inner.assoc_const.value" \"12\"
//@ has "$.index[?(@.docs=='AN_ATTRIBUTE impl')].inner.assoc_const"
//@ is "$.index[?(@.docs=='AN_ATTRIBUTE impl')].inner.assoc_const.type.primitive" \"usize\"
//@ is "$.index[?(@.docs=='AN_ATTRIBUTE impl')].inner.assoc_const.value" \"12\"
/// AN_ATTRIBUTE impl
const AN_ATTRIBUTE: usize = 12;
}
8 changes: 4 additions & 4 deletions tests/rustdoc-json/assoc_type.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Regression test for <https://github.com/rust-lang/rust/issues/98547>.

//@ has "$.index[*][?(@.name=='Trait')]"
//@ has "$.index[*][?(@.name=='AssocType')]"
//@ has "$.index[*][?(@.name=='S')]"
//@ has "$.index[*][?(@.name=='S2')]"
//@ has "$.index[?(@.name=='Trait')]"
//@ has "$.index[?(@.name=='AssocType')]"
//@ has "$.index[?(@.name=='S')]"
//@ has "$.index[?(@.name=='S2')]"

pub trait Trait {
type AssocType;
Expand Down
32 changes: 16 additions & 16 deletions tests/rustdoc-json/attrs/deprecated.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
//@ is "$.index[*][?(@.name=='not')].attrs" []
//@ is "$.index[*][?(@.name=='not')].deprecation" null
//@ is "$.index[?(@.name=='not')].attrs" []
//@ is "$.index[?(@.name=='not')].deprecation" null
pub fn not() {}

//@ is "$.index[*][?(@.name=='raw')].attrs" []
//@ is "$.index[*][?(@.name=='raw')].deprecation" '{"since": null, "note": null}'
//@ is "$.index[?(@.name=='raw')].attrs" []
//@ is "$.index[?(@.name=='raw')].deprecation" '{"since": null, "note": null}'
#[deprecated]
pub fn raw() {}

//@ is "$.index[*][?(@.name=='equals_string')].attrs" []
//@ is "$.index[*][?(@.name=='equals_string')].deprecation" '{"since": null, "note": "here is a reason"}'
//@ is "$.index[?(@.name=='equals_string')].attrs" []
//@ is "$.index[?(@.name=='equals_string')].deprecation" '{"since": null, "note": "here is a reason"}'
#[deprecated = "here is a reason"]
pub fn equals_string() {}

//@ is "$.index[*][?(@.name=='since')].attrs" []
//@ is "$.index[*][?(@.name=='since')].deprecation" '{"since": "yoinks ago", "note": null}'
//@ is "$.index[?(@.name=='since')].attrs" []
//@ is "$.index[?(@.name=='since')].deprecation" '{"since": "yoinks ago", "note": null}'
#[deprecated(since = "yoinks ago")]
pub fn since() {}

//@ is "$.index[*][?(@.name=='note')].attrs" []
//@ is "$.index[*][?(@.name=='note')].deprecation" '{"since": null, "note": "7"}'
//@ is "$.index[?(@.name=='note')].attrs" []
//@ is "$.index[?(@.name=='note')].deprecation" '{"since": null, "note": "7"}'
#[deprecated(note = "7")]
pub fn note() {}

//@ is "$.index[*][?(@.name=='since_and_note')].attrs" []
//@ is "$.index[*][?(@.name=='since_and_note')].deprecation" '{"since": "tomorrow", "note": "sorry"}'
//@ is "$.index[?(@.name=='since_and_note')].attrs" []
//@ is "$.index[?(@.name=='since_and_note')].deprecation" '{"since": "tomorrow", "note": "sorry"}'
#[deprecated(since = "tomorrow", note = "sorry")]
pub fn since_and_note() {}

//@ is "$.index[*][?(@.name=='note_and_since')].attrs" []
//@ is "$.index[*][?(@.name=='note_and_since')].deprecation" '{"since": "a year from tomorrow", "note": "your welcome"}'
//@ is "$.index[?(@.name=='note_and_since')].attrs" []
//@ is "$.index[?(@.name=='note_and_since')].deprecation" '{"since": "a year from tomorrow", "note": "your welcome"}'
#[deprecated(note = "your welcome", since = "a year from tomorrow")]
pub fn note_and_since() {}

//@ is "$.index[*][?(@.name=='neither_but_parens')].attrs" []
//@ is "$.index[*][?(@.name=='neither_but_parens')].deprecation" '{"since": null, "note": null}'
//@ is "$.index[?(@.name=='neither_but_parens')].attrs" []
//@ is "$.index[?(@.name=='neither_but_parens')].deprecation" '{"since": null, "note": null}'
#[deprecated()]
pub fn neither_but_parens() {}
2 changes: 1 addition & 1 deletion tests/rustdoc-json/attrs/export_name_2021.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ edition: 2021
#![no_std]

//@ is "$.index[*][?(@.name=='example')].attrs" '["#[export_name = \"altered\"]"]'
//@ is "$.index[?(@.name=='example')].attrs" '["#[export_name = \"altered\"]"]'
#[export_name = "altered"]
pub extern "C" fn example() {}
2 changes: 1 addition & 1 deletion tests/rustdoc-json/attrs/export_name_2024.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
// The representation of `#[unsafe(export_name = ..)]` in rustdoc in edition 2024
// is still `#[export_name = ..]` without the `unsafe` attribute wrapper.

//@ is "$.index[*][?(@.name=='example')].attrs" '["#[export_name = \"altered\"]"]'
//@ is "$.index[?(@.name=='example')].attrs" '["#[export_name = \"altered\"]"]'
#[unsafe(export_name = "altered")]
pub extern "C" fn example() {}
4 changes: 2 additions & 2 deletions tests/rustdoc-json/attrs/must_use.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#![no_std]

//@ is "$.index[*][?(@.name=='example')].attrs" '["#[must_use]"]'
//@ is "$.index[?(@.name=='example')].attrs" '["#[must_use]"]'
#[must_use]
pub fn example() -> impl Iterator<Item = i64> {}

//@ is "$.index[*][?(@.name=='explicit_message')].attrs" '["#[must_use = \"does nothing if you do not use it\"]"]'
//@ is "$.index[?(@.name=='explicit_message')].attrs" '["#[must_use = \"does nothing if you do not use it\"]"]'
#[must_use = "does nothing if you do not use it"]
pub fn explicit_message() -> impl Iterator<Item = i64> {}
2 changes: 1 addition & 1 deletion tests/rustdoc-json/attrs/no_mangle_2021.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ edition: 2021
#![no_std]

//@ is "$.index[*][?(@.name=='example')].attrs" '["#[no_mangle]"]'
//@ is "$.index[?(@.name=='example')].attrs" '["#[no_mangle]"]'
#[no_mangle]
pub extern "C" fn example() {}
2 changes: 1 addition & 1 deletion tests/rustdoc-json/attrs/no_mangle_2024.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
// The representation of `#[unsafe(no_mangle)]` in rustdoc in edition 2024
// is still `#[no_mangle]` without the `unsafe` attribute wrapper.

//@ is "$.index[*][?(@.name=='example')].attrs" '["#[no_mangle]"]'
//@ is "$.index[?(@.name=='example')].attrs" '["#[no_mangle]"]'
#[unsafe(no_mangle)]
pub extern "C" fn example() {}
6 changes: 3 additions & 3 deletions tests/rustdoc-json/attrs/non_exhaustive.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#![no_std]

//@ is "$.index[*][?(@.name=='MyEnum')].attrs" '["#[non_exhaustive]"]'
//@ is "$.index[?(@.name=='MyEnum')].attrs" '["#[non_exhaustive]"]'
#[non_exhaustive]
pub enum MyEnum {
First,
}

pub enum NonExhaustiveVariant {
//@ is "$.index[*][?(@.name=='Variant')].attrs" '["#[non_exhaustive]"]'
//@ is "$.index[?(@.name=='Variant')].attrs" '["#[non_exhaustive]"]'
#[non_exhaustive]
Variant(i64),
}

//@ is "$.index[*][?(@.name=='MyStruct')].attrs" '["#[non_exhaustive]"]'
//@ is "$.index[?(@.name=='MyStruct')].attrs" '["#[non_exhaustive]"]'
#[non_exhaustive]
pub struct MyStruct {
pub x: i64,
Expand Down
2 changes: 1 addition & 1 deletion tests/rustdoc-json/attrs/repr_align.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![no_std]

//@ is "$.index[*][?(@.name=='Aligned')].attrs" '["#[attr = Repr([ReprAlign(Align(4 bytes))])]\n"]'
//@ is "$.index[?(@.name=='Aligned')].attrs" '["#[attr = Repr([ReprAlign(Align(4 bytes))])]\n"]'
#[repr(align(4))]
pub struct Aligned {
a: i8,
Expand Down
6 changes: 3 additions & 3 deletions tests/rustdoc-json/attrs/repr_c.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#![no_std]

//@ is "$.index[*][?(@.name=='ReprCStruct')].attrs" '["#[attr = Repr([ReprC])]\n"]'
//@ is "$.index[?(@.name=='ReprCStruct')].attrs" '["#[attr = Repr([ReprC])]\n"]'
#[repr(C)]
pub struct ReprCStruct(pub i64);

//@ is "$.index[*][?(@.name=='ReprCEnum')].attrs" '["#[attr = Repr([ReprC])]\n"]'
//@ is "$.index[?(@.name=='ReprCEnum')].attrs" '["#[attr = Repr([ReprC])]\n"]'
#[repr(C)]
pub enum ReprCEnum {
First,
}

//@ is "$.index[*][?(@.name=='ReprCUnion')].attrs" '["#[attr = Repr([ReprC])]\n"]'
//@ is "$.index[?(@.name=='ReprCUnion')].attrs" '["#[attr = Repr([ReprC])]\n"]'
#[repr(C)]
pub union ReprCUnion {
pub left: i64,
Expand Down
Loading
Loading