rust-lang / rust-lang/rust

Baffling suggestion labelled "help: try introducing a local generic parameter here"

Open
#141,872 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-const-generics A-diagnostics A-macros D-confusing D-invalid-suggestion E-needs-mcve T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
https://github.com/BLAKE3-team/BLAKE3 @ 60ed9295f58ba975df58a67b2bfe435f478d05ea +

diff --git a/benches/bench.rs b/benches/bench.rs
index e89f04c..ea21f3c 100644
--- a/benches/bench.rs
+++ b/benches/bench.rs
@@ -85,24 +85,24 @@ fn bench_single_compression_avx512(b: &mut Bencher) {
     }
 }
 
-fn bench_many_chunks_fn(b: &mut Bencher, platform: Platform) {
+fn bench_many_fn<const LEN: usize>(increment: blake3::IncrementCounter, b: &mut Bencher, platform: Platform) {
     let degree = platform.simd_degree();
     let mut inputs = Vec::new();
     for _ in 0..degree {
-        inputs.push(RandomInput::new(b, CHUNK_LEN));
+        inputs.push(RandomInput::new(b, LEN));
     }
     b.iter(|| {
-        let input_arrays: ArrayVec<&[u8; CHUNK_LEN], MAX_SIMD_DEGREE> = inputs
+        let input_arrays: ArrayVec<&[u8; LEN], MAX_SIMD_DEGREE> = inputs
             .iter_mut()
             .take(degree)
-            .map(|i| array_ref!(i.get(), 0, CHUNK_LEN))
+            .map(|i| array_ref!(i.get(), 0, LEN))
             .collect();
         let mut out = [0; MAX_SIMD_DEGREE * OUT_LEN];
         platform.hash_many(
             &input_arrays[..],
             &[0; 8],
             0,
-            blake3::IncrementCounter::Yes,
+            increment,
             0,
             0,
             0,
@@ -111,6 +111,10 @@ fn bench_many_chunks_fn(b: &mut Bencher, platform: Platform) {
     });
 }
 
+fn bench_many_chunks_fn(b: &mut Bencher, platform: Platform) {
+    bench_many_fn::<CHUNK_LEN>(blake3::IncrementCounter::Yes, b, platform)
+}
+
 #[bench]
 #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
 fn bench_many_chunks_sse2(b: &mut Bencher) {
@@ -155,31 +159,8 @@ fn bench_many_chunks_wasm(b: &mut Bencher) {
     bench_many_chunks_fn(b, Platform::wasm32_simd().unwrap());
 }
 
-// TODO: When we get const generics we can unify this with the chunks code.
 fn bench_many_parents_fn(b: &mut Bencher, platform: Platform) {
-    let degree = platform.simd_degree();
-    let mut inputs = Vec::new();
-    for _ in 0..degree {
-        inputs.push(RandomInput::new(b, BLOCK_LEN));
-    }
-    b.iter(|| {
-        let input_arrays: ArrayVec<&[u8; BLOCK_LEN], MAX_SIMD_DEGREE> = inputs
-            .iter_mut()
-            .take(degree)
-            .map(|i| array_ref!(i.get(), 0, BLOCK_LEN))
-            .collect();
-        let mut out = [0; MAX_SIMD_DEGREE * OUT_LEN];
-        platform.hash_many(
-            &input_arrays[..],
-            &[0; 8],
-            0,
-            blake3::IncrementCounter::No,
-            0,
-            0,
-            0,
-            &mut out,
-        );
-    });
+    bench_many_fn::<BLOCK_LEN>(blake3::IncrementCounter::No, b, platform)
 }
 
 #[bench]

+ `cargo bench`
Current output
error[E0401]: can't use generic parameters from outer item
  --> benches/bench.rs:98:45
   |
88 | fn bench_many_fn<const LEN: usize>(increment: blake3::IncrementCounter, b: &mut Bencher, platform: Platform) {
   |                        --- const parameter from outer item
...
98 |             .map(|i| array_ref!(i.get(), 0, LEN))
   |                      -----------------------^^^-
   |                      |                      |
   |                      |                      use of generic parameter from outer item
   |                      help: try introducing a local generic parameter here: `LEN,`
Desired output
idk
Rationale and extra context

This is baffling. Where does it want me to do this. What is this about.

Other cases

Rust Version
rustc 1.87.0 (17067e9ac 2025-05-09)
binary: rustc
commit-hash: 17067e9ac6d7ecb70e50f92c1944e545188d2359
commit-date: 2025-05-09
host: x86_64-unknown-linux-gnu
release: 1.87.0
LLVM version: 20.1.1
Anything else?

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the diagnostic with cargo bench using the code in benches/bench.rs, focusing on the array_ref!(i.get(), 0, LEN) call and its suggested local generic parameter. Trace the compiler diagnostic path that emits this message; done means the report is no longer baffling and points to an actionable location or explanation.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.