Open frehberg opened 5 years ago
I would say that E0401 explains it fairly well, in the first sentence.
Inner items do not inherit type parameters from the functions they are embedded in.
And E0401 further explains it.
Items inside functions are basically just like top-level items, except that they can only be used from the function they are in.
const
is an item, so it cannot use a type parameter. As you don't require const
in this example, you may want to use let
instead.
That said, the hint is wrong, you cannot add a local type parameter in const
/static
, unlike pretty much any other item. It's possible that it will be possible to add a local type parameter to const
in the future, but it's not the future yet.
Sorry, but E0401 doesn't fit, as there is no such scoping or inner/outer present EDITED Maybe there is another hint, that could be presented instead.
It is interesting to see, how much effort it takes to cover with the compiler all different use cases. Thanks for the good work with Rust.
That seems like a duplicate of #45447, unless there is something I'm not understanding.
The following CDR-serde implementation defines functions to serialize data-types such as u16, u32 etc. It is using an abstract function to align write-position, to match with multiple of mem::size_of(), where T is a primitive int or float type.
As the bytesize is known at compile time, I would like to declare the value as const, using the following patch ://github.com/frehberg/cdr-rs/pull/1
but compiler yields with error
As the generic function is not exported by lib, and it is instanciated only from inside the crate, I am wondering why the compiler is not able to derive the type of parameter T.
Any idea?
EDIT the explanation of E0401 does not fit to this code