-
Notifications
You must be signed in to change notification settings - Fork 9
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
bevy_lint: Add zst_query
lint
#168
Conversation
4bdc77e
to
61f0d59
Compare
61f0d59
to
c1e886b
Compare
Just making sure, this still allows |
Good question! I just tested it and it seems like it does! I added a test for this case specifically. |
return None; | ||
}; | ||
|
||
path.segments.last()?.args().args.get(index) |
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.
Is there ever a case where there may be generics before the final path segment? If so we could do this:
path.segments.last()?.args().args.get(index) | |
path.segments.iter().flat_map(|segment| segment.args().args).nth(index) |
This implementation joins all of the generics in a path together, then finds the GenericArg
at the index. This may have undesired effects, though I haven't tested it.
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.
Yeah there could be like Foo::<i32>::baz::<usize>
for a function signature type or something. So it could be useful. I don't think it would break things for our purposes here since Query
doesn't look like that haha.
I'll try it out!
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.
On second thought, this might break in cases like:
trait Queryable {
type Query<'w, 's, D: QueryData + 'static, F: QueryFilter + 'static>;
}
struct MyQueryable<T>(T);
impl<T> Queryable for MyQueryable<T> {
type Query<'w, 's, D: QueryData + 'static, F: QueryFilter + 'static> = Query<'w, 's, D, F>;
}
fn system<'w, 's>(query: <MyQueryable<f32> as Queryable>::Query<'w, 's, &'static Foo, ()>) {}
Although, to be fair, I just tested this and we don't currently catch associated types like this.
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.
Maybe we save adding this functionality for the future when it's needed? It might at that point even make sense to be a separate function depending on the edge cases.
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.
Maybe we save adding this functionality for the future when it's needed?
I'm fine with that, but would you mind adding a comment to the function docs do users know that it only indexes the generics in the final path segment? (Non-blocking, though)
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.
Thank you, let's get this merged!
Resolves #130