Skip to content

Commit

Permalink
Merge pull request #448 from kas-gui/work1
Browse files Browse the repository at this point in the history
Fix various warnings
  • Loading branch information
dhardy authored Apr 24, 2024
2 parents 8873845 + 1580c0c commit a5bb5b3
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 60 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,5 @@ jobs:
# -A clippy::comparison_chain \
# -A clippy::if_same_then_else \
# -A clippy::single-match \
# -A clippy::redundant_pattern_matching \
# -A clippy::unit_arg
4 changes: 1 addition & 3 deletions crates/kas-core/src/app/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,7 @@ impl<A: AppData, G: AppGraphicsBuilder, T: Theme<G::Shared>> Window<A, G, T> {
}

pub(super) fn update_timer(&mut self, state: &mut AppState<A, G, T>) -> Option<Instant> {
let Some(ref window) = self.window else {
return None;
};
let window = self.window.as_ref()?;

let widget = self.widget.as_node(&state.data);
let mut messages = MessageStack::new();
Expand Down
1 change: 1 addition & 0 deletions crates/kas-core/src/core/widget_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ impl<'a> Iterator for WidgetPathIter<'a> {
/// [`Display`]: std::fmt::Display
/// [`Action::RECONFIGURE`]: crate::Action::RECONFIGURE
/// [`ConfigCx::configure`]: crate::event::ConfigCx::configure
#[allow(clippy::assigning_clones)]
#[derive(Clone)]
pub struct Id(IntOrPtr);

Expand Down
1 change: 0 additions & 1 deletion crates/kas-core/src/event/cx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use std::future::Future;
use std::ops::{Deref, DerefMut};
use std::pin::Pin;
use std::time::Instant;
use std::u16;

use super::config::WindowConfig;
use super::*;
Expand Down
1 change: 1 addition & 0 deletions crates/kas-core/src/layout/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub trait Visitable {
///
/// This is templated over `cell_info: C` where `C = ()` for lists or
/// `C = GridCellInfo` for grids.
#[allow(clippy::len_without_is_empty)]
#[cfg_attr(not(feature = "internal_doc"), doc(hidden))]
#[cfg_attr(doc_cfg, doc(cfg(internal_doc)))]
pub trait VisitableList<C> {
Expand Down
15 changes: 7 additions & 8 deletions crates/kas-macros/src/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,24 @@ use syn::{Expr, Ident, Lifetime, LitInt, LitStr, Token};

#[derive(Debug)]
pub enum StorIdent {
Named(Ident, Span),
Generated(Ident, Span),
Named(Ident),
Generated(Ident),
}
impl From<Lifetime> for StorIdent {
fn from(lt: Lifetime) -> StorIdent {
let span = lt.span();
StorIdent::Named(lt.ident, span)
fn from(mut lt: Lifetime) -> StorIdent {
lt.ident.set_span(lt.span());
StorIdent::Named(lt.ident)
}
}
impl From<Ident> for StorIdent {
fn from(ident: Ident) -> StorIdent {
let span = ident.span();
StorIdent::Generated(ident, span)
StorIdent::Generated(ident)
}
}
impl ToTokens for StorIdent {
fn to_tokens(&self, toks: &mut Toks) {
match self {
StorIdent::Named(ident, _) | StorIdent::Generated(ident, _) => ident.to_tokens(toks),
StorIdent::Named(ident) | StorIdent::Generated(ident) => ident.to_tokens(toks),
}
}
}
Expand Down
50 changes: 22 additions & 28 deletions crates/kas-macros/src/make_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,26 @@ impl Tree {
&self,
children: I,
) -> std::result::Result<Toks, (Span, &'static str)> {
match &self.0 {
layout => {
let mut v = Vec::new();
layout.nav_next(children, &mut v).map(|()| {
quote! {
fn nav_next(&self, reverse: bool, from: Option<usize>) -> Option<usize> {
let mut iter = [#(#v),*].into_iter();
if !reverse {
if let Some(wi) = from {
let _ = iter.find(|x| *x == wi);
}
iter.next()
} else {
let mut iter = iter.rev();
if let Some(wi) = from {
let _ = iter.find(|x| *x == wi);
}
iter.next()
}
let mut v = Vec::new();
self.0.nav_next(children, &mut v).map(|()| {
quote! {
fn nav_next(&self, reverse: bool, from: Option<usize>) -> Option<usize> {
let mut iter = [#(#v),*].into_iter();
if !reverse {
if let Some(wi) = from {
let _ = iter.find(|x| *x == wi);
}
iter.next()
} else {
let mut iter = iter.rev();
if let Some(wi) = from {
let _ = iter.find(|x| *x == wi);
}
iter.next()
}
})
}
}
}
})
}

/// If field `ident` is included in the layout, return Span of usage
Expand Down Expand Up @@ -477,7 +473,7 @@ impl Layout {
);

// Clear remainder of input stream to avoid a redundant error
let _ = input.step(|cursor| {
input.step(|cursor| {
let mut rest = *cursor;
while let Some((_, next)) = rest.token_tree() {
rest = next;
Expand Down Expand Up @@ -1090,12 +1086,10 @@ impl Layout {
}
Layout::Widget(ident, _) => {
for (i, child) in children.enumerate() {
if let ChildIdent::CoreField(ref child_ident) = child.ident {
if let Member::Named(ref ci) = child_ident {
if *ident == *ci {
output.push(i);
return Ok(());
}
if let ChildIdent::CoreField(Member::Named(ref ci)) = child.ident {
if *ident == *ci {
output.push(i);
return Ok(());
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion crates/kas-macros/src/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,18 @@ mod kw {

#[derive(Debug)]
pub struct BoolToken {
#[allow(dead_code)]
pub kw_span: Span,
#[allow(dead_code)]
pub eq: Eq,
pub lit: syn::LitBool,
}

#[derive(Debug)]
pub struct ExprToken {
#[allow(dead_code)]
pub kw_span: Span,
#[allow(dead_code)]
pub eq: Eq,
pub expr: syn::Expr,
}
Expand Down Expand Up @@ -176,7 +180,7 @@ pub struct Child {
impl Child {
pub fn new_core(ident: Member) -> Self {
Child {
ident: ChildIdent::CoreField(ident.into()),
ident: ChildIdent::CoreField(ident),
attr_span: None,
data_binding: None,
}
Expand Down
10 changes: 5 additions & 5 deletions crates/kas-resvg/src/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ impl_scope! {
/// Use [`Self::with_size`] or [`Self::with_scaling`] to set the initial size.
#[inline]
pub fn new(program: P) -> Self {
let mut scaling = PixmapScaling::default();
scaling.size = LogicalSize(128.0, 128.0);
scaling.stretch = Stretch::High;

Canvas {
core: Default::default(),
scaling,
scaling: PixmapScaling {
size: LogicalSize(128.0, 128.0),
stretch: Stretch::High,
..Default::default()
},
inner: State::Initial(program),
image: None,
}
Expand Down
6 changes: 4 additions & 2 deletions crates/kas-view/src/filter/filter_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use super::Filter;
use crate::{ListData, SharedData};
use kas::classes::HasStr;
use kas::event::{ConfigCx, EventCx};
use kas::{autoimpl, impl_scope, Events, Widget};
use kas_widgets::edit::{EditBox, EditField, EditGuard};
Expand All @@ -26,7 +27,7 @@ impl EditGuard for KeystrokeGuard {
type Data = ();

fn edit(edit: &mut EditField<Self>, cx: &mut EventCx, _: &Self::Data) {
cx.push(SetFilter(edit.to_string()));
cx.push(SetFilter(edit.get_string()));
}
}

Expand All @@ -42,7 +43,7 @@ impl EditGuard for AflGuard {

#[inline]
fn focus_lost(edit: &mut EditField<Self>, cx: &mut EventCx, _: &Self::Data) {
cx.push(SetFilter(edit.to_string()));
cx.push(SetFilter(edit.get_string()));
}
}

Expand Down Expand Up @@ -196,6 +197,7 @@ impl_scope! {
}

impl Self {
#[allow(clippy::missing_transmute_annotations)] // fields and fn parameters are annotated
unsafe fn new<'a>(data: &'a A, view: &'a [A::Key]) -> Self {
UnsafeFilteredList {
data: std::mem::transmute(data),
Expand Down
16 changes: 4 additions & 12 deletions crates/kas-widgets/src/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,12 +455,6 @@ impl_scope! {
action
}
}

impl ToString for Self {
fn to_string(&self) -> String {
self.inner.to_string()
}
}
}

impl<G: EditGuard> EditBox<G> {
Expand Down Expand Up @@ -904,6 +898,10 @@ impl_scope! {
fn get_str(&self) -> &str {
self.text.text()
}

fn get_string(&self) -> String {
self.text.text().clone()
}
}

impl HasString for Self {
Expand All @@ -925,12 +923,6 @@ impl_scope! {
action | self.set_error_state(false)
}
}

impl ToString for Self {
fn to_string(&self) -> String {
self.text.text().clone()
}
}
}

impl<G: EditGuard> EditField<G> {
Expand Down
2 changes: 2 additions & 0 deletions examples/times-tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ impl MatrixData for TableSize {
(self.0, self.0)
}

#[allow(refining_impl_trait)]
fn col_iter_from(&self, start: usize, limit: usize) -> std::ops::Range<usize> {
let end = self.0.min(start + limit);
start..end
}
#[allow(refining_impl_trait)]
fn row_iter_from(&self, start: usize, limit: usize) -> std::ops::Range<usize> {
let end = self.0.min(start + limit);
start..end
Expand Down

0 comments on commit a5bb5b3

Please sign in to comment.