6 ms·
I don't really understand why the ASTs need to be different. That is I don't really see why it's so different from fn a<T>(_: T) -> i32 { 0 } fn main() {
by edflsafoiewq 6y ago
I don't really understand why the ASTs need to be different. That is I don't really see why it's so different from
fn a<T>(_: T) -> i32 { 0 }
fn main() {
let a = |_: i32| 1;
let c = 0;
a(c);
}
except that a[b](c) requires that an expression can be a type.
- chrismorgan 6y agoAs I say, the particular example I used may not properly demonstrate the precise ambiguity after all (not certain), but the fact stands that Rust is unwilling to put something in its AST that might be a type or an expression. You must know at parse time whether it’s to be taken as a type or an expression. And semantically they’re quite different, as is always the case with types versus values: one is a function call with generic type parameters, which are resolved at compile time, while the other is doing indexing at run time, and then calling it. For them to have the same AST, even were it possible, would be making the AST hollow.