From fee15b9048803ca5c4277487fb8dc84bbdebed10 Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Tue, 22 Sep 2026 14:12:17 +0000 Subject: [PATCH] Clear the workspace clippy warnings and shrink the message enum by boxing the mounted working copy --- desktop/src/dirs.rs | 8 +- desktop/src/persist.rs | 9 +- desktop/wrapper/src/message_dispatcher.rs | 8 +- editor/src/dispatcher.rs | 12 +- .../messages/dialog/dialog_message_handler.rs | 2 +- .../messages/input_mapper/input_mappings.rs | 2 +- .../document/document_message_handler.rs | 10 +- .../utility_types/network_interface/caches.rs | 2 +- .../utility_types/network_interface/layout.rs | 2 +- .../network_interface/mutations.rs | 16 ++- .../utility_types/network_interface/store.rs | 4 +- .../utility_types/network_interface/view.rs | 8 +- .../messages/portfolio/portfolio_message.rs | 2 +- .../portfolio/portfolio_message_handler.rs | 4 +- .../shape_gizmos/spiral_turns_handle.rs | 1 + .../tool/common_functionality/shape_editor.rs | 4 +- .../shapes/shape_utility.rs | 7 +- .../snapping/distribution_snapper.rs | 1 - editor/src/node_graph_executor.rs | 4 +- node-graph/graphene-cli/src/main.rs | 1 - .../benches/benchmark_util.rs | 1 + .../libraries/rendering/src/renderer.rs | 4 +- node-graph/nodes/vector/src/vector_nodes.rs | 6 +- proc-macros/src/message_handler_data_attr.rs | 116 +++++++++--------- tools/crate-hierarchy-viz/src/main.rs | 5 +- 25 files changed, 125 insertions(+), 114 deletions(-) diff --git a/desktop/src/dirs.rs b/desktop/src/dirs.rs index c6f7c80aeb..ec2eefea81 100644 --- a/desktop/src/dirs.rs +++ b/desktop/src/dirs.rs @@ -20,10 +20,10 @@ pub(crate) fn clear_dir(path: &PathBuf) { if let Err(e) = fs::remove_dir_all(&entry_path) { tracing::error!("Failed to remove directory at {:?}: {}", entry_path, e); } - } else if entry_path.is_file() { - if let Err(e) = fs::remove_file(&entry_path) { - tracing::error!("Failed to remove file at {:?}: {}", entry_path, e); - } + } else if entry_path.is_file() + && let Err(e) = fs::remove_file(&entry_path) + { + tracing::error!("Failed to remove file at {:?}: {}", entry_path, e); } } } diff --git a/desktop/src/persist.rs b/desktop/src/persist.rs index f28ad4c8c4..7ac387a33f 100644 --- a/desktop/src/persist.rs +++ b/desktop/src/persist.rs @@ -71,10 +71,11 @@ fn garbage_collect_document_files(state: &PersistedState) { for entry in entries.flatten() { let path = entry.path(); - if path.is_file() && !valid_paths.contains(&path) { - if let Err(e) = std::fs::remove_file(&path) { - tracing::error!("Failed to remove orphaned document file {path:?}: {e}"); - } + if path.is_file() + && !valid_paths.contains(&path) + && let Err(e) = std::fs::remove_file(&path) + { + tracing::error!("Failed to remove orphaned document file {path:?}: {e}"); } } } diff --git a/desktop/wrapper/src/message_dispatcher.rs b/desktop/wrapper/src/message_dispatcher.rs index bb28296e06..ded85a52ec 100644 --- a/desktop/wrapper/src/message_dispatcher.rs +++ b/desktop/wrapper/src/message_dispatcher.rs @@ -44,10 +44,10 @@ impl<'a> DesktopWrapperMessageDispatcher<'a> { pub(super) fn poll_node_graph_evaluation(&mut self) { let mut responses = VecDeque::new(); - if let Err(e) = self.editor.poll_node_graph_evaluation(&mut responses) { - if e != "No active document" { - tracing::error!("Error poling node graph: {}", e); - } + if let Err(e) = self.editor.poll_node_graph_evaluation(&mut responses) + && e != "No active document" + { + tracing::error!("Error poling node graph: {}", e); } while let Some(message) = responses.pop_front() { self.queue_editor_message(message); diff --git a/editor/src/dispatcher.rs b/editor/src/dispatcher.rs index 6f8a9d407e..6ddd599179 100644 --- a/editor/src/dispatcher.rs +++ b/editor/src/dispatcher.rs @@ -496,15 +496,11 @@ mod test { if let FrontendMessage::UpdateLayout { layout_target: LayoutTarget::DialogColumn1, diff, - } = response + } = response && let DiffUpdate::Layout(sub_layout) = &diff[0].new_value + && let LayoutGroup::Row(WidgetRow { widgets }) = &sub_layout.0[0] + && let Widget::TextLabel(TextLabel { value, .. }) = &*widgets[0].widget { - if let DiffUpdate::Layout(sub_layout) = &diff[0].new_value { - if let LayoutGroup::Row(WidgetRow { widgets }) = &sub_layout.0[0] { - if let Widget::TextLabel(TextLabel { value, .. }) = &*widgets[0].widget { - print_problem_to_terminal_on_failure(value); - } - } - } + print_problem_to_terminal_on_failure(value); } } } diff --git a/editor/src/messages/dialog/dialog_message_handler.rs b/editor/src/messages/dialog/dialog_message_handler.rs index e788ff5364..58e9076a28 100644 --- a/editor/src/messages/dialog/dialog_message_handler.rs +++ b/editor/src/messages/dialog/dialog_message_handler.rs @@ -95,7 +95,7 @@ impl MessageHandler> for DialogMessageHa .network_interface .node_metadata(&layer.to_node(), &[]) .map(|node| node.persistent_metadata.display_name.clone()) - .and_then(|name| if name.is_empty() { None } else { Some(name) }) + .filter(|name| !name.is_empty()) .unwrap_or_else(|| "Artboard".to_string()); (layer, name) }) diff --git a/editor/src/messages/input_mapper/input_mappings.rs b/editor/src/messages/input_mapper/input_mappings.rs index 15b57bf3f5..fcd6bd4563 100644 --- a/editor/src/messages/input_mapper/input_mappings.rs +++ b/editor/src/messages/input_mapper/input_mappings.rs @@ -465,7 +465,7 @@ pub fn input_mappings(zoom_with_scroll: bool) -> Mapping { ]; let (mut key_up, mut key_down, mut key_up_no_repeat, mut key_down_no_repeat, mut double_click, mut wheel_scroll, mut pointer_move, mut pointer_shake) = mappings; - let sort = |list: &mut KeyMappingEntries| list.0.sort_by(|a, b| b.modifiers.count_ones().cmp(&a.modifiers.count_ones())); + let sort = |list: &mut KeyMappingEntries| list.0.sort_by_key(|entry| std::cmp::Reverse(entry.modifiers.count_ones())); // Sort the sublists of `key_up`, `key_down`, `key_up_no_repeat`, and `key_down_no_repeat` for list in [&mut key_up, &mut key_down, &mut key_up_no_repeat, &mut key_down_no_repeat] { for sublist in list { diff --git a/editor/src/messages/portfolio/document/document_message_handler.rs b/editor/src/messages/portfolio/document/document_message_handler.rs index 2520d76039..bb415834f6 100644 --- a/editor/src/messages/portfolio/document/document_message_handler.rs +++ b/editor/src/messages/portfolio/document/document_message_handler.rs @@ -4106,10 +4106,11 @@ mod document_message_handler_tests { async fn get_layer_by_bounds(editor: &mut EditorTestUtils, min_x: f64, min_y: f64) -> Option { let document = editor.active_document(); for layer in document.metadata().all_layers() { - if let Some(bbox) = document.metadata().bounding_box_viewport(layer) { - if (bbox[0].x - min_x).abs() < 1. && (bbox[0].y - min_y).abs() < 1. { - return Some(layer); - } + if let Some(bbox) = document.metadata().bounding_box_viewport(layer) + && (bbox[0].x - min_x).abs() < 1. + && (bbox[0].y - min_y).abs() < 1. + { + return Some(layer); } } None @@ -4166,7 +4167,6 @@ mod document_message_handler_tests { // The operation completed without crashing // Verifying application still functions by performing another operation editor.handle_message(DocumentMessage::CreateEmptyFolder).await; - assert!(true, "Application didn't crash after folder move operation"); } // Merging nodes whose output isn't wired downstream produces an encapsulating subnetwork with no exports. diff --git a/editor/src/messages/portfolio/document/utility_types/network_interface/caches.rs b/editor/src/messages/portfolio/document/utility_types/network_interface/caches.rs index 3a7dd4c120..dce3aa003a 100644 --- a/editor/src/messages/portfolio/document/utility_types/network_interface/caches.rs +++ b/editor/src/messages/portfolio/document/utility_types/network_interface/caches.rs @@ -543,7 +543,7 @@ impl NodeNetworkInterface { return; }; // Initialize all output connectors for nodes - for (node_id, _) in network.nodes.iter() { + for node_id in network.nodes.keys() { let number_of_outputs = self.number_of_outputs(node_id, network_path); for output_index in 0..number_of_outputs { outward_wires.insert(OutputConnector::node(*node_id, output_index), Vec::new()); diff --git a/editor/src/messages/portfolio/document/utility_types/network_interface/layout.rs b/editor/src/messages/portfolio/document/utility_types/network_interface/layout.rs index e7fc1ef226..fb7cd40f1f 100644 --- a/editor/src/messages/portfolio/document/utility_types/network_interface/layout.rs +++ b/editor/src/messages/portfolio/document/utility_types/network_interface/layout.rs @@ -321,7 +321,7 @@ impl NodeNetworkInterface { }) .collect::>(); - node_ids_with_position.sort_unstable_by(|a, b| a.1.cmp(&b.1)); + node_ids_with_position.sort_unstable_by_key(|a| a.1); Some(node_ids_with_position.into_iter().map(|(node_id, _)| node_id).collect::>()) } diff --git a/editor/src/messages/portfolio/document/utility_types/network_interface/mutations.rs b/editor/src/messages/portfolio/document/utility_types/network_interface/mutations.rs index 406f939019..6e6f3923e3 100644 --- a/editor/src/messages/portfolio/document/utility_types/network_interface/mutations.rs +++ b/editor/src/messages/portfolio/document/utility_types/network_interface/mutations.rs @@ -156,7 +156,11 @@ impl NodeNetworkInterface { }; let locator = NodeLocator::new(node_id, &encapsulating_network_path); - let inserted_index = if insert_index == -1 { self.number_of_inputs(&node_id, &encapsulating_network_path) } else { insert_index as usize }; + let inserted_index = if insert_index == -1 { + self.number_of_inputs(&node_id, &encapsulating_network_path) + } else { + insert_index as usize + }; if !self.insert_input_slot(locator, inserted_index, NodeInput::value(default_value, exposed), (input_name, input_description).into()) { return; } @@ -540,7 +544,9 @@ impl NodeNetworkInterface { return; } - let Some(old_input) = self.set_input_slot(input_connector, network_path, new_input.clone()) else { return }; + let Some(old_input) = self.set_input_slot(input_connector, network_path, new_input.clone()) else { + return; + }; self.transaction_modified(); self.update_outward_wires(network_path, input_connector, &old_input, &new_input); @@ -608,7 +614,9 @@ impl NodeNetworkInterface { } } - let Some(old_input) = self.set_input_slot(input_connector, network_path, new_input.clone()) else { return }; + let Some(old_input) = self.set_input_slot(input_connector, network_path, new_input.clone()) else { + return; + }; if old_input == new_input { return; @@ -1037,7 +1045,7 @@ impl NodeNetworkInterface { if !(matches!(reconnect_to_input, Some(NodeInput::Import { .. })) && matches!(downstream_input, InputConnector::Export(_))) && let Some(reconnect_input) = &reconnect_to_input { - reconnect_node = reconnect_input.as_node().and_then(|node_id| if self.is_stack(&node_id, network_path) { Some(node_id) } else { None }); + reconnect_node = reconnect_input.as_node().filter(|&node_id| self.is_stack(&node_id, network_path)); self.disconnect_input(&InputConnector::primary_input(*node_id), network_path); self.set_input(downstream_input, reconnect_input.clone(), network_path); } diff --git a/editor/src/messages/portfolio/document/utility_types/network_interface/store.rs b/editor/src/messages/portfolio/document/utility_types/network_interface/store.rs index fdf2791fc9..a508212c4a 100644 --- a/editor/src/messages/portfolio/document/utility_types/network_interface/store.rs +++ b/editor/src/messages/portfolio/document/utility_types/network_interface/store.rs @@ -389,7 +389,9 @@ impl NodeNetworkInterface { }, ); - previous_node.zip(previous_metadata).map(|(node, metadata)| NodeTemplate::from_parts(node, metadata.persistent_metadata)) + previous_node + .zip(previous_metadata) + .map(|(node, metadata)| NodeTemplate::from_parts(node, metadata.persistent_metadata)) } /// Removes a node and its metadata, returning them joined as a template. diff --git a/editor/src/messages/portfolio/document/utility_types/network_interface/view.rs b/editor/src/messages/portfolio/document/utility_types/network_interface/view.rs index d3cee8b246..88afa6c83b 100644 --- a/editor/src/messages/portfolio/document/utility_types/network_interface/view.rs +++ b/editor/src/messages/portfolio/document/utility_types/network_interface/view.rs @@ -227,7 +227,13 @@ impl<'a, 'p> NetworkView<'a, 'p> { /// Input rows the node displays: every exposed input, plus the primary input, whose row is shown even when it is not exposed. pub fn input_row_count(&self, node_id: &NodeId) -> Result { - Ok(self.node(node_id)?.inputs.iter().enumerate().filter(|(input_index, input)| *input_index == 0 || input.is_exposed()).count()) + Ok(self + .node(node_id)? + .inputs + .iter() + .enumerate() + .filter(|(input_index, input)| *input_index == 0 || input.is_exposed()) + .count()) } /// Grid rows the node body spans, which is the greater of its input rows and its output count. diff --git a/editor/src/messages/portfolio/portfolio_message.rs b/editor/src/messages/portfolio/portfolio_message.rs index bbed19141c..cf516318d3 100644 --- a/editor/src/messages/portfolio/portfolio_message.rs +++ b/editor/src/messages/portfolio/portfolio_message.rs @@ -55,7 +55,7 @@ pub enum PortfolioMessage { reopened: bool, #[serde(skip, default)] #[derivative(Debug = "ignore", PartialEq = "ignore", Clone(clone_with = "clone_to_none"))] - gdd: Option, + gdd: Option>, }, DestroyAllDocuments, EditorPreferences, diff --git a/editor/src/messages/portfolio/portfolio_message_handler.rs b/editor/src/messages/portfolio/portfolio_message_handler.rs index 8b9c11ead6..65fc56c823 100644 --- a/editor/src/messages/portfolio/portfolio_message_handler.rs +++ b/editor/src/messages/portfolio/portfolio_message_handler.rs @@ -314,7 +314,7 @@ impl MessageHandler> for Portfolio // Document was closed before its working copy finished mounting. return; }; - document.set_storage(gdd); + document.set_storage(gdd.map(|gdd| *gdd)); if !reopened { document.commit_storage_snapshot(&resource_storage.resources_mut(), preferences.validate_storage_round_trip); document.retire_storage_interaction(); @@ -1325,7 +1325,7 @@ impl PortfolioMessageHandler { Message::Portfolio(PortfolioMessage::DocumentStorageMounted { document_id, reopened, - gdd: Some(gdd), + gdd: Some(Box::new(gdd)), }) }; future.into() diff --git a/editor/src/messages/tool/common_functionality/gizmos/shape_gizmos/spiral_turns_handle.rs b/editor/src/messages/tool/common_functionality/gizmos/shape_gizmos/spiral_turns_handle.rs index 9b297339ed..b1a3c98851 100644 --- a/editor/src/messages/tool/common_functionality/gizmos/shape_gizmos/spiral_turns_handle.rs +++ b/editor/src/messages/tool/common_functionality/gizmos/shape_gizmos/spiral_turns_handle.rs @@ -68,6 +68,7 @@ impl SpiralTurns { self.handle_state == SpiralTurnsState::Dragging } + #[expect(clippy::too_many_arguments, reason = "the gizmo records one value per spiral parameter, so grouping them would only move the argument list")] pub fn store_initial_parameters( &mut self, layer: LayerNodeIdentifier, diff --git a/editor/src/messages/tool/common_functionality/shape_editor.rs b/editor/src/messages/tool/common_functionality/shape_editor.rs index 37208b9af1..9c88451be6 100644 --- a/editor/src/messages/tool/common_functionality/shape_editor.rs +++ b/editor/src/messages/tool/common_functionality/shape_editor.rs @@ -865,7 +865,7 @@ impl ShapeState { /// Deselects all the anchors across every selected layer. pub fn deselect_all_anchors(&mut self) { - for (_, state) in self.selected_shape_state.iter_mut() { + for state in self.selected_shape_state.values_mut() { let selected_anchor_points: Vec = state.selected_points.iter().filter(|selected_point| selected_point.as_anchor().is_some()).cloned().collect(); for point in selected_anchor_points { @@ -876,7 +876,7 @@ impl ShapeState { /// Deselects all the handles across every selected layer. pub fn deselect_all_handles(&mut self) { - for (_, state) in self.selected_shape_state.iter_mut() { + for state in self.selected_shape_state.values_mut() { let selected_handle_points: Vec = state.selected_points.iter().filter(|selected_point| selected_point.as_handle().is_some()).cloned().collect(); for point in selected_handle_points { diff --git a/editor/src/messages/tool/common_functionality/shapes/shape_utility.rs b/editor/src/messages/tool/common_functionality/shapes/shape_utility.rs index 6c077983a8..54415fd0d7 100644 --- a/editor/src/messages/tool/common_functionality/shapes/shape_utility.rs +++ b/editor/src/messages/tool/common_functionality/shapes/shape_utility.rs @@ -89,11 +89,8 @@ impl ShapeType { } pub fn tooltip_description(&self) -> String { - (match self { - // TODO: Add descriptions to all the shape tools - _ => "", - }) - .into() + // TODO: Add descriptions to all the shape tools + String::new() } pub fn icon_name(&self) -> String { diff --git a/editor/src/messages/tool/common_functionality/snapping/distribution_snapper.rs b/editor/src/messages/tool/common_functionality/snapping/distribution_snapper.rs index 543c2280ff..a30c729d68 100644 --- a/editor/src/messages/tool/common_functionality/snapping/distribution_snapper.rs +++ b/editor/src/messages/tool/common_functionality/snapping/distribution_snapper.rs @@ -677,7 +677,6 @@ mod tests { down: [10., 15.].map(|y| Rect::from_square(DVec2::new(0., y), 2.)).to_vec(), left: [-12., -15.].map(|x| Rect::from_square(DVec2::new(x, 0.), 2.)).to_vec(), right: [12., 15.].map(|x| Rect::from_square(DVec2::new(x, 0.), 2.)).to_vec(), - ..Default::default() }; let source = Rect::from_square(DVec2::new(0.3, 0.4), 2.); let snap_results = &mut SnapResults::default(); diff --git a/editor/src/node_graph_executor.rs b/editor/src/node_graph_executor.rs index 4211a9b9c3..c50879aa56 100644 --- a/editor/src/node_graph_executor.rs +++ b/editor/src/node_graph_executor.rs @@ -939,10 +939,8 @@ mod test { Some(x.output.clone()) } else if let Some(x) = dynamic.downcast_ref::>() { Some(x.output.clone()) - } else if let Some(x) = dynamic.downcast_ref::>() { - Some(x.output.clone()) } else { - None + dynamic.downcast_ref::>().map(|x| x.output.clone()) } } diff --git a/node-graph/graphene-cli/src/main.rs b/node-graph/graphene-cli/src/main.rs index 673b0c3aa2..765c96f6c0 100644 --- a/node-graph/graphene-cli/src/main.rs +++ b/node-graph/graphene-cli/src/main.rs @@ -7,7 +7,6 @@ use document_format::{GddV1, GddV1Layout}; use fern::colors::{Color, ColoredLevelConfig}; use futures::executor::block_on; use graph_craft::application_io::EditorPreferences; -use graph_craft::application_io::resource::ResourceRegistry; use graph_craft::application_io::{PlatformApplicationIo, PlatformEditorApi}; use graph_craft::document::*; use graph_craft::graphene_compiler::Compiler; diff --git a/node-graph/interpreted-executor/benches/benchmark_util.rs b/node-graph/interpreted-executor/benches/benchmark_util.rs index 54449ff13e..25c62f55f8 100644 --- a/node-graph/interpreted-executor/benches/benchmark_util.rs +++ b/node-graph/interpreted-executor/benches/benchmark_util.rs @@ -18,6 +18,7 @@ pub fn setup_network(name: &str) -> (DynamicExecutor, ProtoNetwork) { (executor, proto_network) } +#[allow(dead_code, reason = "shared by the bench targets, only some of which call it, and each compiles this module separately")] pub fn bench_for_each_demo(group: &mut BenchmarkGroup, f: F) where F: Fn(&str, &mut BenchmarkGroup), diff --git a/node-graph/libraries/rendering/src/renderer.rs b/node-graph/libraries/rendering/src/renderer.rs index 759353bacc..6bf1484b14 100644 --- a/node-graph/libraries/rendering/src/renderer.rs +++ b/node-graph/libraries/rendering/src/renderer.rs @@ -219,7 +219,7 @@ impl SvgRender { let (size_x, size_y) = (bounds_max - bounds_min).into(); let svg_header = format!( r#"{defs}"#, - defs = &self.svg_defs + defs = self.svg_defs ); self.svg_defs = String::new(); self.svg.insert(0, svg_header.into()); @@ -237,7 +237,7 @@ impl SvgRender { let svg_header = format!( r#"{defs}"#, - defs = &self.svg_defs + defs = self.svg_defs ); self.svg_defs = String::new(); self.svg.insert(0, svg_header.into()); diff --git a/node-graph/nodes/vector/src/vector_nodes.rs b/node-graph/nodes/vector/src/vector_nodes.rs index f661eddbcf..2b58bd7e1e 100644 --- a/node-graph/nodes/vector/src/vector_nodes.rs +++ b/node-graph/nodes/vector/src/vector_nodes.rs @@ -3708,7 +3708,7 @@ mod test { let result = super::voronoi_cells((), vector_item_from_points(&SQUARE_WITH_CENTER), item(true)).await; let vector = result.element(); assert!(vector.use_face_fill()); - assert!(vector.segment_domain.ids().len() > 0); + assert!(!vector.segment_domain.ids().is_empty()); } #[tokio::test] @@ -3739,8 +3739,8 @@ mod test { assert_eq!(vector.point_domain.ids().len(), points.len()); assert_ne!(vector.point_domain.positions(), &points[..]); // The convex-hull corners are pinned. - for i in 0..4 { - assert_eq!(vector.point_domain.positions()[i], points[i], "hull corner {i} should be pinned"); + for (corner, (&position, &point)) in vector.point_domain.positions().iter().zip(&points).take(4).enumerate() { + assert_eq!(position, point, "hull corner {corner} should be pinned"); } for &point in vector.point_domain.positions() { assert!(point.x >= -1e-6 && point.x <= 10. + 1e-6); diff --git a/proc-macros/src/message_handler_data_attr.rs b/proc-macros/src/message_handler_data_attr.rs index 7e38bbfef7..cbf45f79ec 100644 --- a/proc-macros/src/message_handler_data_attr.rs +++ b/proc-macros/src/message_handler_data_attr.rs @@ -29,76 +29,76 @@ pub fn message_handler_data_attr_impl(attr: TokenStream, input_item: TokenStream if segment.ident != "MessageHandler" { return Err(syn::Error::new(segment.ident.span(), "Expected MessageHandler trait")); } - if let syn::PathArguments::AngleBracketed(args) = &segment.arguments { - if args.args.len() >= 2 { - // Extract the message type (M) and context struct type (C) from the trait params - let message_type = &args.args[0]; - let data_type = &args.args[1]; + if let syn::PathArguments::AngleBracketed(args) = &segment.arguments + && args.args.len() >= 2 + { + // Extract the message type (M) and context struct type (C) from the trait params + let message_type = &args.args[0]; + let data_type = &args.args[1]; - let impl_item = match data_type { - syn::GenericArgument::Type(t) => { - match t { - syn::Type::Path(type_path) if !type_path.path.segments.is_empty() => { - // Get just the base identifier (ToolMessageData) without generics - let type_name = &type_path.path.segments.first().unwrap().ident; + let impl_item = match data_type { + syn::GenericArgument::Type(t) => { + match t { + syn::Type::Path(type_path) if !type_path.path.segments.is_empty() => { + // Get just the base identifier (ToolMessageData) without generics + let type_name = &type_path.path.segments.first().unwrap().ident; - let handler_data_line_number = type_name.span().start().line; + let handler_data_line_number = type_name.span().start().line; - quote! { - #input_item - impl #message_type { - pub fn message_handler_data_str() -> MessageData { - MessageData::new(format!("{}", stringify!(#type_name)), #type_name::field_types(), #type_name::path(), #type_name::line_number()) - } - pub fn message_handler_str() -> MessageData { - MessageData::new(format!("{}", stringify!(#input_type)), #input_type::field_types(), #input_type::path(), #input_type::line_number()) - - } - } - } - } - syn::Type::Tuple(_) => quote! { + quote! { #input_item impl #message_type { - pub fn message_handler_str() -> MessageData { - MessageData::new(format!("{}", stringify!(#input_type)), #input_type::field_types(), #input_type::path(), #input_type::line_number()) - } + pub fn message_handler_data_str() -> MessageData { + MessageData::new(format!("{}", stringify!(#type_name)), #type_name::field_types(), #type_name::path(), #type_name::line_number()) } - }, - syn::Type::Reference(type_reference) => { - let message_type = call_site_ident(format!("{input_type}Message")); - let type_ident = match &*type_reference.elem { - syn::Type::Path(type_path) => &type_path.path.segments.first().unwrap().ident, - _ => return Err(syn::Error::new(type_reference.elem.span(), "Expected type path")), - }; + pub fn message_handler_str() -> MessageData { + MessageData::new(format!("{}", stringify!(#input_type)), #input_type::field_types(), #input_type::path(), #input_type::line_number()) - let type_line_number = type_ident.span().start().line; - - let tr = clean_rust_type_syntax(type_reference.to_token_stream().to_string()); - quote! { - #input_item - impl #message_type { - pub fn message_handler_data_str() -> MessageData { - MessageData::new(format!("{}", #tr), #type_ident::field_types(), #type_ident::path(), #type_ident::line_number()) - } - - pub fn message_handler_str() -> MessageData { - MessageData::new(format!("{}", stringify!(#input_type)), #input_type::field_types(), #input_type::path(), #input_type::line_number()) - - } } } } - _ => return Err(syn::Error::new(t.span(), "Unsupported type format")), } - } + syn::Type::Tuple(_) => quote! { + #input_item + impl #message_type { + pub fn message_handler_str() -> MessageData { + MessageData::new(format!("{}", stringify!(#input_type)), #input_type::field_types(), #input_type::path(), #input_type::line_number()) + } + } + }, + syn::Type::Reference(type_reference) => { + let message_type = call_site_ident(format!("{input_type}Message")); + let type_ident = match &*type_reference.elem { + syn::Type::Path(type_path) => &type_path.path.segments.first().unwrap().ident, + _ => return Err(syn::Error::new(type_reference.elem.span(), "Expected type path")), + }; - _ => quote! { - #input_item - }, - }; - return Ok(impl_item); - } + let type_line_number = type_ident.span().start().line; + + let tr = clean_rust_type_syntax(type_reference.to_token_stream().to_string()); + quote! { + #input_item + impl #message_type { + pub fn message_handler_data_str() -> MessageData { + MessageData::new(format!("{}", #tr), #type_ident::field_types(), #type_ident::path(), #type_ident::line_number()) + } + + pub fn message_handler_str() -> MessageData { + MessageData::new(format!("{}", stringify!(#input_type)), #input_type::field_types(), #input_type::path(), #input_type::line_number()) + + } + } + } + } + _ => return Err(syn::Error::new(t.span(), "Unsupported type format")), + } + } + + _ => quote! { + #input_item + }, + }; + return Ok(impl_item); } } Ok(input_item) diff --git a/tools/crate-hierarchy-viz/src/main.rs b/tools/crate-hierarchy-viz/src/main.rs index a53eff48c1..c8f997e622 100644 --- a/tools/crate-hierarchy-viz/src/main.rs +++ b/tools/crate-hierarchy-viz/src/main.rs @@ -249,6 +249,9 @@ fn dot_to_svg(dot: &str) -> Result { String::from_utf8(output.stdout).with_context(|| "SVG output was not valid UTF-8") } +/// A Graphviz subgraph cluster: its id, its label, its fill color, and which crates belong to it. +type Cluster = (&'static str, &'static str, &'static str, Box bool>); + fn generate_dot(crates: &[CrateInfo]) -> String { let mut out = String::new(); out.push_str("digraph CrateHierarchy {\n"); @@ -257,7 +260,7 @@ fn generate_dot(crates: &[CrateInfo]) -> String { out.push_str(" edge [color=gray];\n\n"); // Define subgraph clusters - let clusters: &[(&str, &str, &str, Box bool>)] = &[ + let clusters: &[Cluster] = &[ ( "cluster_core", "Core Components",