Closed
Description
This code
fn x<T: Default>() {
static a: T = T::default();
}
generates this error:
error[E0401]: can't use type parameters from outer function; try using a local type parameter instead
--> src/main.rs:2:15
|
2 | static a: T = T::default();
| ^ use of type variable from outer function
error[E0401]: can't use type parameters from outer function; try using a local type parameter instead
--> src/main.rs:2:19
|
2 | static a: T = T::default();
| ^^^^^^^^^^ use of type variable from outer function
error: aborting due to 2 previous errors
which is misleading because a local type parameter is being used.
The original message was different.
I have one question: why this is forbidden? There is an issue with some discussion but I do not see why this is not possible.
Using static with type parameters is very useful, for example, defining thread local buffer for store temporary results (like in a sorting algorithm).