-
Notifications
You must be signed in to change notification settings - Fork 575
Description
Page: https://rustc-dev-guide.rust-lang.org/ty-module/generic-arguments.html
The code snippit in my head as an example:
struct S<T1> {
f: T1,
}
impl<T1> S<T1> {
fn func<T2>() {}
}
fn main() {
S::<u32>::func::<bool>()
}My question that I want answered by that page: How is S::<u32>::func::<bool> represented? The DefId part of (DefId, GenericArgs) points to fn func(), but is the GenericArgs just [bool] (somehow storing u32 somewhere else), or does it include "parent" generics as well, being [u32, bool]?
I ended up DM'ing @BoxyUwU to ask how this works - turns out it's [u32, bool]. She asked me to open this issue to make the rustc-dev-guide page more clear that GenericArgs is [u32, bool] in this case. A reference to the generics_of query/ty::Generics would be really helpful as well, to answer the question "ok, I have a GenericsArgs list, how do I figure out which arg goes where".
The next page, https://rustc-dev-guide.rust-lang.org/ty-module/param-ty-const-regions.html implies that the answer is [u32, bool], by saying "right, references to generics are based on their flattened index, outermost generics first, inner next". Explicitly saying "hey, GenericArgs is a list of all parent scopes too, [u32, bool]" would make this much easier to understand (trying to understand this next page before realizing that is rough, haha).