Skip to content

Commit

Permalink
Fix clippy lints (GraphiteEditor#2119)
Browse files Browse the repository at this point in the history
  • Loading branch information
0HyperCube authored Nov 29, 2024
1 parent 0062957 commit e3bb11e
Show file tree
Hide file tree
Showing 32 changed files with 682 additions and 444 deletions.
1,011 changes: 622 additions & 389 deletions Cargo.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ struct BitVectorIter<'a, const LENGTH: usize> {
iter_index: usize,
}

impl<'a, const LENGTH: usize> Iterator for BitVectorIter<'a, LENGTH> {
impl<const LENGTH: usize> Iterator for BitVectorIter<'_, LENGTH> {
type Item = usize;

fn next(&mut self) -> Option<Self::Item> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2144,7 +2144,7 @@ impl<'a> ClickXRayIter<'a> {
};
let get_clip = || path.iter().map(segment);

let intersects = click_targets.map_or(false, |targets| targets.iter().any(|target| target.intersect_path(get_clip, transform)));
let intersects = click_targets.is_some_and(|targets| targets.iter().any(|target| target.intersect_path(get_clip, transform)));
let clicked = intersects;
let mut use_children = !clip || intersects;

Expand Down Expand Up @@ -2179,7 +2179,7 @@ impl<'a> ClickXRayIter<'a> {
match target {
// Single points are much cheaper than paths so have their own special case
XRayTarget::Point(point) => {
let intersects = click_targets.map_or(false, |targets| targets.iter().any(|target| target.intersect_point(*point, transform)));
let intersects = click_targets.is_some_and(|targets| targets.iter().any(|target| target.intersect_point(*point, transform)));
XRayResult {
clicked: intersects,
use_children: !clip || intersects,
Expand Down Expand Up @@ -2256,7 +2256,7 @@ pub fn navigation_controls(ptz: &PTZ, navigation_handler: &NavigationMessageHand
]
}

impl<'a> Iterator for ClickXRayIter<'a> {
impl Iterator for ClickXRayIter<'_> {
type Item = LayerNodeIdentifier;

fn next(&mut self) -> Option<Self::Item> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::messages::prelude::*;
#[derive(Debug, Clone, Default)]
pub struct PropertiesPanelMessageHandler {}

impl<'a> MessageHandler<PropertiesPanelMessage, (&PersistentData, PropertiesPanelMessageHandlerData<'a>)> for PropertiesPanelMessageHandler {
impl MessageHandler<PropertiesPanelMessage, (&PersistentData, PropertiesPanelMessageHandlerData<'_>)> for PropertiesPanelMessageHandler {
fn process_message(&mut self, message: PropertiesPanelMessage, responses: &mut VecDeque<Message>, (persistent_data, data): (&PersistentData, PropertiesPanelMessageHandlerData)) {
let PropertiesPanelMessageHandlerData {
network_interface,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ pub struct AxisIter<'a> {
pub metadata: &'a DocumentMetadata,
}

impl<'a> Iterator for AxisIter<'a> {
impl Iterator for AxisIter<'_> {
type Item = LayerNodeIdentifier;

fn next(&mut self) -> Option<Self::Item> {
Expand All @@ -417,7 +417,7 @@ pub struct DescendantsIter<'a> {
metadata: &'a DocumentMetadata,
}

impl<'a> Iterator for DescendantsIter<'a> {
impl Iterator for DescendantsIter<'_> {
type Item = LayerNodeIdentifier;

fn next(&mut self) -> Option<Self::Item> {
Expand All @@ -435,7 +435,7 @@ impl<'a> Iterator for DescendantsIter<'a> {
}
}
}
impl<'a> DoubleEndedIterator for DescendantsIter<'a> {
impl DoubleEndedIterator for DescendantsIter<'_> {
fn next_back(&mut self) -> Option<Self::Item> {
if self.front == self.back {
self.front = None;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1534,7 +1534,7 @@ impl NodeNetworkInterface {
Some(parent_metadata)
}

/// Mutably get the node which encapsulates the currently viewed network. Will always be None in the document network.
// /// Mutably get the node which encapsulates the currently viewed network. Will always be None in the document network.
// fn encapsulating_node_mut(&mut self, network_path: &[NodeId]) -> Option<&mut DocumentNode> {
// let mut encapsulating_path = network_path.to_vec();
// let encapsulating_node_id = encapsulating_path.pop()?;
Expand Down Expand Up @@ -3887,7 +3887,7 @@ impl NodeNetworkInterface {
network_metadata.persistent_metadata.previewing = Previewing::No;
}

/// Sets the root node only if a node is being previewed
// /// Sets the root node only if a node is being previewed
// pub fn update_root_node(&mut self, node_id: NodeId, output_index: usize) {
// if let Previewing::Yes { root_node_to_restore } = self.previewing {
// // Only continue previewing if the new root node is not the same as the primary export. If it is the same, end the preview
Expand Down Expand Up @@ -5148,14 +5148,13 @@ pub enum FlowType {
/// - [`FlowType::PrimaryFlow`]: iterates along the horizontal inputs of nodes, so in the case of a node chain `a -> b -> c`, this would yield `c, b, a` if we started from `c`.
/// - [`FlowType::HorizontalFlow`]: iterates over the secondary input for layer nodes and primary input for non layer nodes.
/// - [`FlowType::LayerChildrenUpstreamFlow`]: iterates over all upstream nodes from the secondary input of the node.
struct FlowIter<'a> {
stack: Vec<NodeId>,
network: &'a NodeNetwork,
network_metadata: &'a NodeNetworkMetadata,
flow_type: FlowType,
}
impl<'a> Iterator for FlowIter<'a> {
impl Iterator for FlowIter<'_> {
type Item = NodeId;
fn next(&mut self) -> Option<Self::Item> {
loop {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ impl ShapeState {
.selected_shape_state
.iter()
.map(|(&layer, selection_state)| (network_interface.compute_modified_vector(layer), selection_state))
.flat_map(|(data, selection_state)| selection_state.selected_points.iter().map(move |&point| data.as_ref().map_or(false, |data| data.colinear(point))));
.flat_map(|(data, selection_state)| selection_state.selected_points.iter().map(move |&point| data.as_ref().is_some_and(|data| data.colinear(point))));

let Some(first_is_colinear) = points_colinear_status.next() else { return ManipulatorAngle::Mixed };
if points_colinear_status.any(|point| first_is_colinear != point) {
Expand Down
2 changes: 1 addition & 1 deletion editor/src/messages/tool/tool_messages/gradient_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ impl Fsm for GradientToolFsmState {
let Some(gradient) = get_gradient(layer, &document.network_interface) else { continue };
let transform = gradient_space_transform(layer, document);
let dragging = selected
.filter(|selected| selected.layer.map_or(false, |selected_layer| selected_layer == layer))
.filter(|selected| selected.layer.is_some_and(|selected_layer| selected_layer == layer))
.map(|selected| selected.dragging);

let Gradient { start, end, stops, .. } = gradient;
Expand Down
2 changes: 1 addition & 1 deletion editor/src/messages/tool/tool_messages/path_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ impl PathToolData {
// Check if the toggle_colinear key has just been pressed
if toggle_colinear && !self.toggle_colinear_debounce {
self.opposing_handle_lengths = None;
let colinear = self.selection_status.angle().map_or(false, |angle| match angle {
let colinear = self.selection_status.angle().is_some_and(|angle| match angle {
ManipulatorAngle::Colinear => true,
ManipulatorAngle::Free => false,
ManipulatorAngle::Mixed => false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl TransformLayerMessageHandler {
}

type TransformData<'a> = (&'a DocumentMessageHandler, &'a InputPreprocessorMessageHandler, &'a ToolData, &'a mut ShapeState);
impl<'a> MessageHandler<TransformLayerMessage, TransformData<'a>> for TransformLayerMessageHandler {
impl MessageHandler<TransformLayerMessage, TransformData<'_>> for TransformLayerMessageHandler {
fn process_message(&mut self, message: TransformLayerMessage, responses: &mut VecDeque<Message>, (document, input, tool_data, shape_editor): TransformData) {
let using_path_tool = tool_data.active_tool_type == ToolType::Path;

Expand Down
3 changes: 3 additions & 0 deletions frontend/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,6 @@ wasm-opt = ["-Os", "-g"]
debug-js-glue = true
demangle-name-section = true
dwarf-debug-info = true

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(wasm_bindgen_unstable_test_coverage)'] }
4 changes: 2 additions & 2 deletions frontend/wasm/src/editor_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ use std::sync::atomic::Ordering;
use std::time::Duration;
use wasm_bindgen::prelude::*;

/// We directly interface with the updateImage JS function for massively increased performance over serializing and deserializing.
/// This avoids creating a json with a list millions of numbers long.
// /// We directly interface with the updateImage JS function for massively increased performance over serializing and deserializing.
// /// This avoids creating a json with a list millions of numbers long.
// #[wasm_bindgen(module = "/../src/wasm-communication/editor.ts")]
// extern "C" {
// // fn dispatchTauri(message: String) -> String;
Expand Down
2 changes: 1 addition & 1 deletion libraries/bezier-rs/src/symmetrical_basis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl SymmetricalBasis {
}

// https://gitlab.com/inkscape/lib2geom/-/blob/master/src/2geom/sbasis.cpp#L228
impl<'a> std::ops::Mul for &'a SymmetricalBasis {
impl std::ops::Mul for &SymmetricalBasis {
type Output = SymmetricalBasis;
fn mul(self, b: Self) -> Self::Output {
let a = self;
Expand Down
1 change: 0 additions & 1 deletion libraries/dyn-any/derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ use syn::{parse_macro_input, DeriveInput, GenericParam, Lifetime, LifetimeParam,
/// // }
///
/// ```
#[proc_macro_derive(DynAny, attributes(dyn_any_derive))]
pub fn system_desc_derive(input: TokenStream) -> TokenStream {
let ast = parse_macro_input!(input as DeriveInput);
Expand Down
6 changes: 3 additions & 3 deletions libraries/dyn-any/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ macro_rules! impl_type {
}

#[cfg(feature = "alloc")]
unsafe impl<'a, T: StaticTypeClone + Clone> StaticType for Cow<'a, T> {
unsafe impl<T: StaticTypeClone + Clone> StaticType for Cow<'_, T> {
type Static = Cow<'static, <T as StaticTypeClone>::Static>;
}
unsafe impl<T: StaticTypeSized> StaticType for *const [T] {
Expand Down Expand Up @@ -173,11 +173,11 @@ mod slice {
}

#[cfg(feature = "alloc")]
unsafe impl<'a, T: StaticTypeSized> StaticType for Box<dyn Iterator<Item = T> + 'a + Send + Sync> {
unsafe impl<T: StaticTypeSized> StaticType for Box<dyn Iterator<Item = T> + '_ + Send + Sync> {
type Static = Box<dyn Iterator<Item = <T as StaticTypeSized>::Static> + Send + Sync>;
}

unsafe impl<'a> StaticType for &'a str {
unsafe impl StaticType for &str {
type Static = &'static str;
}
unsafe impl StaticType for () {
Expand Down
4 changes: 2 additions & 2 deletions libraries/math-parser/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ macro_rules! generate_benchmarks {
$(
c.bench_function(concat!("parse ", $input), |b| {
b.iter(|| {
let _ = black_box(ast::Node::from_str($input)).unwrap();
let _ = black_box(ast::Node::try_parse_from_str($input)).unwrap();
});
});
)*
}

fn evaluation_bench(c: &mut Criterion) {
$(
let expr = ast::Node::from_str($input).unwrap().0;
let expr = ast::Node::try_parse_from_str($input).unwrap().0;
let context = EvalContext::default();

c.bench_function(concat!("eval ", $input), |b| {
Expand Down
5 changes: 3 additions & 2 deletions libraries/math-parser/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ use lazy_static::lazy_static;
use num_complex::{Complex, ComplexFloat};

use crate::value::{Number, Value};
type FunctionImplementation = Box<dyn Fn(&[Value]) -> Option<Value> + Send + Sync>;
lazy_static! {
pub static ref DEFAULT_FUNCTIONS: HashMap<&'static str, Box<dyn Fn(&[Value]) -> Option<Value> + Send + Sync>> = {
let mut map: HashMap<&'static str, Box<dyn Fn(&[Value]) -> Option<Value> + Send + Sync>> = HashMap::new();
pub static ref DEFAULT_FUNCTIONS: HashMap<&'static str, FunctionImplementation> = {
let mut map: HashMap<&'static str, FunctionImplementation> = HashMap::new();

map.insert(
"sin",
Expand Down
4 changes: 2 additions & 2 deletions libraries/math-parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use parser::ParseError;
use value::Value;

pub fn evaluate(expression: &str) -> Result<(Result<Value, EvalError>, Unit), ParseError> {
let expr = ast::Node::from_str(expression);
let expr = ast::Node::try_parse_from_str(expression);
let context = EvalContext::default();
expr.map(|(node, unit)| (node.eval(&context), unit))
}
Expand All @@ -37,7 +37,7 @@ mod tests {
let expected_value = $expected_value;
let expected_unit = $expected_unit;

let expr = ast::Node::from_str($input);
let expr = ast::Node::try_parse_from_str($input);
let context = EvalContext::default();

let (actual_value, actual_unit) = expr.map(|(node, unit)| (node.eval(&context), unit)).unwrap();
Expand Down
6 changes: 3 additions & 3 deletions libraries/math-parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub enum ParseError {
}

impl Node {
pub fn from_str(s: &str) -> Result<(Node, Unit), ParseError> {
pub fn try_parse_from_str(s: &str) -> Result<(Node, Unit), ParseError> {
let pairs = ExprParser::parse(Rule::program, s).map_err(Box::new)?;
let (node, metadata) = parse_expr(pairs)?;
Ok((node, metadata.unit))
Expand Down Expand Up @@ -325,7 +325,7 @@ mod tests {
$(
#[test]
fn $name() {
let result = Node::from_str($input).unwrap();
let result = Node::try_parse_from_str($input).unwrap();
assert_eq!(result.0, $expected);
}
)*
Expand All @@ -334,7 +334,7 @@ mod tests {

test_parser! {
test_parse_int_literal: "42" => Node::Lit(Literal::Float(42.0)),
test_parse_float_literal: "3.14" => Node::Lit(Literal::Float(3.14)),
test_parse_float_literal: "3.14" => Node::Lit(Literal::Float(#[allow(clippy::approx_constant)] 3.14)),
test_parse_ident: "x" => Node::Var("x".to_string()),
test_parse_unary_neg: "-42" => Node::UnaryOp {
expr: Box::new(Node::Lit(Literal::Float(42.0))),
Expand Down
2 changes: 1 addition & 1 deletion node-graph/gcore/src/graphic_element/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ impl RenderSvgSegmentList for Vec<SvgSegment> {

pub struct SvgRenderAttrs<'a>(&'a mut SvgRender);

impl<'a> SvgRenderAttrs<'a> {
impl SvgRenderAttrs<'_> {
pub fn push_complex(&mut self, name: impl Into<SvgSegment>, value: impl FnOnce(&mut SvgRender)) {
self.0.svg.push(" ".into());
self.0.svg.push(name.into());
Expand Down
6 changes: 3 additions & 3 deletions node-graph/gcore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,21 +125,21 @@ where
{
}

impl<'i, 's: 'i, I: 'i, N: Node<'i, I> + ?Sized> Node<'i, I> for &'i N {
impl<'i, I: 'i, N: Node<'i, I> + ?Sized> Node<'i, I> for &'i N {
type Output = N::Output;
fn eval(&'i self, input: I) -> N::Output {
(*self).eval(input)
}
}
#[cfg(feature = "alloc")]
impl<'i, 's: 'i, I: 'i, O: 'i, N: Node<'i, I, Output = O> + ?Sized> Node<'i, I> for Box<N> {
impl<'i, I: 'i, O: 'i, N: Node<'i, I, Output = O> + ?Sized> Node<'i, I> for Box<N> {
type Output = O;
fn eval(&'i self, input: I) -> O {
(**self).eval(input)
}
}
#[cfg(feature = "alloc")]
impl<'i, 's: 'i, I: 'i, O: 'i, N: Node<'i, I, Output = O> + ?Sized> Node<'i, I> for alloc::sync::Arc<N> {
impl<'i, I: 'i, O: 'i, N: Node<'i, I, Output = O> + ?Sized> Node<'i, I> for alloc::sync::Arc<N> {
type Output = O;
fn eval(&'i self, input: I) -> O {
(**self).eval(input)
Expand Down
10 changes: 5 additions & 5 deletions node-graph/gcore/src/memo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct MemoNode<T, CachedNode> {
cache: Arc<Mutex<Option<(u64, T)>>>,
node: CachedNode,
}
impl<'i, 'o: 'i, I: Hash + 'i, T: 'i + Clone + 'o + WasmNotSend, CachedNode: 'i> Node<'i, I> for MemoNode<T, CachedNode>
impl<'i, I: Hash + 'i, T: 'i + Clone + WasmNotSend, CachedNode: 'i> Node<'i, I> for MemoNode<T, CachedNode>
where
CachedNode: for<'any_input> Node<'any_input, I>,
for<'a> <CachedNode as Node<'a, I>>::Output: core::future::Future<Output = T> + WasmNotSend,
Expand Down Expand Up @@ -62,7 +62,7 @@ pub struct ImpureMemoNode<I, T, CachedNode> {
_phantom: std::marker::PhantomData<I>,
}

impl<'i, 'o: 'i, I: 'i, T: 'i + Clone + 'o + WasmNotSend, CachedNode: 'i> Node<'i, I> for ImpureMemoNode<I, T, CachedNode>
impl<'i, I: 'i, T: 'i + Clone + WasmNotSend, CachedNode: 'i> Node<'i, I> for ImpureMemoNode<I, T, CachedNode>
where
CachedNode: for<'any_input> Node<'any_input, I>,
for<'a> <CachedNode as Node<'a, I>>::Output: core::future::Future<Output = T> + WasmNotSend,
Expand Down Expand Up @@ -224,22 +224,22 @@ pub struct MemoHashGuard<'a, T: Hash> {
inner: &'a mut MemoHash<T>,
}

impl<'a, T: Hash> core::ops::Drop for MemoHashGuard<'a, T> {
impl<T: Hash> core::ops::Drop for MemoHashGuard<'_, T> {
fn drop(&mut self) {
let hash = MemoHash::<T>::calc_hash(&self.inner.value);
self.inner.hash = hash;
}
}

impl<'a, T: Hash> core::ops::Deref for MemoHashGuard<'a, T> {
impl<T: Hash> core::ops::Deref for MemoHashGuard<'_, T> {
type Target = T;

fn deref(&self) -> &Self::Target {
&self.inner.value
}
}

impl<'a, T: Hash> core::ops::DerefMut for MemoHashGuard<'a, T> {
impl<T: Hash> core::ops::DerefMut for MemoHashGuard<'_, T> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner.value
}
Expand Down
8 changes: 4 additions & 4 deletions node-graph/gcore/src/raster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ pub trait Sample {
fn sample(&self, pos: DVec2, area: DVec2) -> Option<Self::Pixel>;
}

impl<'i, T: Sample> Sample for &'i T {
impl<T: Sample> Sample for &T {
type Pixel = T::Pixel;

#[inline(always)]
Expand All @@ -229,7 +229,7 @@ pub trait Bitmap {
fn get_pixel(&self, x: u32, y: u32) -> Option<Self::Pixel>;
}

impl<'i, T: Bitmap> Bitmap for &'i T {
impl<T: Bitmap> Bitmap for &T {
type Pixel = T::Pixel;

fn width(&self) -> u32 {
Expand All @@ -245,7 +245,7 @@ impl<'i, T: Bitmap> Bitmap for &'i T {
}
}

impl<'i, T: Bitmap> Bitmap for &'i mut T {
impl<T: Bitmap> Bitmap for &mut T {
type Pixel = T::Pixel;

fn width(&self) -> u32 {
Expand Down Expand Up @@ -276,7 +276,7 @@ pub trait BitmapMut: Bitmap {
}
}

impl<'i, T: BitmapMut + Bitmap> BitmapMut for &'i mut T {
impl<T: BitmapMut + Bitmap> BitmapMut for &mut T {
fn get_pixel_mut(&mut self, x: u32, y: u32) -> Option<&mut Self::Pixel> {
(*self).get_pixel_mut(x, y)
}
Expand Down
Loading

0 comments on commit e3bb11e

Please sign in to comment.