Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autoimpl; revise widget macros #258

Merged
merged 33 commits into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
8df442d
Remove outdated TODO
dhardy Nov 4, 2021
5b360e3
Replace derive(Widget) with function-like macro
dhardy Nov 9, 2021
3dc8b0b
Move impls into widget! macro
dhardy Nov 10, 2021
4a53a0b
Move handling for impl on Self up
dhardy Nov 10, 2021
ee0ee6f
Update make_widget! to use impl Self syntax
dhardy Nov 10, 2021
db0c5bb
widget! macro: discover whether to derive WidgetChildren
dhardy Nov 10, 2021
dbf4833
widget! macro: discover whether to derive WidgetConfig
dhardy Nov 10, 2021
9a52612
widget! macro: discover whether to derive Handler and SendEvent
dhardy Nov 10, 2021
f3ba3a3
Remove handler type substitutions: unused and over-complex
dhardy Nov 10, 2021
188dede
Remove support for multiple handler impls: unused
dhardy Nov 10, 2021
0adb8a6
make_widget: simplify extra bounds
dhardy Nov 10, 2021
c6b14b1
Remove support for #[handler(generics = ...)]
dhardy Nov 10, 2021
a179288
kas_macros: move widget and make_widget impls to sub-modules
dhardy Nov 11, 2021
6377190
New autoimpl macro (only supports Debug)
dhardy Nov 11, 2021
04f7725
Use #[autoimpl(Debug)]
dhardy Nov 11, 2021
cd26bd3
autoimpl: support Clone
dhardy Nov 11, 2021
491544d
autoimpl: support Deref, DerefMut
dhardy Nov 11, 2021
0abcc6a
Remove widget_derive support for Deref, DerefMut
dhardy Nov 11, 2021
0b19d7d
autoimpl: on and skip are mutually exclusive
dhardy Nov 13, 2021
ac84441
autoimpl: revise implementation, reporting more errors during parsing
dhardy Nov 13, 2021
ee4ceac
autoimpl: support each class trait
dhardy Nov 13, 2021
4745922
autoimpl: support "where T: trait" syntax
dhardy Nov 24, 2021
761b8a2
autoimpl: support deriving class_traits
dhardy Nov 24, 2021
6c39ea5
widget_derive: remove support for class_traits
dhardy Nov 24, 2021
2fd058e
Move more class trait impls to autoimpl
dhardy Nov 24, 2021
71be81a
Replace #[widget_derive] with #[widget(derive=FIELD)]
dhardy Nov 25, 2021
d8fd49c
Update widget and autoimpl macro doc; fix examples
dhardy Nov 28, 2021
a4cd76a
Fix mandlebrot example
dhardy Nov 28, 2021
4f9049a
autoimpl: use paths on bounds inferred via X: trait
dhardy Nov 28, 2021
6cd00f4
Clippy fixes
dhardy Nov 28, 2021
97f23b2
autoimpl before derive
dhardy Nov 28, 2021
eb7c6f5
Apply required bounds on GATs
dhardy Nov 29, 2021
cb6eb56
autoimpl: support Default
dhardy Nov 29, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Clippy fixes
  • Loading branch information
dhardy committed Nov 28, 2021
commit 6cd00f4abdd4ac8f777adfd06be84de789c2b250
27 changes: 15 additions & 12 deletions crates/kas-macros/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,16 +327,22 @@ fn parse_impl(in_ident: Option<&Ident>, input: ParseStream) -> Result<ItemImpl>
}

fn parse_attrs_inner(input: ParseStream, attrs: &mut Vec<Attribute>) -> Result<()> {
Ok(while input.peek(Token![#]) && input.peek2(Token![!]) {
while input.peek(Token![#]) && input.peek2(Token![!]) {
let pound_token = input.parse()?;
let style = AttrStyle::Inner(input.parse()?);
let content;
let bracket_token = bracketed!(content in input);
let path = content.call(Path::parse_mod_style)?;
let tokens = content.parse()?;
attrs.push(Attribute {
pound_token: input.parse()?,
style: AttrStyle::Inner(input.parse()?),
bracket_token: bracketed!(content in input),
path: content.call(Path::parse_mod_style)?,
tokens: content.parse()?,
pound_token,
style,
bracket_token,
path,
tokens,
});
})
}
Ok(())
}

fn member(index: usize, ident: Option<Ident>) -> Member {
Expand Down Expand Up @@ -399,11 +405,8 @@ impl Parse for WidgetDerive {
let content;
let _ = parenthesized!(content in input);

loop {
let lookahead = content.lookahead1();
if content.is_empty() {
break;
}
let lookahead = content.lookahead1();
if !content.is_empty() {
return Err(lookahead.error());
}

Expand Down
5 changes: 3 additions & 2 deletions crates/kas-macros/src/autoimpl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ enum TraitOne {
SetAccel(Span),
}
#[derive(Clone, Copy)]
#[allow(clippy::enum_variant_names)]
enum Class {
Many(TraitMany),
One(TraitOne),
Expand Down Expand Up @@ -105,7 +106,7 @@ impl Parse for AutoImpl {

if empty_or_trailing {
if lookahead.peek(Ident) {
const MSG: &'static str = "incompatible: traits targetting a single field and traits targetting multiple fields may not be derived simultaneously";
const MSG: &str = "incompatible: traits targetting a single field and traits targetting multiple fields may not be derived simultaneously";
let target = input.parse()?;
match class(&target) {
Some(Class::Many(trait_)) => {
Expand Down Expand Up @@ -341,7 +342,7 @@ fn autoimpl_one(
clause: &Option<WhereClause>,
toks: &mut TokenStream,
) {
fn for_field<'a, T, F: Fn(&Field) -> T>(fields: &'a Fields, mem: &Member, f: F) -> Option<T> {
fn for_field<T, F: Fn(&Field) -> T>(fields: &Fields, mem: &Member, f: F) -> Option<T> {
match (fields, mem) {
(Fields::Named(ref fields), Member::Named(ref ident)) => {
for field in fields.named.iter() {
Expand Down
4 changes: 2 additions & 2 deletions crates/kas-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ fn extend_generics(generics: &mut Generics, in_generics: &Generics) {
if generics.lt_token.is_none() {
debug_assert!(generics.params.is_empty());
debug_assert!(generics.gt_token.is_none());
generics.lt_token = in_generics.lt_token.clone();
generics.lt_token = in_generics.lt_token;
generics.params = in_generics.params.clone();
generics.gt_token = in_generics.gt_token.clone();
generics.gt_token = in_generics.gt_token;
} else if in_generics.lt_token.is_none() {
debug_assert!(in_generics.params.is_empty());
debug_assert!(in_generics.gt_token.is_none());
Expand Down
7 changes: 3 additions & 4 deletions crates/kas-macros/src/make_widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ pub(crate) fn make_widget(mut args: MakeWidget) -> TokenStream {
handler_clauses
.push(parse_quote! { #ty: ::kas::Widget<Msg = #ty_bound> });
} else {
return quote! {}.into(); // exit after emitting error
return quote! {}; // exit after emitting error
}
} else if wattr.args.handler == Handler::Discard {
// No type bound on discarded message
Expand Down Expand Up @@ -245,7 +245,7 @@ pub(crate) fn make_widget(mut args: MakeWidget) -> TokenStream {

// TODO: we should probably not rely on recursive macro expansion here!
// (I.e. use direct code generation for Widget derivation, instead of derive.)
let toks = (quote! { {
let toks = quote! { {
::kas::macros::widget! {
#[derive(Debug)]
#extra_attrs
Expand All @@ -261,8 +261,7 @@ pub(crate) fn make_widget(mut args: MakeWidget) -> TokenStream {
AnonWidget {
#field_val_toks
}
} })
.into();
} };

toks
}
1 change: 1 addition & 0 deletions crates/kas-macros/src/where_clause.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub struct WhereClause {
}

/// A single predicate in a `where` clause: `T: Deserialize<'de>`.
#[allow(clippy::large_enum_variant)]
pub enum WherePredicate {
/// A type predicate in a `where` clause: `for<'c> Foo<'c>: Trait<'c>`.
Type(PredicateType),
Expand Down
4 changes: 2 additions & 2 deletions crates/kas-macros/src/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ pub(crate) fn widget(mut args: Widget) -> TokenStream {
#dt
}
}),
Err(err) => return err.to_compile_error().into(),
Err(err) => return err.to_compile_error(),
}

match layout::derive(&args.children, layout, &args.layout_data) {
Expand All @@ -279,7 +279,7 @@ pub(crate) fn widget(mut args: Widget) -> TokenStream {
#fns
}
}),
Err(err) => return err.to_compile_error().into(),
Err(err) => return err.to_compile_error(),
}
}

Expand Down