-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
C-bugCategory: This is a bug.Category: This is a bug.const-generics-bad-diagnosticsAn error is correctly emitted, but is confusing, for `min_const_generics`.An error is correctly emitted, but is confusing, for `min_const_generics`.
Description
This is wrong code (because there's no way to infer N):
#![feature(min_const_generics)]
use std::convert::TryInto;
#[inline(never)]
fn take_array_from_mut<T, const N: usize>(data: &mut [T], start: usize) -> &mut [T; N] {
(&mut data[start .. start + N]).try_into().unwrap()
}
fn main() {
let mut arr = [0, 1, 2, 3, 4, 5, 6, 7, 8];
for i in 1 .. 4 {
println!("{:?}", take_array_from_mut(&mut arr, i));
}
}
rustc V. 1.48.0-nightly 0da580074 2020-09-22
gives:
error[E0282]: type annotations needed
|
= note: unable to infer the value of a const parameter
error: aborting due to previous error
For more information about this error, try `rustc --explain E0282`.
Tool completed with exit code 1
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.const-generics-bad-diagnosticsAn error is correctly emitted, but is confusing, for `min_const_generics`.An error is correctly emitted, but is confusing, for `min_const_generics`.