Immediate suggestion: “generic value parameters”. At first glance, I thought this was about something like static<T> FOO: T; or something.
Also, to say this up front: I’m not an expert on the type inference Rust uses. Personally, I would want to see the RFC go into specifics on how this is going to impact the inference rules.
I think this proposal should probably stick to things that can be done without CTFE. If (hopefully when) Rust gets CTFE, it should be a reasonably natural expansion of this. Predicating anything here on CTFE just seems like a really bad idea in terms of defining something that is likely to be implemented.
For what it’s worth, it should be const. static implies storage, which in this case does not exist. A const doesn’t imply storage at all, so I feel it’s the correct keyword.
This should probably be let x = add_n::<3>(2);.
And that should be [f64; n]. Actually, it should probably be [f64; N] since the convention is to write constants in ALL_CAPS.
My only concern here is: how would this interact with variadic generics?
How do you propose to implement this without CTFE? This implies that I can do this:
#[derive(Eq)]
struct Blah(i32);
impl PartialEq for Blah {
fn eq(&self, other: &Blah) -> bool {
/* insert arbitrarily complex code here */
}
}
Also: whatever types are allowed, the compiler has to be able to serialise them as part of a symbol’s mangled name. This is why D limits them to (if I remember correctly) the basic atomic types, strings and maybe tuples and arrays thereof.
Aside: this led to people making templated types so complicated that the object file format couldn’t store the mangled name, which is why some D symbols are unreadable gibberish: I believe Walter ended up DEFLATE compressing them over a certain size! 
Another aside: it might be worth considering D’s concept of an alias. This could be used to basically pass a variable or function “by name”. You could use it to write generic wrappers around functions that allowed the compiler to use static dispatch. In Rust, the closest analogue I can think of would be something like a use param. Anyway…
You don’t need CTFE for this. You just need to be clear about what constant folding is supported. Honestly, I really like the idea, but I’m terrified about the possible implications. Because type inference in Rust goes both ways, I’m not sure there’s a difference in the two examples.
I mean, what do you do about N / 2? For most values, there’s going to be two possible values of N it could have been.
Yeah, I suspect the coherence checker would need to be very conservative, if this is even feasible.
- What, exactly, are the changes to the type inference algorithm?
- How does coherence work?
In addition, I’d like to see more examples, in terms of breadth and complexity. The application to fixed-size arrays is obvious, but what else could you do with it, practically speaking? I just feel like that for something which should be as useful as I want this to be, solid motivating examples should be abundant.
Closing thoughts: I want this, but I think this is skipping too many big, important, and hard details.