While developing crate using const_generics I found strange warning.
In method:
pub fn write_struct<T: ConstWriterAdapter>(writer: ConstWriter<T, 10>) -> ConstWriter<T, 0> {
writer.write_u16_le(34).write_u16_le(2).write_u16_le(3).write_u16_le(4).write_u16_le(5)
}
I got:
warning: cannot use constants which depend on generic parameters in types
--> src/lib.rs:493:12
|
| writer.write_u32_le(34).write_u16_le(2).write_u16_le(3).write_u16_le(4).write_u16_le(5)
| ^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #76200 <https://github.com/rust-lang/rust/issues/76200>
There are few questions:
- Why do I get this warning only in playground? Does playground uses some rustc flags? Or this is because I use rust on windows?
rustc 1.52.0-nightly (5fa22fe6f 2021-02-14)
binary: rustc
commit-hash: 5fa22fe6f821ac3801d05f624b123dda25fde32c
commit-date: 2021-02-14
host: x86_64-pc-windows-gnu
release: 1.52.0-nightly
LLVM version: 11.0.1
- After reading linked issue I didn't get how it's connected with my code.
You can check linked repo with lib or look at short definition there
pub struct ConstWriter<T: ConstWriterAdapter, const N: usize> {v: T}
impl<T: ConstWriterAdapter, const N: usize> ConstWriter<T, {N}> {
pub fn write_u32_le(self, value: u32) ->ConstWriter<T, {N - std::mem::size_of::<u32>()}> {
ConstWriter { v: self.v }
}
If this warning really connected with my code, can you please describe me how.