Better generic support in implement #2986
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes: #2984
It turns out windows-rs already supports generics in the
implement
macro, but would handle generic bounds of the form<T: Bound>
a bit wrong. It would generate code like this:This is wrong, first line should read
impl<T: AmsiProvider> ::core::convert::From<AmsiClassFactory<T>>
, dropping the bound when applying the generic on the right hand side of the for.Syn has a function for exactly this use-case:
Generics::split_for_impl
, which returns three values: An ImplGeneric to apply to the impl and contains the bounds, aTypeGenerics
to apply on a type and does not contain the bounds,and the WhereClause with the additional bounds.This MR reworks the implement macro to use this function, thus fixing this corner case.