Skip to content

Commit 2578c7d

Browse files
committed
fix collapsible_if clippy warning
1 parent 2803d0a commit 2578c7d

File tree

1 file changed

+50
-56
lines changed

1 file changed

+50
-56
lines changed

contrib/tools/config-docs-generator/src/extract_docs.rs

Lines changed: 50 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,10 @@ fn extract_config_docs_from_rustdoc(
243243
// Check if this item is a struct by looking for the "struct" field
244244
if get_json_object(item, &["inner", "struct"]).is_some() {
245245
// 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;
250250
}
251251

252252
let (struct_doc_opt, referenced_constants) =
@@ -814,14 +814,12 @@ fn resolve_constant_reference(
814814

815815
for lib_name in &additional_crate_libs {
816816
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);
825823
}
826824
}
827825

@@ -835,61 +833,57 @@ fn resolve_constant_in_index(
835833
// Look for a constant with the given name in the rustdoc index
836834
for (_item_id, item) in rustdoc_index {
837835
// 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
868850
if let Some(expr) =
869851
get_json_string(&constant_data_value, &["const", "expr"])
852+
&& expr != "_"
870853
{
871-
if expr != "_" {
872-
return Some(expr.to_string());
873-
}
854+
return Some(expr.to_string());
874855
}
875856
}
876857

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+
{
879861
return Some(strip_type_suffix(value));
880862
}
881-
if let Some(expr) = get_json_string(&constant_data_value, &["expr"]) {
882-
if expr != "_" {
883-
return Some(expr.to_string());
884-
}
885-
}
886863

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());
891869
}
892870
}
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+
}
893887
}
894888
}
895889
}

0 commit comments

Comments
 (0)