Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Malformed error message with wrong use of min const generics #77092

Closed
leonardo-m opened this issue Sep 23, 2020 · 0 comments · Fixed by #77093
Closed

Malformed error message with wrong use of min const generics #77092

leonardo-m opened this issue Sep 23, 2020 · 0 comments · Fixed by #77093
Labels
C-bug Category: This is a bug. const-generics-bad-diagnostics An error is correctly emitted, but is confusing, for `min_const_generics`.

Comments

@leonardo-m
Copy link

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
@leonardo-m leonardo-m added the C-bug Category: This is a bug. label Sep 23, 2020
@lcnr lcnr added const-generics-blocking const-generics-bad-diagnostics An error is correctly emitted, but is confusing, for `min_const_generics`. labels Sep 23, 2020
RalfJung added a commit to RalfJung/rust that referenced this issue Sep 26, 2020
…r=varkor

merge `need_type_info_err(_const)`

I hoped that this would automatically solve rust-lang#76737 but it doesn't quite seem like it

fixes rust-lang#77092

r? @varkor
@bors bors closed this as completed in ac8169d Sep 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. const-generics-bad-diagnostics An error is correctly emitted, but is confusing, for `min_const_generics`.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants