-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Improve handling of the generic baggage fields #5656
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very good! Thank you
.iter() | ||
.filter_map(|gen| match gen { | ||
syn::GenericArgument::Type(ty) => | ||
try_type_to_path(ty.clone(), span.clone()).ok(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This swallows somerrors, which we shouldn't swallow but expose as part of the return type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The GenericArgument enum looks the following:
pub enum GenericArgument {
/// A lifetime argument.
Lifetime(Lifetime),
/// A type argument.
Type(Type),
/// A binding (equality constraint) on an associated type: the `Item =
/// u8` in `Iterator<Item = u8>`.
Binding(Binding),
/// An associated type bound: `Iterator<Item: Display>`.
Constraint(Constraint),
/// A const expression. Must be inside of a block.
///
/// NOTE: Identity expressions are represented as Type arguments, as
/// they are indistinguishable syntactically.
Const(Expr),
}
Lifetimes are irrelevant - we can emit error on that, but it will be also emitted during compilation, as lifetimes are not efficiently supported. Binding is more interesting here, as there could be something like Item = T
where T
is indeed a generic. Constraint can also have generic inside. Probably, it is not a bad option just to throw an error there as it will be a compile error afterwards.
Well, adding strict checks has revealed that we have no real support of anything but paths, for example tuples. It is bad and requires some more changes... |
To clarify, the existing implementation supports |
With this approach, baggage type is now |
bot merge |
Waiting for commit status. |
* Parse generic baggage types more carefully to preserve inner structure * Add example * Way too many clones * Allow multiple generic arguments for baggage fields * Try to detect errors earlier * Support more types for the baggage fields, get rid of the path constraint
This PR addresses issue paritytech/orchestra#6 and allows orchestra proc-macros to deal with the generics in baggage fields.
Gen<T>
,Gen<Gen<T>>
HashMap<Gen<T>, Gen<U>>
Think about lifetimes- not relevant in this case, as subsystems must be staticThink about- not needed (yet), support can be added if any need arisesconst
generic parameters