Fix clippy warnings (#3085)

* Run clippy fix

* Clippy v2

* Make const item static

* Cargo fmt
This commit is contained in:
Dennis Kobert
2025-08-23 11:45:47 +02:00
committed by GitHub
parent c6ec3a27ca
commit 7377871106
47 changed files with 218 additions and 258 deletions

View File

@@ -249,7 +249,7 @@ struct Logger;
impl NodeGraphUpdateSender for Logger {
fn send(&self, message: NodeGraphUpdateMessage) {
log::warn!("dispatching message with fallback node graph update sender {:?}", message);
log::warn!("dispatching message with fallback node graph update sender {message:?}");
}
}

View File

@@ -1,7 +1,7 @@
mod color;
mod color_traits;
mod color_types;
mod discrete_srgb;
pub use color::*;
pub use color_traits::*;
pub use color_types::*;
pub use discrete_srgb::*;

View File

@@ -287,6 +287,6 @@ mod test {
fn display() {
let p = Polynomial::new([1., 2., 0., 3.]);
assert_eq!(format!("{:.2}", p), "3.00x^3 + 2.00x + 1.00");
assert_eq!(format!("{p:.2}"), "3.00x^3 + 2.00x + 1.00");
}
}

View File

@@ -50,6 +50,7 @@ impl<T, CachedNode> MemoNode<T, CachedNode> {
}
}
#[allow(clippy::module_inception)]
pub mod memo {
pub const IDENTIFIER: crate::ProtoNodeIdentifier = crate::ProtoNodeIdentifier::new("graphene_core::memo::MemoNode");
}

View File

@@ -258,7 +258,7 @@ pub fn migrate_image_frame<'de, D: serde::Deserializer<'de>>(deserializer: D) ->
GraphicElement::RasterFrame(RasterFrame::ImageFrame(image)) => Self {
image: image.iter().next().unwrap().element.clone(),
},
_ => panic!("Expected Image, found {:?}", element),
_ => panic!("Expected Image, found {element:?}"),
}
}
}
@@ -478,9 +478,9 @@ mod test {
};
let serialized = serde_json::to_string(&image).unwrap();
println!("{}", serialized);
println!("{serialized}");
let deserialized: Image<Color> = serde_json::from_str(&serialized).unwrap();
println!("{:?}", deserialized);
println!("{deserialized:?}");
assert_eq!(image, deserialized);
}

View File

@@ -234,7 +234,7 @@ where
};
match dyn_any::downcast(input) {
Ok(input) => Box::pin(output(*input)),
Err(e) => panic!("DynAnyNode Input, {0} in:\n{1}", e, node_name),
Err(e) => panic!("DynAnyNode Input, {e} in:\n{node_name}"),
}
}

View File

@@ -367,7 +367,7 @@ impl std::fmt::Debug for Type {
Self::Future(ty) => format!("{ty:?}"),
};
let result = result.replace("Option<Arc<OwnedContextImpl>>", "Context");
write!(f, "{}", result)
write!(f, "{result}")
}
}
@@ -380,6 +380,6 @@ impl std::fmt::Display for Type {
Type::Future(ty) => ty.to_string(),
};
let result = result.replace("Option<Arc<OwnedContextImpl>>", "Context");
write!(f, "{}", result)
write!(f, "{result}")
}
}

View File

@@ -60,8 +60,7 @@ impl<'i, T: 'i> Node<'i, ()> for RefCellMutNode<T> {
type Output = RefMut<'i, T>;
#[inline(always)]
fn eval(&'i self, _input: ()) -> Self::Output {
let a = self.0.borrow_mut();
a
self.0.borrow_mut()
}
}

View File

@@ -225,7 +225,7 @@ pub fn pathseg_find_tvalues_for_x(segment: PathSeg, x: f64) -> impl Iterator<Ite
let b = 2.0 * (p1.x - p0.x);
let c = p0.x - x;
let r = solve_quadratic(c, b, a);
[r.get(0).map(|t| *t), r.get(1).map(|t| *t), None]
[r.first().copied(), r.get(1).copied(), None]
}
PathSeg::Cubic(CubicBez { p0, p1, p2, p3 }) => {
let a = p3.x - 3.0 * p2.x + 3.0 * p1.x - p0.x;
@@ -233,7 +233,7 @@ pub fn pathseg_find_tvalues_for_x(segment: PathSeg, x: f64) -> impl Iterator<Ite
let c = 3.0 * (p1.x - p0.x);
let d = p0.x - x;
let r = solve_cubic(d, c, b, a);
[r.get(0).map(|t| *t), r.get(1).map(|t| *t), r.get(2).map(|t| *t)]
[r.first().copied(), r.get(1).copied(), r.get(2).copied()]
}
}
.into_iter()

