Skip to content

Commit

Permalink
Fix as many new clippy lints as possible
Browse files Browse the repository at this point in the history
Signed-off-by: Manos Pitsidianakis <[email protected]>
  • Loading branch information
epilys committed Oct 17, 2024
1 parent 75df734 commit b5b29b2
Show file tree
Hide file tree
Showing 39 changed files with 298 additions and 303 deletions.
2 changes: 1 addition & 1 deletion src/api/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ pub struct ObjectRegistry {
}

impl ObjectRegistry {
const QUARK_KEY: &str = "api-uuid";
const QUARK_KEY: &'static str = "api-uuid";

pub fn add(&mut self, obj: &glib::Object) -> Uuid {
Self::opt_id(obj).unwrap_or_else(|| {
Expand Down
2 changes: 1 addition & 1 deletion src/api/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ macro_rules! generate_py_class {
}
_pyo3::ffi::PyType_Slot {
slot: _pyo3::ffi::Py_tp_repr,
pfunc: trampoline as _pyo3::ffi::reprfunc as _,
pfunc: trampoline as _pyo3::ffi::reprfunc as *mut std::ffi::c_void,
}
}],
};
Expand Down
4 changes: 2 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ impl std::ops::Deref for Application {
}

impl Application {
pub const UI_FONT: &str = "ui-font";
pub const THEME: &str = "theme";
pub const UI_FONT: &'static str = "ui-font";
pub const THEME: &'static str = "theme";

#[allow(clippy::new_without_default)]
pub fn new() -> Self {
Expand Down
19 changes: 12 additions & 7 deletions src/app/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ impl SettingsInner {
.read(true)
.write(true)
.create(false)
.truncate(false)
.open(path)
.is_ok()
{
Expand All @@ -208,6 +209,7 @@ impl SettingsInner {
.read(true)
.write(true)
.create(true)
.truncate(false)
.open(path)?;
Ok(())
}
Expand Down Expand Up @@ -247,6 +249,7 @@ impl SettingsInner {
.read(true)
.write(true)
.create(true)
.truncate(false)
.open(&path)?;
let mut toml = String::new();

Expand Down Expand Up @@ -357,7 +360,9 @@ impl SettingsInner {
.flatten()
.filter(|wref| wref.upgrade().as_ref() != Some(obj))
{
let Some(obj) = e.upgrade() else { continue; };
let Some(obj) = e.upgrade() else {
continue;
};
let document = self.document.borrow();
macro_rules! set_if_neq {
($ty:ty, $val:expr) => {{
Expand Down Expand Up @@ -604,12 +609,12 @@ impl Default for Settings {
}

impl Settings {
pub const HANDLE_SIZE: &str = "handle-size";
pub const LINE_WIDTH: &str = "line-width";
pub const GUIDELINE_WIDTH: &str = "guideline-width";
pub const WARP_CURSOR: &str = "warp-cursor";
pub const MARK_COLOR: &str = "mark-color";
pub const SHOW_PRERELEASE_WARNING: &str = "show-prerelease-warning";
pub const HANDLE_SIZE: &'static str = "handle-size";
pub const LINE_WIDTH: &'static str = "line-width";
pub const GUIDELINE_WIDTH: &'static str = "guideline-width";
pub const WARP_CURSOR: &'static str = "warp-cursor";
pub const MARK_COLOR: &'static str = "mark-color";
pub const SHOW_PRERELEASE_WARNING: &'static str = "show-prerelease-warning";

pub fn new() -> Self {
glib::Object::new::<Self>(&[]).unwrap()
Expand Down
2 changes: 1 addition & 1 deletion src/app/settings/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl EnumValue<'_> for Theme {
}

impl Theme {
pub const PAPERWHITE_CSS: &[u8] = include_bytes!("../../themes/paperwhite/gtk.css");
pub const PAPERWHITE_CSS: &'static [u8] = include_bytes!("../../themes/paperwhite/gtk.css");
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions src/app/undo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ impl Default for UndoDatabase {
}

impl UndoDatabase {
pub const CAN_UNDO: &str = "can-undo";
pub const CAN_REDO: &str = "can-redo";
pub const CAN_UNDO: &'static str = "can-undo";
pub const CAN_REDO: &'static str = "can-redo";

pub fn new() -> Self {
let ret: Self = glib::Object::new::<Self>(&[]).unwrap();
Expand Down
26 changes: 13 additions & 13 deletions src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,9 @@ impl ObjectImpl for EditorInner {
),
def_param!(f64 Editor::UNITS_PER_EM, 1.0, ufo::constants::UNITS_PER_EM),
def_param!(f64 Editor::X_HEIGHT, 1.0, ufo::constants::X_HEIGHT),
def_param!(f64 Editor::ASCENDER, std::f64::MIN, ufo::constants::ASCENDER),
def_param!(f64 Editor::DESCENDER, std::f64::MIN, ufo::constants::DESCENDER),
def_param!(f64 Editor::CAP_HEIGHT, std::f64::MIN, ufo::constants::CAP_HEIGHT),
def_param!(f64 Editor::ASCENDER, f64::MIN, ufo::constants::ASCENDER),
def_param!(f64 Editor::DESCENDER, f64::MIN, ufo::constants::DESCENDER),
def_param!(f64 Editor::CAP_HEIGHT, f64::MIN, ufo::constants::CAP_HEIGHT),
glib::ParamSpecBoolean::new(
Editor::LOCK_GUIDELINES,
Editor::LOCK_GUIDELINES,
Expand Down Expand Up @@ -358,12 +358,12 @@ impl ObjectImpl for EditorInner {
Editor::ACTIVE_TOOL => {
let state = self.state.get().unwrap().borrow();
let active_tool = state.active_tool;
state.tools.get(&active_tool).map(Clone::clone).to_value()
state.tools.get(&active_tool).cloned().to_value()
}
Editor::PANNING_TOOL => {
let state = self.state.get().unwrap().borrow();
let panning_tool = state.panning_tool;
state.tools.get(&panning_tool).map(Clone::clone).to_value()
state.tools.get(&panning_tool).cloned().to_value()
}
Editor::MENUBAR => Some(self.menubar.clone()).to_value(),
Editor::LOCK => self.lock.get().1.bits().to_value(),
Expand Down Expand Up @@ -548,11 +548,11 @@ impl_deref!(Editor, EditorInner);
impl_friendly_name!(Editor);

impl Editor {
pub const CLOSEABLE: &str = Workspace::CLOSEABLE;
pub const TITLE: &str = Workspace::TITLE;
pub const IS_MENU_VISIBLE: &str = Workspace::IS_MENU_VISIBLE;
pub const MENUBAR: &str = Workspace::MENUBAR;
pub const PREVIEW: &str = "preview";
pub const CLOSEABLE: &'static str = Workspace::CLOSEABLE;
pub const TITLE: &'static str = Workspace::TITLE;
pub const IS_MENU_VISIBLE: &'static str = Workspace::IS_MENU_VISIBLE;
pub const MENUBAR: &'static str = Workspace::MENUBAR;
pub const PREVIEW: &'static str = "preview";
inherit_property!(
FontInfo,
ASCENDER,
Expand All @@ -561,9 +561,9 @@ impl Editor {
UNITS_PER_EM,
X_HEIGHT
);
pub const MODIFYING_IN_PROCESS: &str = "modifying-in-process";
pub const ACTIVE_TOOL: &str = "active-tool";
pub const PANNING_TOOL: &str = "panning-tool";
pub const MODIFYING_IN_PROCESS: &'static str = "modifying-in-process";
pub const ACTIVE_TOOL: &'static str = "active-tool";
pub const PANNING_TOOL: &'static str = "panning-tool";
inherit_property!(
EditorSettings,
SHOW_MINIMAP,
Expand Down
10 changes: 5 additions & 5 deletions src/editor/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ impl Default for EditorSettings {
}

impl EditorSettings {
pub const SHOW_MINIMAP: &str = "show-minimap";
pub const LOCK_GUIDELINES: &str = "lock-guidelines";
pub const SHOW_GLYPH_GUIDELINES: &str = "show-glyph-guidelines";
pub const SHOW_PROJECT_GUIDELINES: &str = "show-project-guidelines";
pub const SHOW_METRICS_GUIDELINES: &str = "show-metrics-guidelines";
pub const SHOW_MINIMAP: &'static str = "show-minimap";
pub const LOCK_GUIDELINES: &'static str = "lock-guidelines";
pub const SHOW_GLYPH_GUIDELINES: &'static str = "show-glyph-guidelines";
pub const SHOW_PROJECT_GUIDELINES: &'static str = "show-project-guidelines";
pub const SHOW_METRICS_GUIDELINES: &'static str = "show-metrics-guidelines";

pub fn new() -> Self {
glib::Object::new::<Self>(&[]).unwrap()
Expand Down
50 changes: 25 additions & 25 deletions src/editor/shortcuts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,31 @@ use super::*;
use gtk::gdk::keys::constants as keys;

impl Editor {
pub const LOCK: &str = "lock";
pub const SNAP: &str = "snap";
pub const PRECISION: &str = "precision";
pub const PREVIEW_ACTION: &str = Self::PREVIEW;
pub const ZOOM_IN_ACTION: &str = "zoom.in";
pub const ZOOM_OUT_ACTION: &str = "zoom.out";
pub const LOCK_ACTION: &str = Self::LOCK;
pub const LOCK_X_ACTION: &str = "lock.x";
pub const LOCK_Y_ACTION: &str = "lock.y";
pub const LOCK_LOCAL_ACTION: &str = "lock.local";
pub const LOCK_CONTROLS_ACTION: &str = "lock.controls";
pub const PRECISION_ACTION: &str = Self::PRECISION;
pub const SNAP_ACTION: &str = Self::SNAP;
pub const SNAP_CLEAR_ACTION: &str = "snap.clear";
pub const SNAP_ANGLE_ACTION: &str = "snap.angle";
pub const SNAP_GRID_ACTION: &str = "snap.grid";
pub const SNAP_GUIDELINES_ACTION: &str = "snap.guidelines";
pub const SNAP_METRICS_ACTION: &str = "snap.metrics";
pub const MOVE_UP_ACTION: &str = "move.up";
pub const MOVE_DOWN_ACTION: &str = "move.down";
pub const MOVE_RIGHT_ACTION: &str = "move.right";
pub const MOVE_LEFT_ACTION: &str = "move.left";
pub const SELECT_ALL_ACTION: &str = "select.all";
pub const SELECT_NONE_ACTION: &str = "select.none";
pub const SELECT_INVERT_ACTION: &str = "select.invert";
pub const LOCK: &'static str = "lock";
pub const SNAP: &'static str = "snap";
pub const PRECISION: &'static str = "precision";
pub const PREVIEW_ACTION: &'static str = Self::PREVIEW;
pub const ZOOM_IN_ACTION: &'static str = "zoom.in";
pub const ZOOM_OUT_ACTION: &'static str = "zoom.out";
pub const LOCK_ACTION: &'static str = Self::LOCK;
pub const LOCK_X_ACTION: &'static str = "lock.x";
pub const LOCK_Y_ACTION: &'static str = "lock.y";
pub const LOCK_LOCAL_ACTION: &'static str = "lock.local";
pub const LOCK_CONTROLS_ACTION: &'static str = "lock.controls";
pub const PRECISION_ACTION: &'static str = Self::PRECISION;
pub const SNAP_ACTION: &'static str = Self::SNAP;
pub const SNAP_CLEAR_ACTION: &'static str = "snap.clear";
pub const SNAP_ANGLE_ACTION: &'static str = "snap.angle";
pub const SNAP_GRID_ACTION: &'static str = "snap.grid";
pub const SNAP_GUIDELINES_ACTION: &'static str = "snap.guidelines";
pub const SNAP_METRICS_ACTION: &'static str = "snap.metrics";
pub const MOVE_UP_ACTION: &'static str = "move.up";
pub const MOVE_DOWN_ACTION: &'static str = "move.down";
pub const MOVE_RIGHT_ACTION: &'static str = "move.right";
pub const MOVE_LEFT_ACTION: &'static str = "move.left";
pub const SELECT_ALL_ACTION: &'static str = "select.all";
pub const SELECT_NONE_ACTION: &'static str = "select.none";
pub const SELECT_INVERT_ACTION: &'static str = "select.invert";
}

impl EditorInner {
Expand Down
4 changes: 2 additions & 2 deletions src/editor/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ impl State {
clone!(@strong idxs, @weak self.kd_tree as kd_tree, @weak self.glyph as glyph, @weak viewport => move || {
let mut kd_tree = kd_tree.borrow_mut();
let glyph = glyph.borrow();
for contour_index in idxs.iter().map(|i| i.contour_index).collect::<HashSet<usize>>() {
for contour_index in idxs.iter().map(|i| i.contour_index) {
let contour = &glyph.contours[contour_index];
for (idx, new_pos) in contour.transform_points(contour_index, &idxs, m) {
kd_tree.add(idx, new_pos);
Expand All @@ -262,7 +262,7 @@ impl State {
let m = if let Ok(m) = m.try_invert() {m} else {return;};
let mut kd_tree = kd_tree.borrow_mut();
let glyph = glyph.borrow();
for contour_index in idxs.iter().map(|i| i.contour_index).collect::<HashSet<usize>>() {
for contour_index in idxs.iter().map(|i| i.contour_index) {
let contour = &glyph.contours[contour_index];
for (idx, new_pos) in contour.transform_points(contour_index, &idxs, m) {
/* update kd_tree */
Expand Down
44 changes: 13 additions & 31 deletions src/editor/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ mod tool_impl;
mod zoom;
pub use self::image::*;
pub use bezier::*;
pub use bspline::*;
pub use panning::*;
pub use shapes::*;
pub use tool_impl::*;
Expand All @@ -48,15 +47,9 @@ impl Tool {
let active_tools = state
.tools
.get(&state.active_tool)
.map(Clone::clone)
.cloned()
.into_iter()
.chain(
state
.tools
.get(&state.panning_tool)
.map(Clone::clone)
.into_iter(),
);
.chain(state.tools.get(&state.panning_tool).cloned());
drop(state);
for t in active_tools {
if t.on_button_press_event(obj.clone(), viewport, event) == Inhibit(true) {
Expand All @@ -75,15 +68,9 @@ impl Tool {
let active_tools = state
.tools
.get(&state.active_tool)
.map(Clone::clone)
.cloned()
.into_iter()
.chain(
state
.tools
.get(&state.panning_tool)
.map(Clone::clone)
.into_iter(),
);
.chain(state.tools.get(&state.panning_tool).cloned());
drop(state);
for t in active_tools {
if t.on_button_release_event(obj.clone(), viewport, event) == Inhibit(true) {
Expand All @@ -99,13 +86,14 @@ impl Tool {
event: &gtk::gdk::EventScroll,
) -> Inhibit {
let state = obj.state().borrow();
let (panning_tool, active_tool) = (state.panning_tool, state.active_tool);
let panning_tool = state.panning_tool;
let active_tool = state.active_tool;
let active_tools = state
.tools
.get(&active_tool)
.map(Clone::clone)
.cloned()
.into_iter()
.chain(state.tools.get(&panning_tool).map(Clone::clone).into_iter())
.chain(state.tools.get(&panning_tool).cloned())
.chain(state.tools.clone().into_iter().filter_map(|(k, v)| {
if [panning_tool, active_tool].contains(&k) {
None
Expand All @@ -131,15 +119,9 @@ impl Tool {
let active_tools = state
.tools
.get(&state.active_tool)
.map(Clone::clone)
.cloned()
.into_iter()
.chain(
state
.tools
.get(&state.panning_tool)
.map(Clone::clone)
.into_iter(),
);
.chain(state.tools.get(&state.panning_tool).cloned());
drop(state);
for t in active_tools {
if t.on_motion_notify_event(obj.clone(), viewport, event) == Inhibit(true) {
Expand Down Expand Up @@ -401,7 +383,7 @@ pub mod constraints {
}

impl Lock {
const ACTION_NAME: &str = Editor::LOCK_ACTION;
const ACTION_NAME: &'static str = Editor::LOCK_ACTION;

pub fn as_str(&self) -> &'static str {
match *self {
Expand Down Expand Up @@ -438,7 +420,7 @@ pub mod constraints {
}

impl Precision {
const ACTION_NAME: &str = Editor::PRECISION_ACTION;
const ACTION_NAME: &'static str = Editor::PRECISION_ACTION;

pub fn as_str(&self) -> &'static str {
match *self {
Expand Down Expand Up @@ -468,7 +450,7 @@ pub mod constraints {
}

impl Snap {
const ACTION_NAME: &str = Editor::SNAP_ACTION;
const ACTION_NAME: &'static str = Editor::SNAP_ACTION;

pub fn as_str(&self) -> &'static str {
match *self {
Expand Down
12 changes: 4 additions & 8 deletions src/editor/tools/bezier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,12 +467,8 @@ impl ToolImplImpl for BezierToolInner {
self.transform_point(m, &view, state, state.curve_index, handle_point);
}
if !unlinked {
let linked_curve_point = state.contour.curves()[0]
.points()
.iter()
.nth(1)
.unwrap()
.clone();
let linked_curve_point =
state.contour.curves()[0].points().get(1).unwrap().clone();
let new_mirrored_position = handle.mirror(state.first_point);
let diff_vector = new_mirrored_position - linked_curve_point.position;
let mut m = Matrix::identity();
Expand Down Expand Up @@ -567,7 +563,7 @@ impl BezierToolInner {
mut state_opt: RefMut<'_, Option<ContourState>>,
point: Point,
) {
if let Some(mut state) = state_opt.as_mut() {
if let Some(state) = state_opt.as_mut() {
let add_to_kdtree =
|state: &mut ContourState, curve_index: usize, curve_point: CurvePoint| {
let editor_state = view.state().borrow();
Expand Down Expand Up @@ -738,7 +734,7 @@ impl Default for BezierTool {
}

impl BezierTool {
pub const ACTIVE: &str = "active";
pub const ACTIVE: &'static str = "active";

pub fn new() -> Self {
glib::Object::new(&[]).unwrap()
Expand Down
Loading

0 comments on commit b5b29b2

Please sign in to comment.