Can't understand warning when using const_evaluatable_checked

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:

  1. 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
  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.

Since these features are still under active development, you might also want to ask questions like this on Zulip in the #project-const-generics stream.

Could you share a link to that Playground snippet? I haven't been able to reproduce that warning even when testing multiple versions of the nightly toolchain (on macOS though):

  • On old versions (before const_evaluatable_checked) get an error;

  • Starting from 1.48.0 all the versions pass without any warning.

So it may be something that is Windows-specific, or commit specific; in all cases, being able to reproduce the problem would be quite helpful :slightly_smiling_face:

1 Like

playground there is a bunch of code

1 Like

Minimized this code by dropping unused parts: playground. No ideas what went wrong, though.

2 Likes

I have investigated this a bit further, and submitted a report on the associated tracking issue.

From a recent comment there, it appears this warning (and the erroring variants) are not intended / a bug :slightly_smiling_face:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.