Skip to content

Commit 7377871

Browse files
authored
Fix clippy warnings (#3085)
* Run clippy fix * Clippy v2 * Make const item static * Cargo fmt
1 parent c6ec3a2 commit 7377871

47 files changed

Lines changed: 218 additions & 258 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

editor/src/dispatcher.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ mod test {
442442
assert_eq!(layers_before_copy.len(), 3);
443443
assert_eq!(layers_after_copy.len(), 6);
444444

445-
println!("{:?} {:?}", layers_after_copy, layers_before_copy);
445+
println!("{layers_after_copy:?} {layers_before_copy:?}");
446446

447447
assert_eq!(layers_after_copy[5], shape_id);
448448
}

editor/src/messages/input_mapper/utility_types/input_keyboard.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ impl<const LENGTH: usize> Iterator for BitVectorIter<'_, LENGTH> {
479479
impl<const LENGTH: usize> Display for BitVector<LENGTH> {
480480
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
481481
for storage in self.0.iter().rev() {
482-
write!(f, "{:0width$b}", storage, width = STORAGE_SIZE_BITS)?;
482+
write!(f, "{storage:0STORAGE_SIZE_BITS$b}")?;
483483
}
484484

485485
Ok(())

editor/src/messages/message.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,11 @@ mod test {
7070
fn print_tree_node(tree: &DebugMessageTree, prefix: &str, is_last: bool, file: &mut std::fs::File) {
7171
// Print the current node
7272
let (branch, child_prefix) = if tree.message_handler_data_fields().is_some() || tree.message_handler_fields().is_some() {
73-
("├── ", format!("{}│ ", prefix))
73+
("├── ", format!("{prefix}│ "))
74+
} else if is_last {
75+
("└── ", format!("{prefix} "))
7476
} else {
75-
if is_last {
76-
("└── ", format!("{} ", prefix))
77-
} else {
78-
("├── ", format!("{}│ ", prefix))
79-
}
77+
("├── ", format!("{prefix}│ "))
8078
};
8179

8280
if tree.path().is_empty() {
@@ -101,17 +99,17 @@ mod test {
10199
let is_last_field = i == len - 1;
102100
let branch = if is_last_field { "└── " } else { "├── " };
103101

104-
file.write_all(format!("{}{}{}\n", child_prefix, branch, field).as_bytes()).unwrap();
102+
file.write_all(format!("{child_prefix}{branch}{field}\n").as_bytes()).unwrap();
105103
}
106104
}
107105

108106
// Print handler field if any
109107
if let Some(data) = tree.message_handler_fields() {
110108
let len = data.fields().len();
111109
let (branch, child_prefix) = if tree.message_handler_data_fields().is_some() {
112-
("├── ", format!("{}│ ", prefix))
110+
("├── ", format!("{prefix}│ "))
113111
} else {
114-
("└── ", format!("{} ", prefix))
112+
("└── ", format!("{prefix} "))
115113
};
116114

117115
const FRONTEND_MESSAGE_STR: &str = "FrontendMessage";

editor/src/messages/portfolio/document/graph_operation/transform_utils.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,32 @@ pub fn get_current_normalized_pivot(inputs: &[NodeInput]) -> DVec2 {
9191
if let Some(&TaggedValue::DVec2(pivot)) = inputs[5].as_value() { pivot } else { DVec2::splat(0.5) }
9292
}
9393

94+
/// Expand a bounds to avoid div zero errors
95+
fn clamp_bounds(bounds_min: DVec2, mut bounds_max: DVec2) -> [DVec2; 2] {
96+
let bounds_size = bounds_max - bounds_min;
97+
if bounds_size.x < 1e-10 {
98+
bounds_max.x = bounds_min.x + 1.;
99+
}
100+
if bounds_size.y < 1e-10 {
101+
bounds_max.y = bounds_min.y + 1.;
102+
}
103+
[bounds_min, bounds_max]
104+
}
105+
/// Returns corners of all subpaths
106+
fn subpath_bounds(subpaths: &[Subpath<PointId>]) -> [DVec2; 2] {
107+
subpaths
108+
.iter()
109+
.filter_map(|subpath| subpath.bounding_box())
110+
.reduce(|b1, b2| [b1[0].min(b2[0]), b1[1].max(b2[1])])
111+
.unwrap_or_default()
112+
}
113+
114+
/// Returns corners of all subpaths (but expanded to avoid division-by-zero errors)
115+
pub fn nonzero_subpath_bounds(subpaths: &[Subpath<PointId>]) -> [DVec2; 2] {
116+
let [bounds_min, bounds_max] = subpath_bounds(subpaths);
117+
clamp_bounds(bounds_min, bounds_max)
118+
}
119+
94120
#[cfg(test)]
95121
mod tests {
96122
use super::*;
@@ -138,29 +164,3 @@ mod tests {
138164
}
139165
}
140166
}
141-
142-
/// Expand a bounds to avoid div zero errors
143-
fn clamp_bounds(bounds_min: DVec2, mut bounds_max: DVec2) -> [DVec2; 2] {
144-
let bounds_size = bounds_max - bounds_min;
145-
if bounds_size.x < 1e-10 {
146-
bounds_max.x = bounds_min.x + 1.;
147-
}
148-
if bounds_size.y < 1e-10 {
149-
bounds_max.y = bounds_min.y + 1.;
150-
}
151-
[bounds_min, bounds_max]
152-
}
153-
/// Returns corners of all subpaths
154-
fn subpath_bounds(subpaths: &[Subpath<PointId>]) -> [DVec2; 2] {
155-
subpaths
156-
.iter()
157-
.filter_map(|subpath| subpath.bounding_box())
158-
.reduce(|b1, b2| [b1[0].min(b2[0]), b1[1].max(b2[1])])
159-
.unwrap_or_default()
160-
}
161-
162-
/// Returns corners of all subpaths (but expanded to avoid division-by-zero errors)
163-
pub fn nonzero_subpath_bounds(subpaths: &[Subpath<PointId>]) -> [DVec2; 2] {
164-
let [bounds_min, bounds_max] = subpath_bounds(subpaths);
165-
clamp_bounds(bounds_min, bounds_max)
166-
}

editor/src/messages/portfolio/document/node_graph/document_node_definitions.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl NodePropertiesContext<'_> {
4646
return None;
4747
};
4848
widget_override_lambda(*node_id, index, self)
49-
.map_err(|error| log::error!("Error in widget override lambda: {}", error))
49+
.map_err(|error| log::error!("Error in widget override lambda: {error}"))
5050
.ok()
5151
} else {
5252
None
@@ -1944,10 +1944,10 @@ fn static_input_properties() -> InputProperties {
19441944
"string".to_string(),
19451945
Box::new(|node_id, index, context| {
19461946
let Some(value) = context.network_interface.input_data(&node_id, index, "string_properties", context.selection_network_path) else {
1947-
return Err(format!("Could not get string properties for node {}", node_id));
1947+
return Err(format!("Could not get string properties for node {node_id}"));
19481948
};
19491949
let Some(string) = value.as_str() else {
1950-
return Err(format!("Could not downcast string properties for node {}", node_id));
1950+
return Err(format!("Could not downcast string properties for node {node_id}"));
19511951
};
19521952
Ok(node_properties::string_properties(string))
19531953
}),

editor/src/messages/portfolio/document/node_graph/document_node_definitions/document_node_derive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub(super) fn post_process_nodes(mut custom: Vec<DocumentNodeDefinition>) -> Vec
6060
document_node: DocumentNode {
6161
inputs,
6262
manual_composition: Some(input_type.clone()),
63-
implementation: DocumentNodeImplementation::ProtoNode(id.clone().into()),
63+
implementation: DocumentNodeImplementation::ProtoNode(id.clone()),
6464
visible: true,
6565
skip_deduplication: false,
6666
..Default::default()

editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,7 +1516,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
15161516
let mut nodes = Vec::new();
15171517
for node_id in &self.frontend_nodes {
15181518
let Some(node_bbox) = network_interface.node_bounding_box(node_id, breadcrumb_network_path) else {
1519-
log::error!("Could not get bbox for node: {:?}", node_id);
1519+
log::error!("Could not get bbox for node: {node_id:?}");
15201520
continue;
15211521
};
15221522

@@ -1721,7 +1721,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
17211721
}
17221722
NodeGraphMessage::ToggleLocked { node_id } => {
17231723
let Some(node_metadata) = network_interface.document_network_metadata().persistent_metadata.node_metadata.get(&node_id) else {
1724-
log::error!("Cannot get node {:?} in NodeGraphMessage::ToggleLocked", node_id);
1724+
log::error!("Cannot get node {node_id:?} in NodeGraphMessage::ToggleLocked");
17251725
return;
17261726
};
17271727

@@ -2486,7 +2486,7 @@ impl NodeGraphMessageHandler {
24862486
data_type: frontend_data_type,
24872487
name: "Output 1".to_string(),
24882488
description: String::new(),
2489-
resolved_type: format!("{:?}", output_type),
2489+
resolved_type: format!("{output_type:?}"),
24902490
connected_to,
24912491
})
24922492
} else {
@@ -2518,7 +2518,7 @@ impl NodeGraphMessageHandler {
25182518
data_type,
25192519
name: output_name,
25202520
description: String::new(),
2521-
resolved_type: format!("{:?}", output_type),
2521+
resolved_type: format!("{output_type:?}"),
25222522
connected_to,
25232523
});
25242524
}

editor/src/messages/portfolio/document/overlays/utility_types_vello.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1156,7 +1156,7 @@ impl OverlayContextInternal {
11561156
let move_to = last_point != Some(start_id);
11571157
last_point = Some(end_id);
11581158

1159-
self.bezier_to_path(bezier, row.transform.clone(), move_to, &mut path);
1159+
self.bezier_to_path(bezier, *row.transform, move_to, &mut path);
11601160
}
11611161

11621162
// Render the path

editor/src/messages/portfolio/document/utility_types/network_interface.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,8 @@ impl NodeNetworkInterface {
7373
fix_network(network);
7474
}
7575
if let DocumentNodeImplementation::ProtoNode(protonode) = &node.implementation {
76-
if protonode.name.contains("PathModifyNode") {
77-
if node.inputs.len() < 3 {
78-
node.inputs.push(NodeInput::Reflection(graph_craft::document::DocumentNodeMetadata::DocumentNodePath));
79-
}
76+
if protonode.name.contains("PathModifyNode") && node.inputs.len() < 3 {
77+
node.inputs.push(NodeInput::Reflection(graph_craft::document::DocumentNodeMetadata::DocumentNodePath));
8078
}
8179
}
8280
}
@@ -821,7 +819,7 @@ impl NodeNetworkInterface {
821819
data_type,
822820
name,
823821
description,
824-
resolved_type: format!("{:?}", input_type),
822+
resolved_type: format!("{input_type:?}"),
825823
connected_to,
826824
},
827825
click_target,
@@ -1069,7 +1067,7 @@ impl NodeNetworkInterface {
10691067

10701068
pub fn reference(&self, node_id: &NodeId, network_path: &[NodeId]) -> Option<&Option<String>> {
10711069
let Some(node_metadata) = self.node_metadata(node_id, network_path) else {
1072-
log::error!("Could not get reference for node: {:?}", node_id);
1070+
log::error!("Could not get reference for node: {node_id:?}");
10731071
return None;
10741072
};
10751073
Some(&node_metadata.persistent_metadata.reference)
@@ -2522,15 +2520,15 @@ impl NodeNetworkInterface {
25222520
InputConnector::Node { node_id, input_index } => {
25232521
let input_metadata = self.transient_input_metadata(node_id, *input_index, network_path)?;
25242522
let TransientMetadata::Loaded(wire) = &input_metadata.wire else {
2525-
log::error!("Could not load wire for input: {:?}", input);
2523+
log::error!("Could not load wire for input: {input:?}");
25262524
return None;
25272525
};
25282526
wire.clone()
25292527
}
25302528
InputConnector::Export(export_index) => {
25312529
let network_metadata = self.network_metadata(network_path)?;
25322530
let Some(TransientMetadata::Loaded(wire)) = network_metadata.transient_metadata.wires.get(*export_index) else {
2533-
log::error!("Could not load wire for input: {:?}", input);
2531+
log::error!("Could not load wire for input: {input:?}");
25342532
return None;
25352533
};
25362534
wire.clone()
@@ -2701,12 +2699,12 @@ impl NodeNetworkInterface {
27012699
return None;
27022700
}
27032701
let Some(input_position) = self.get_input_center(&input, network_path) else {
2704-
log::error!("Could not get dom rect for wire end in root node: {:?}", input);
2702+
log::error!("Could not get dom rect for wire end in root node: {input:?}");
27052703
return None;
27062704
};
27072705
let upstream_output = OutputConnector::node(root_node.node_id, root_node.output_index);
27082706
let Some(output_position) = self.get_output_center(&upstream_output, network_path) else {
2709-
log::error!("Could not get dom rect for wire start in root node: {:?}", upstream_output);
2707+
log::error!("Could not get dom rect for wire start in root node: {upstream_output:?}");
27102708
return None;
27112709
};
27122710
let vertical_end = input.node_id().is_some_and(|node_id| self.is_layer(&node_id, network_path) && input.input_index() == 0);
@@ -2733,15 +2731,15 @@ impl NodeNetworkInterface {
27332731
/// Returns the vector subpath and a boolean of whether the wire should be thick.
27342732
pub fn vector_wire_from_input(&mut self, input: &InputConnector, wire_style: GraphWireStyle, network_path: &[NodeId]) -> Option<(BezPath, bool)> {
27352733
let Some(input_position) = self.get_input_center(input, network_path) else {
2736-
log::error!("Could not get dom rect for wire end: {:?}", input);
2734+
log::error!("Could not get dom rect for wire end: {input:?}");
27372735
return None;
27382736
};
27392737
// An upstream output could not be found, so the wire does not exist, but it should still be loaded as as empty vector
27402738
let Some(upstream_output) = self.upstream_output_connector(input, network_path) else {
27412739
return Some((BezPath::new(), false));
27422740
};
27432741
let Some(output_position) = self.get_output_center(&upstream_output, network_path) else {
2744-
log::error!("Could not get dom rect for wire start: {:?}", upstream_output);
2742+
log::error!("Could not get dom rect for wire start: {upstream_output:?}");
27452743
return None;
27462744
};
27472745
let vertical_end = input.node_id().is_some_and(|node_id| self.is_layer(&node_id, network_path) && input.input_index() == 0);
@@ -3357,7 +3355,7 @@ impl NodeNetworkInterface {
33573355
self.selected_nodes()
33583356
.0
33593357
.iter()
3360-
.filter(|node| self.is_layer(&node, &[]))
3358+
.filter(|node| self.is_layer(node, &[]))
33613359
.filter_map(|layer| self.document_metadata.bounding_box_viewport(LayerNodeIdentifier::new(*layer, self)))
33623360
.reduce(Quad::combine_bounds)
33633361
}
@@ -3366,7 +3364,7 @@ impl NodeNetworkInterface {
33663364
self.selected_nodes()
33673365
.0
33683366
.iter()
3369-
.filter(|node| self.is_layer(&node, &[]) && !self.is_locked(&node, &[]))
3367+
.filter(|node| self.is_layer(node, &[]) && !self.is_locked(node, &[]))
33703368
.filter_map(|layer| self.document_metadata.bounding_box_viewport(LayerNodeIdentifier::new(*layer, self)))
33713369
.reduce(Quad::combine_bounds)
33723370
}
@@ -4138,7 +4136,7 @@ impl NodeNetworkInterface {
41384136
if let DocumentNodeImplementation::Network(network) = &node.implementation {
41394137
let number_of_exports = network.exports.len();
41404138
let Some(metadata) = self.node_metadata_mut(node_id, network_path) else {
4141-
log::error!("Could not get metadata for node: {:?}", node_id);
4139+
log::error!("Could not get metadata for node: {node_id:?}");
41424140
return;
41434141
};
41444142
metadata.persistent_metadata.output_names.resize(number_of_exports, "".to_string());

editor/src/messages/portfolio/document_migration.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,8 +1083,8 @@ mod tests {
10831083
*hashmap.entry(node.node.clone()).or_default() += 1;
10841084
});
10851085
let duplicates = hashmap.iter().filter(|(_, count)| **count > 1).map(|(node, _)| &node.name).collect::<Vec<_>>();
1086-
if duplicates.len() > 0 {
1087-
panic!("Duplicate entries in `NODE_REPLACEMENTS`: {:?}", duplicates);
1086+
if !duplicates.is_empty() {
1087+
panic!("Duplicate entries in `NODE_REPLACEMENTS`: {duplicates:?}");
10881088
}
10891089
}
10901090
}

0 commit comments

Comments
 (0)