Closed
Description
Given the following test and nightly 2020-01-12:
#![allow(unused)]
#![feature(const_generics)]
trait Child {
const N: usize;
}
struct C1;
impl Child for C1 {
const N: usize = 2;
}
struct Main<C: Child> {
c: C
}
impl<C: Child> Main<C> {
fn test() -> [u8; C::N] {
[0; C::N]
}
}
I get that this is not supposed to work without const generics, but the error message suggestion is very funny:
error[E0599]: no associated item named `N` found for type parameter `C` in the current scope
--> src/main.rs:22:27
|
22 | fn test2() -> [u8; C::N] {
| ^ associated item not found in `C`
|
= help: items from traits can only be used if the type parameter is bounded by the trait
help: the following trait defines an item `N`, perhaps you need to restrict type parameter `C` with it:
|
17 | impl<C: Child + Child> Main<C> {
| ^^^^^^^^^^
With const generics:
warning: Error finalizing incremental compilation session directory `/home/gbr/devel/rust-test/target/debug/incremental/rust_test-xwudz02f6bay/s-fjpbjlpyxj-1ihvwt0-working`: No such file or directory (os error 2)
error: internal compiler error: cat_expr Errd
--> src/main.rs:22:30
|
22 | fn test2() -> [u8; C::N] {
| ______________________________^
23 | | [0; C::N]
24 | | }
| |_____^
error: internal compiler error: cat_expr Errd
--> src/main.rs:23:9
|
23 | [0; C::N]
| ^^^^^^^^^
error: internal compiler error: PromoteTemps: MIR had errors
--> src/main.rs:22:5
|
22 | / fn test2() -> [u8; C::N] {
23 | | [0; C::N]
24 | | }
| |_____^
error: internal compiler error: broken MIR in DefId(0:16 ~ rust_test[3df1]::{{impl}}[1]::test2[0]) ("return type"): bad type [type error]
--> src/main.rs:22:5
|
22 | / fn test2() -> [u8; C::N] {
23 | | [0; C::N]
24 | | }
| |_____^
error: internal compiler error: broken MIR in DefId(0:16 ~ rust_test[3df1]::{{impl}}[1]::test2[0]) (LocalDecl { mutability: Mut, local_info: Other, internal: false, is_block_tail: None, ty: [type error], user_ty: UserTypeProjections { contents: [] }, source_info: SourceInfo { span: src/main.rs:22:5: 24:6, scope: scope[0] } }): bad type [type error]
--> src/main.rs:22:5
|
22 | / fn test2() -> [u8; C::N] {
23 | | [0; C::N]
24 | | }
| |_____^
thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:346:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: rustc 1.42.0-nightly (3ebcfa145 2020-01-12) running on x86_64-unknown-linux-gnu
note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin
note: some of the compiler flags provided by cargo are hidden
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsCategory: This is a bug.Diagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: A structured suggestion resulting in incorrect code.Relevant to the compiler team, which will review and decide on the PR/issue.ICE tracked in rust-lang/glacier.