@@ -243,10 +243,10 @@ fn extract_config_docs_from_rustdoc(
243
243
// Check if this item is a struct by looking for the "struct" field
244
244
if get_json_object ( item, & [ "inner" , "struct" ] ) . is_some ( ) {
245
245
// Check if this struct is in our target list (if specified)
246
- if let Some ( targets) = target_structs {
247
- if !targets. contains ( & name. to_string ( ) ) {
248
- continue ;
249
- }
246
+ if let Some ( targets) = target_structs
247
+ && !targets. contains ( & name. to_string ( ) )
248
+ {
249
+ continue ;
250
250
}
251
251
252
252
let ( struct_doc_opt, referenced_constants) =
@@ -814,14 +814,12 @@ fn resolve_constant_reference(
814
814
815
815
for lib_name in & additional_crate_libs {
816
816
let json_file_path = format ! ( "target/rustdoc-json/doc/{lib_name}.json" ) ;
817
- if let Ok ( json_content) = std:: fs:: read_to_string ( & json_file_path) {
818
- if let Ok ( rustdoc_json) = serde_json:: from_str :: < serde_json:: Value > ( & json_content) {
819
- if let Some ( index) = get_json_object ( & rustdoc_json, & [ "index" ] ) {
820
- if let Some ( value) = resolve_constant_in_index ( name, index) {
821
- return Some ( value) ;
822
- }
823
- }
824
- }
817
+ if let Ok ( json_content) = std:: fs:: read_to_string ( & json_file_path)
818
+ && let Ok ( rustdoc_json) = serde_json:: from_str :: < serde_json:: Value > ( & json_content)
819
+ && let Some ( index) = get_json_object ( & rustdoc_json, & [ "index" ] )
820
+ && let Some ( value) = resolve_constant_in_index ( name, index)
821
+ {
822
+ return Some ( value) ;
825
823
}
826
824
}
827
825
@@ -835,61 +833,57 @@ fn resolve_constant_in_index(
835
833
// Look for a constant with the given name in the rustdoc index
836
834
for ( _item_id, item) in rustdoc_index {
837
835
// Check if this item's name matches the constant we're looking for
838
- if let Some ( item_name) = get_json_string ( item, & [ "name" ] ) {
839
- if item_name == name {
840
- // Check if this item is a constant by looking for the "constant" field
841
- if let Some ( constant_data) = get_json_object ( item, & [ "inner" , "constant" ] ) {
842
- // Try newer rustdoc JSON structure first (with nested 'const' field)
843
- let constant_data_value = serde_json:: Value :: Object ( constant_data. clone ( ) ) ;
844
- if get_json_object ( & constant_data_value, & [ "const" ] ) . is_some ( ) {
845
- // For literal constants, prefer expr which doesn't have type suffix
846
- if get_json_path ( & constant_data_value, & [ "const" , "is_literal" ] )
847
- . and_then ( |v| v. as_bool ( ) )
848
- == Some ( true )
849
- {
850
- // Access the expression field for literal constant values
851
- if let Some ( expr) =
852
- get_json_string ( & constant_data_value, & [ "const" , "expr" ] )
853
- {
854
- if expr != "_" {
855
- return Some ( expr. to_string ( ) ) ;
856
- }
857
- }
858
- }
859
-
860
- // For computed constants or when expr is "_", use value but strip type suffix
861
- if let Some ( value) =
862
- get_json_string ( & constant_data_value, & [ "const" , "value" ] )
863
- {
864
- return Some ( strip_type_suffix ( value) ) ;
865
- }
866
-
867
- // Fallback to expr if value is not available
836
+ if let Some ( item_name) = get_json_string ( item, & [ "name" ] )
837
+ && item_name == name
838
+ {
839
+ // Check if this item is a constant by looking for the "constant" field
840
+ if let Some ( constant_data) = get_json_object ( item, & [ "inner" , "constant" ] ) {
841
+ // Try newer rustdoc JSON structure first (with nested 'const' field)
842
+ let constant_data_value = serde_json:: Value :: Object ( constant_data. clone ( ) ) ;
843
+ if get_json_object ( & constant_data_value, & [ "const" ] ) . is_some ( ) {
844
+ // For literal constants, prefer expr which doesn't have type suffix
845
+ if get_json_path ( & constant_data_value, & [ "const" , "is_literal" ] )
846
+ . and_then ( |v| v. as_bool ( ) )
847
+ == Some ( true )
848
+ {
849
+ // Access the expression field for literal constant values
868
850
if let Some ( expr) =
869
851
get_json_string ( & constant_data_value, & [ "const" , "expr" ] )
852
+ && expr != "_"
870
853
{
871
- if expr != "_" {
872
- return Some ( expr. to_string ( ) ) ;
873
- }
854
+ return Some ( expr. to_string ( ) ) ;
874
855
}
875
856
}
876
857
877
- // Fall back to older rustdoc JSON structure for compatibility
878
- if let Some ( value) = get_json_string ( & constant_data_value, & [ "value" ] ) {
858
+ // For computed constants or when expr is "_", use value but strip type suffix
859
+ if let Some ( value) = get_json_string ( & constant_data_value, & [ "const" , "value" ] )
860
+ {
879
861
return Some ( strip_type_suffix ( value) ) ;
880
862
}
881
- if let Some ( expr) = get_json_string ( & constant_data_value, & [ "expr" ] ) {
882
- if expr != "_" {
883
- return Some ( expr. to_string ( ) ) ;
884
- }
885
- }
886
863
887
- // For some constants, the value might be in the type field if it's a simple literal
888
- if let Some ( type_str) = get_json_string ( & constant_data_value, & [ "type" ] ) {
889
- // Handle simple numeric or string literals embedded in type
890
- return Some ( type_str. to_string ( ) ) ;
864
+ // Fallback to expr if value is not available
865
+ if let Some ( expr) = get_json_string ( & constant_data_value, & [ "const" , "expr" ] )
866
+ && expr != "_"
867
+ {
868
+ return Some ( expr. to_string ( ) ) ;
891
869
}
892
870
}
871
+
872
+ // Fall back to older rustdoc JSON structure for compatibility
873
+ if let Some ( value) = get_json_string ( & constant_data_value, & [ "value" ] ) {
874
+ return Some ( strip_type_suffix ( value) ) ;
875
+ }
876
+ if let Some ( expr) = get_json_string ( & constant_data_value, & [ "expr" ] )
877
+ && expr != "_"
878
+ {
879
+ return Some ( expr. to_string ( ) ) ;
880
+ }
881
+
882
+ // For some constants, the value might be in the type field if it's a simple literal
883
+ if let Some ( type_str) = get_json_string ( & constant_data_value, & [ "type" ] ) {
884
+ // Handle simple numeric or string literals embedded in type
885
+ return Some ( type_str. to_string ( ) ) ;
886
+ }
893
887
}
894
888
}
895
889
}
0 commit comments