mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-16 06:38:03 +08:00
Fix assorted Clippy lints (#3390)
This commit is contained in:
@@ -686,10 +686,10 @@ impl NodeNetwork {
|
||||
fn replace_node_inputs(&mut self, node_id: NodeId, old_input: (NodeId, usize), new_input: (NodeId, usize)) {
|
||||
let Some(node) = self.nodes.get_mut(&node_id) else { return };
|
||||
node.inputs.iter_mut().for_each(|input| {
|
||||
if let NodeInput::Node { node_id: input_id, output_index, .. } = input {
|
||||
if (*input_id, *output_index) == old_input {
|
||||
(*input_id, *output_index) = new_input;
|
||||
}
|
||||
if let NodeInput::Node { node_id: input_id, output_index, .. } = input
|
||||
&& (*input_id, *output_index) == old_input
|
||||
{
|
||||
(*input_id, *output_index) = new_input;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -738,10 +738,10 @@ impl NodeNetwork {
|
||||
let mut are_inputs_used = vec![false; number_of_inputs];
|
||||
for node in &self.nodes {
|
||||
for node_input in &node.1.inputs {
|
||||
if let NodeInput::Import { import_index, .. } = node_input {
|
||||
if let Some(is_used) = are_inputs_used.get_mut(*import_index) {
|
||||
*is_used = true;
|
||||
}
|
||||
if let NodeInput::Import { import_index, .. } = node_input
|
||||
&& let Some(is_used) = are_inputs_used.get_mut(*import_index)
|
||||
{
|
||||
*is_used = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -937,50 +937,48 @@ impl NodeNetwork {
|
||||
|
||||
fn remove_id_node(&mut self, id: NodeId) -> Result<(), String> {
|
||||
let node = self.nodes.get(&id).ok_or_else(|| format!("Node with id {id} does not exist"))?.clone();
|
||||
if let DocumentNodeImplementation::ProtoNode(ident) = &node.implementation {
|
||||
if ident.name == "graphene_core::ops::IdentityNode" {
|
||||
assert_eq!(node.inputs.len(), 1, "Id node has more than one input");
|
||||
if let NodeInput::Node { node_id, output_index, .. } = node.inputs[0] {
|
||||
let node_input_output_index = output_index;
|
||||
// TODO fix
|
||||
if let Some(input_node) = self.nodes.get_mut(&node_id) {
|
||||
for &dep in &node.original_location.dependants[0] {
|
||||
input_node.original_location.dependants[output_index].push(dep);
|
||||
if let DocumentNodeImplementation::ProtoNode(ident) = &node.implementation
|
||||
&& *ident == graphene_core::ops::identity::IDENTIFIER
|
||||
{
|
||||
assert_eq!(node.inputs.len(), 1, "Id node has more than one input");
|
||||
if let NodeInput::Node { node_id, output_index, .. } = node.inputs[0] {
|
||||
let node_input_output_index = output_index;
|
||||
// TODO fix
|
||||
if let Some(input_node) = self.nodes.get_mut(&node_id) {
|
||||
for &dep in &node.original_location.dependants[0] {
|
||||
input_node.original_location.dependants[output_index].push(dep);
|
||||
}
|
||||
}
|
||||
|
||||
let input_node_id = node_id;
|
||||
for output in self.nodes.values_mut() {
|
||||
for (index, input) in output.inputs.iter_mut().enumerate() {
|
||||
if let NodeInput::Node {
|
||||
node_id: output_node_id,
|
||||
output_index: output_output_index,
|
||||
..
|
||||
} = input && *output_node_id == id
|
||||
{
|
||||
*output_node_id = input_node_id;
|
||||
*output_output_index = node_input_output_index;
|
||||
|
||||
let input_source = &mut output.original_location.inputs_source;
|
||||
for source in node.original_location.inputs(index) {
|
||||
input_source.insert(source, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let input_node_id = node_id;
|
||||
for output in self.nodes.values_mut() {
|
||||
for (index, input) in output.inputs.iter_mut().enumerate() {
|
||||
if let NodeInput::Node {
|
||||
node_id: output_node_id,
|
||||
output_index: output_output_index,
|
||||
..
|
||||
} = input
|
||||
{
|
||||
if *output_node_id == id {
|
||||
*output_node_id = input_node_id;
|
||||
*output_output_index = node_input_output_index;
|
||||
|
||||
let input_source = &mut output.original_location.inputs_source;
|
||||
for source in node.original_location.inputs(index) {
|
||||
input_source.insert(source, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for node_input in self.exports.iter_mut() {
|
||||
if let NodeInput::Node { node_id, output_index, .. } = node_input {
|
||||
if *node_id == id {
|
||||
*node_id = input_node_id;
|
||||
*output_index = node_input_output_index;
|
||||
}
|
||||
}
|
||||
for node_input in self.exports.iter_mut() {
|
||||
if let NodeInput::Node { node_id, output_index, .. } = node_input
|
||||
&& *node_id == id
|
||||
{
|
||||
*node_id = input_node_id;
|
||||
*output_index = node_input_output_index;
|
||||
}
|
||||
}
|
||||
}
|
||||
self.nodes.remove(&id);
|
||||
}
|
||||
self.nodes.remove(&id);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -1047,15 +1045,15 @@ impl NodeNetwork {
|
||||
let nodes: Vec<_> = self.nodes.into_iter().map(|(id, node)| (id, node.resolve_proto_node())).collect();
|
||||
|
||||
// Create a network to evaluate each output
|
||||
if self.exports.len() == 1 {
|
||||
if let NodeInput::Node { node_id, .. } = self.exports[0] {
|
||||
return vec![ProtoNetwork {
|
||||
inputs: Vec::new(),
|
||||
output: node_id,
|
||||
nodes,
|
||||
}]
|
||||
.into_iter();
|
||||
}
|
||||
if self.exports.len() == 1
|
||||
&& let NodeInput::Node { node_id, .. } = self.exports[0]
|
||||
{
|
||||
return vec![ProtoNetwork {
|
||||
inputs: Vec::new(),
|
||||
output: node_id,
|
||||
nodes,
|
||||
}]
|
||||
.into_iter();
|
||||
}
|
||||
|
||||
// Create a network to evaluate each output
|
||||
|
||||
@@ -308,10 +308,10 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
|
||||
let mut new_name = id.name.replace('\n', " ");
|
||||
|
||||
// Remove struct generics for all nodes except for the IntoNode and ConvertNode
|
||||
if !(new_name.contains("IntoNode") || new_name.contains("ConvertNode")) {
|
||||
if let Some((path, _generics)) = new_name.split_once("<") {
|
||||
new_name = path.to_string();
|
||||
}
|
||||
if !(new_name.contains("IntoNode") || new_name.contains("ConvertNode"))
|
||||
&& let Some((path, _generics)) = new_name.split_once("<")
|
||||
{
|
||||
new_name = path.to_string();
|
||||
}
|
||||
|
||||
let nid = ProtoNodeIdentifier { name: Cow::Owned(new_name) };
|
||||
|
||||
@@ -50,14 +50,12 @@ impl BasicItem {
|
||||
let token: LitStr = attribute.parse_args()?;
|
||||
self.icon = Some(token.value());
|
||||
}
|
||||
if attribute.path().is_ident("doc") {
|
||||
if let Meta::NameValue(meta_name_value) = &attribute.meta {
|
||||
if let Expr::Lit(el) = &meta_name_value.value {
|
||||
if let syn::Lit::Str(token) = &el.lit {
|
||||
self.description = Some(token.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
if attribute.path().is_ident("doc")
|
||||
&& let Meta::NameValue(meta_name_value) = &attribute.meta
|
||||
&& let Expr::Lit(el) = &meta_name_value.value
|
||||
&& let syn::Lit::Str(token) = &el.lit
|
||||
{
|
||||
self.description = Some(token.value());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -530,10 +530,10 @@ fn parse_field(pat_ident: PatIdent, ty: Type, attrs: &[Attribute]) -> syn::Resul
|
||||
})
|
||||
})
|
||||
.transpose()?;
|
||||
if let Some(range) = &number_mode_range {
|
||||
if range.elems.len() != 2 {
|
||||
return Err(Error::new_spanned(range, "Expected a tuple of two values for `range` for the min and max, respectively"));
|
||||
}
|
||||
if let Some(range) = &number_mode_range
|
||||
&& range.elems.len() != 2
|
||||
{
|
||||
return Err(Error::new_spanned(range, "Expected a tuple of two values for `range` for the min and max, respectively"));
|
||||
}
|
||||
|
||||
let unit = extract_attribute(attrs, "unit")
|
||||
@@ -641,20 +641,19 @@ fn parse_field(pat_ident: PatIdent, ty: Type, attrs: &[Attribute]) -> syn::Resul
|
||||
fn parse_node_type(ty: &Type) -> (bool, Option<Type>, Option<Type>) {
|
||||
if let Type::ImplTrait(impl_trait) = ty {
|
||||
for bound in &impl_trait.bounds {
|
||||
if let syn::TypeParamBound::Trait(trait_bound) = bound {
|
||||
if trait_bound.path.segments.last().is_some_and(|seg| seg.ident == "Node") {
|
||||
if let syn::PathArguments::AngleBracketed(args) = &trait_bound.path.segments.last().unwrap().arguments {
|
||||
let input_type = args.args.iter().find_map(|arg| if let syn::GenericArgument::Type(ty) = arg { Some(ty.clone()) } else { None });
|
||||
let output_type = args.args.iter().find_map(|arg| {
|
||||
if let syn::GenericArgument::AssocType(assoc_type) = arg {
|
||||
if assoc_type.ident == "Output" { Some(assoc_type.ty.clone()) } else { None }
|
||||
} else {
|
||||
None
|
||||
}
|
||||
});
|
||||
return (true, input_type, output_type);
|
||||
if let syn::TypeParamBound::Trait(trait_bound) = bound
|
||||
&& trait_bound.path.segments.last().is_some_and(|seg| seg.ident == "Node")
|
||||
&& let syn::PathArguments::AngleBracketed(args) = &trait_bound.path.segments.last().unwrap().arguments
|
||||
{
|
||||
let input_type = args.args.iter().find_map(|arg| if let syn::GenericArgument::Type(ty) = arg { Some(ty.clone()) } else { None });
|
||||
let output_type = args.args.iter().find_map(|arg| {
|
||||
if let syn::GenericArgument::AssocType(assoc_type) = arg {
|
||||
if assoc_type.ident == "Output" { Some(assoc_type.ty.clone()) } else { None }
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
});
|
||||
return (true, input_type, output_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user