View File

@@ -307,7 +307,7 @@ mod tests {
assert_eq!(bezier.handles, subpath::BezierHandles::Linear);
let vector = bezier.start - bezier.end;
let angle = (vector.angle_to(DVec2::X).to_degrees() + 180.) % 180.;
assert!([90., 150., 40.].into_iter().any(|target| (target - angle).abs() < 1e-10), "unexpected angle of {}", angle)
assert!([90., 150., 40.].into_iter().any(|target| (target - angle).abs() < 1e-10), "unexpected angle of {angle}")
}
}
}

View File

@@ -343,8 +343,8 @@ fn to_path_segments(path: &mut Vec<path_bool::PathSegment>, subpath: &Subpath<Po
let PathSegPoints { p0, p1, p2, p3 } = pathseg_points(bezier);
let p0 = transform_point(p0);
let p1 = p1.map(|p1| transform_point(p1));
let p2 = p2.map(|p2| transform_point(p2));
let p1 = p1.map(transform_point);
let p2 = p2.map(transform_point);
let p3 = transform_point(p3);
if global_start.is_none() {

View File

@@ -949,7 +949,7 @@ impl NodeNetwork {
for (nested_node_id, mut nested_node) in inner_network.nodes.into_iter() {
for (nested_input_index, nested_input) in nested_node.clone().inputs.iter().enumerate() {
if let NodeInput::Network { import_index, .. } = nested_input {
let parent_input = node.inputs.get(*import_index).unwrap_or_else(|| panic!("Import index {} should always exist", import_index));
let parent_input = node.inputs.get(*import_index).unwrap_or_else(|| panic!("Import index {import_index} should always exist"));
match *parent_input {
// If the input to self is a node, connect the corresponding output of the inner network to it
NodeInput::Node { node_id, output_index, lambda } => {

View File

@@ -301,13 +301,13 @@ impl TaggedValue {
"MAGENTA" => Color::MAGENTA,
"TRANSPARENT" => Color::TRANSPARENT,
_ => {
log::error!("Invalid default value color constant: {}", input);
log::error!("Invalid default value color constant: {input}");
return None;
}
});
}
log::error!("Invalid default value color: {}", input);
log::error!("Invalid default value color: {input}");
None
}
@@ -327,13 +327,13 @@ impl TaggedValue {
"BottomCenter" => ReferencePoint::BottomCenter,
"BottomRight" => ReferencePoint::BottomRight,
_ => {
log::error!("Invalid ReferencePoint default type variant: {}", input);
log::error!("Invalid ReferencePoint default type variant: {input}");
return None;
}
});
}
log::error!("Invalid ReferencePoint default type: {}", input);
log::error!("Invalid ReferencePoint default type: {input}");
None
}

View File

@@ -88,10 +88,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
}
let device = application_io.gpu_executor().unwrap().context.device.clone();
let preferences = EditorPreferences {
use_vello: true,
..Default::default()
};
let preferences = EditorPreferences { use_vello: true };
let editor_api = Arc::new(WasmEditorApi {
font_cache: FontCache::default(),
application_io: Some(application_io.into()),
@@ -104,7 +101,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
match app.command {
Command::Compile { print_proto, .. } => {
if print_proto {
println!("{}", proto_graph);
println!("{proto_graph}");
}
}
Command::Run { run_loop, .. } => {
@@ -120,7 +117,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
loop {
let result = (&executor).execute(render_config).await?;
if !run_loop {
println!("{:?}", result);
println!("{result:?}");
break;
}
tokio::time::sleep(std::time::Duration::from_millis(16)).await;

View File

@@ -1209,7 +1209,7 @@ impl Render for Table<Raster<CPU>> {
}
}
const LAZY_ARC_VEC_ZERO_U8: LazyLock<Arc<Vec<u8>>> = LazyLock::new(|| Arc::new(Vec::new()));
static LAZY_ARC_VEC_ZERO_U8: LazyLock<Arc<Vec<u8>>> = LazyLock::new(|| Arc::new(Vec::new()));
impl Render for Table<Raster<GPU>> {
fn render_svg(&self, _render: &mut SvgRender, _render_params: &RenderParams) {

View File

@@ -150,8 +150,8 @@ pub enum IntrospectError {
impl std::fmt::Display for IntrospectError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
IntrospectError::PathNotFound(path) => write!(f, "Path not found: {:?}", path),
IntrospectError::ProtoNodeNotFound(id) => write!(f, "ProtoNode not found: {:?}", id),
IntrospectError::PathNotFound(path) => write!(f, "Path not found: {path:?}"),
IntrospectError::ProtoNodeNotFound(id) => write!(f, "ProtoNode not found: {id:?}"),
IntrospectError::NoData => write!(f, "No data found for this node"),
IntrospectError::RuntimeNotReady => write!(f, "Node runtime is not ready"),
}

View File

@@ -293,7 +293,7 @@ pub(crate) fn generate_node_code(parsed: &ParsedNodeFn) -> syn::Result<TokenStre
let properties = &attributes.properties_string.as_ref().map(|value| quote!(Some(#value))).unwrap_or(quote!(None));
let cfg = crate::shader_nodes::modify_cfg(&attributes);
let cfg = crate::shader_nodes::modify_cfg(attributes);
let node_input_accessor = generate_node_input_references(parsed, fn_generics, &field_idents, &graphene_core, &identifier, &cfg);
Ok(quote! {
/// Underlying implementation for [#struct_name]
@@ -323,6 +323,7 @@ pub(crate) fn generate_node_code(parsed: &ParsedNodeFn) -> syn::Result<TokenStre
#cfg
#[doc(hidden)]
#[allow(clippy::module_inception)]
mod #mod_name {
use super::*;
use #graphene_core as gcore;

View File

@@ -117,7 +117,7 @@ fn derive_enum(enum_attributes: &[Attribute], name: Ident, input: syn::DataEnum)
.map_err(|e| {
syn::Error::new(
Span::call_site(),
format!("Failed to find location of 'graphene_core' or 'graphene-core-shaders'. Make sure it is imported as a dependency: {}", e),
format!("Failed to find location of 'graphene_core' or 'graphene-core-shaders'. Make sure it is imported as a dependency: {e}"),
)
})?;
match crate_name {

View File

@@ -295,8 +295,8 @@ impl Parse for NodeFnAttributes {
}
fn parse_node_fn(attr: TokenStream2, item: TokenStream2) -> syn::Result<ParsedNodeFn> {
let attributes = syn::parse2::<NodeFnAttributes>(attr.clone()).map_err(|e| Error::new(e.span(), format!("Failed to parse node_fn attributes: {}", e)))?;
let input_fn = syn::parse2::<ItemFn>(item.clone()).map_err(|e| Error::new(e.span(), format!("Failed to parse function: {}. Make sure it's a valid Rust function.", e)))?;
let attributes = syn::parse2::<NodeFnAttributes>(attr.clone()).map_err(|e| Error::new(e.span(), format!("Failed to parse node_fn attributes: {e}")))?;
let input_fn = syn::parse2::<ItemFn>(item.clone()).map_err(|e| Error::new(e.span(), format!("Failed to parse function: {e}. Make sure it's a valid Rust function.")))?;
let vis = input_fn.vis;
let fn_name = input_fn.sig.ident.clone();
@@ -312,7 +312,7 @@ fn parse_node_fn(attr: TokenStream2, item: TokenStream2) -> syn::Result<ParsedNo
let crate_name = proc_macro_crate::crate_name("graphene-core").map_err(|e| {
Error::new(
proc_macro2::Span::call_site(),
format!("Failed to find location of graphene_core. Make sure it is imported as a dependency: {}", e),
format!("Failed to find location of graphene_core. Make sure it is imported as a dependency: {e}"),
)
})?;
let description = input_fn
@@ -405,7 +405,7 @@ fn parse_implementations(attr: &Attribute, name: &Ident) -> syn::Result<Punctuat
let parser = Punctuated::<Type, Comma>::parse_terminated;
parser.parse2(content.clone()).map_err(|e| {
let span = e.span(); // Get the span of the error
Error::new(span, format!("Failed to parse implementations for argument '{}': {}", name, e))
Error::new(span, format!("Failed to parse implementations for argument '{name}': {e}"))
})
}
@@ -431,27 +431,21 @@ fn parse_field(pat_ident: PatIdent, ty: Type, attrs: &[Attribute]) -> syn::Resul
let ident = &pat_ident.ident;
let default_value = extract_attribute(attrs, "default")
.map(|attr| {
attr.parse_args()
.map_err(|e| Error::new_spanned(attr, format!("Invalid `default` value for argument '{}': {}", ident, e)))
})
.map(|attr| attr.parse_args().map_err(|e| Error::new_spanned(attr, format!("Invalid `default` value for argument '{ident}': {e}"))))
.transpose()?;
let scope = extract_attribute(attrs, "scope")
.map(|attr| {
attr.parse_args()
.map_err(|e| Error::new_spanned(attr, format!("Invalid `scope` value for argument '{}': {}", ident, e)))
})
.map(|attr| attr.parse_args().map_err(|e| Error::new_spanned(attr, format!("Invalid `scope` value for argument '{ident}': {e}"))))
.transpose()?;
let name = extract_attribute(attrs, "name")
.map(|attr| attr.parse_args().map_err(|e| Error::new_spanned(attr, format!("Invalid `name` value for argument '{}': {}", ident, e))))
.map(|attr| attr.parse_args().map_err(|e| Error::new_spanned(attr, format!("Invalid `name` value for argument '{ident}': {e}"))))
.transpose()?;
let widget_override = extract_attribute(attrs, "widget")
.map(|attr| {
attr.parse_args()
.map_err(|e| Error::new_spanned(attr, format!("Invalid `widget override` value for argument '{}': {}", ident, e)))
.map_err(|e| Error::new_spanned(attr, format!("Invalid `widget override` value for argument '{ident}': {e}")))
})
.transpose()?
.unwrap_or_default();
@@ -468,26 +462,26 @@ fn parse_field(pat_ident: PatIdent, ty: Type, attrs: &[Attribute]) -> syn::Resul
let number_soft_min = extract_attribute(attrs, "soft_min")
.map(|attr| {
attr.parse_args()
.map_err(|e| Error::new_spanned(attr, format!("Invalid numerical `soft_min` value for argument '{}': {}", ident, e)))
.map_err(|e| Error::new_spanned(attr, format!("Invalid numerical `soft_min` value for argument '{ident}': {e}")))
})
.transpose()?;
let number_soft_max = extract_attribute(attrs, "soft_max")
.map(|attr| {
attr.parse_args()
.map_err(|e| Error::new_spanned(attr, format!("Invalid numerical `soft_max` value for argument '{}': {}", ident, e)))
.map_err(|e| Error::new_spanned(attr, format!("Invalid numerical `soft_max` value for argument '{ident}': {e}")))
})
.transpose()?;
let number_hard_min = extract_attribute(attrs, "hard_min")
.map(|attr| {
attr.parse_args()
.map_err(|e| Error::new_spanned(attr, format!("Invalid numerical `hard_min` value for argument '{}': {}", ident, e)))
.map_err(|e| Error::new_spanned(attr, format!("Invalid numerical `hard_min` value for argument '{ident}': {e}")))
})
.transpose()?;
let number_hard_max = extract_attribute(attrs, "hard_max")
.map(|attr| {
attr.parse_args()
.map_err(|e| Error::new_spanned(attr, format!("Invalid numerical `hard_max` value for argument '{}': {}", ident, e)))
.map_err(|e| Error::new_spanned(attr, format!("Invalid numerical `hard_max` value for argument '{ident}': {e}")))
})
.transpose()?;
@@ -496,10 +490,7 @@ fn parse_field(pat_ident: PatIdent, ty: Type, attrs: &[Attribute]) -> syn::Resul
attr.parse_args::<ExprTuple>().map_err(|e| {
Error::new_spanned(
attr,
format!(
"Invalid `range` tuple of min and max range slider values for argument '{}': {}\nUSAGE EXAMPLE: #[range((0., 100.))]",
ident, e
),
format!("Invalid `range` tuple of min and max range slider values for argument '{ident}': {e}\nUSAGE EXAMPLE: #[range((0., 100.))]"),
)
})
})
@@ -511,7 +502,7 @@ fn parse_field(pat_ident: PatIdent, ty: Type, attrs: &[Attribute]) -> syn::Resul
}
let unit = extract_attribute(attrs, "unit")
.map(|attr| attr.parse_args::<LitStr>().map_err(|_e| Error::new_spanned(attr, format!("Expected a unit type as string"))))
.map(|attr| attr.parse_args::<LitStr>().map_err(|_e| Error::new_spanned(attr, "Expected a unit type as string".to_string())))
.transpose()?;
let number_display_decimal_places = extract_attribute(attrs, "display_decimal_places")
@@ -519,14 +510,14 @@ fn parse_field(pat_ident: PatIdent, ty: Type, attrs: &[Attribute]) -> syn::Resul
attr.parse_args::<LitInt>().map_err(|e| {
Error::new_spanned(
attr,
format!("Invalid `integer` for number of decimals for argument '{}': {}\nUSAGE EXAMPLE: #[display_decimal_places(2)]", ident, e),
format!("Invalid `integer` for number of decimals for argument '{ident}': {e}\nUSAGE EXAMPLE: #[display_decimal_places(2)]"),
)
})
})
.transpose()?
.map(|f| {
if let Err(e) = f.base10_parse::<u32>() {
Err(Error::new_spanned(f, format!("Expected a `u32` for `display_decimal_places` for '{}': {}", ident, e)))
Err(Error::new_spanned(f, format!("Expected a `u32` for `display_decimal_places` for '{ident}': {e}")))
} else {
Ok(f)
}
@@ -535,7 +526,7 @@ fn parse_field(pat_ident: PatIdent, ty: Type, attrs: &[Attribute]) -> syn::Resul
let number_step = extract_attribute(attrs, "step")
.map(|attr| {
attr.parse_args::<LitFloat>()
.map_err(|e| Error::new_spanned(attr, format!("Invalid `step` for argument '{}': {}\nUSAGE EXAMPLE: #[step(2.)]", ident, e)))
.map_err(|e| Error::new_spanned(attr, format!("Invalid `step` for argument '{ident}': {e}\nUSAGE EXAMPLE: #[step(2.)]")))
})
.transpose()?;
@@ -660,7 +651,7 @@ pub fn new_node_fn(attr: TokenStream2, item: TokenStream2) -> TokenStream2 {
Ok(parsed) => parsed,
Err(e) => {
// Return the error as a compile error
Error::new(e.span(), format!("Failed to parse node function: {}", e)).to_compile_error()
Error::new(e.span(), format!("Failed to parse node function: {e}")).to_compile_error()
}
}
}
@@ -757,7 +748,7 @@ mod tests {
}
_ => panic!("Mismatched default values"),
}
assert_eq!(format!("{:?}", p_ty), format!("{:?}", e_ty));
assert_eq!(format!("{p_ty:?}"), format!("{:?}", e_ty));
}
(
ParsedField {
@@ -780,8 +771,8 @@ mod tests {
},
) => {
assert_eq!(p_name, e_name);
assert_eq!(format!("{:?}", p_input), format!("{:?}", e_input));
assert_eq!(format!("{:?}", p_output), format!("{:?}", e_output));
assert_eq!(format!("{p_input:?}"), format!("{:?}", e_input));
assert_eq!(format!("{p_output:?}"), format!("{:?}", e_output));
}
_ => panic!("Mismatched field types"),
}

View File

@@ -108,7 +108,7 @@ pub fn generate_node_substitutions() -> HashMap<ProtoNodeIdentifier, DocumentNod
let document_node = DocumentNode {
inputs: network_inputs,
manual_composition: Some(input_type.clone()),
implementation: DocumentNodeImplementation::ProtoNode(id.clone().into()),
implementation: DocumentNodeImplementation::ProtoNode(id.clone()),
visible: true,
skip_deduplication: false,
..Default::default()