Skip to content

ICE using const_generics_defaults #83938

Closed
@197g

Description

@197g

Code

#![crate_type = "lib"]
#![feature(const_evaluatable_checked, const_generics, const_generics_defaults)]
#![allow(incomplete_features)]

type NpOne<T, const N: usize, const NP: usize = {N+1usize}> = [T; NP];

pub fn push<T, const N: usize>(_: [T; N], _: T)
    -> NpOne<T, N>
{
    todo!()
}

(Playground link)

I'm not sure how to treat this. It seems that we can sneakily misuse defaults in type definitions to insert a dependent computation on a const parameter which definitely should be forbidden at the moment.

Meta

rustc --version --verbose:

 rustc 1.53.0-nightly (d32238532 2021-04-05) running on x86_64-unknown-linux-gnu

Error output

error: internal compiler error: broken MIR in DefId(0:9 ~ playground[e970]::push) (LocalDecl { mutability: Mut, local_info: None, internal: false, is_block_tail: None, ty: [type error], user_ty: None, source_info: SourceInfo { span: src/lib.rs:5:1: 6:19 (#0), scope: scope[0] } }): bad type [type error]
 --> src/lib.rs:5:1
  |
5 | / pub fn push<T, const N: usize>(_: [T; N], _: T)
6 | |     -> NpOne<T, N>
  | |__________________^
  |
  = note: delayed at compiler/rustc_mir/src/borrow_check/type_check/mod.rs:252:27

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler/rustc_errors/src/lib.rs:1018:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Backtrace

warning: the feature `const_generics_defaults` is incomplete and may not be safe to use and/or cause compiler crashes
 --> src/lib.rs:1:12
  |
1 | #![feature(const_generics_defaults)]
  |            ^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information

warning: 1 warning emitted

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler/rustc_typeck/src/check/expr.rs:473:21

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler/rustc_typeck/src/check/coercion.rs:154:49

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler/rustc_typeck/src/check/coercion.rs:868:53

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler/rustc_trait_selection/src/traits/project.rs:710:28

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler/rustc_infer/src/infer/sub.rs:124:31

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler/rustc_typeck/src/check/coercion.rs:1261:42

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler/rustc_typeck/src/check/fn_ctxt/checks.rs:714:27

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs:652:60

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at /rustc/d32238532138485c80db4f2cd596372bce214e00/compiler/rustc_middle/src/ty/relate.rs:334:59

error: internal compiler error: cat_expr Errd
 --> src/lib.rs:3:49
  |
3 | type NpOne<T, const N: usize, const NP: usize = {N+1usize}> = [T; NP];
  |                                                 ^^^^^^^^^^
  |
  = note: delayed at compiler/rustc_typeck/src/check/regionck.rs:402:31

error: internal compiler error: cat_expr Errd
 --> src/lib.rs:3:50
  |
3 | type NpOne<T, const N: usize, const NP: usize = {N+1usize}> = [T; NP];
  |                                                  ^^^^^^^^
  |
  = note: delayed at compiler/rustc_typeck/src/check/regionck.rs:402:31

error: internal compiler error: cat_expr Errd
 --> src/lib.rs:3:50
  |
3 | type NpOne<T, const N: usize, const NP: usize = {N+1usize}> = [T; NP];
  |                                                  ^
  |
  = note: delayed at compiler/rustc_typeck/src/check/regionck.rs:402:31

error: internal compiler error: ty::ConstKind::Error constructed but no error reported.
  |
  = note: delayed at /rustc/d32238532138485c80db4f2cd596372bce214e00/compiler/rustc_middle/src/ty/consts.rs:184:43

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at /rustc/d32238532138485c80db4f2cd596372bce214e00/compiler/rustc_trait_selection/src/opaque_types.rs:1007:32

error: internal compiler error: cat_expr Errd
 --> src/lib.rs:7:1
  |
7 | / {
8 | |     todo!()
9 | | }
  | |_^
  |
  = note: delayed at compiler/rustc_typeck/src/check/regionck.rs:402:31

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler/rustc_mir_build/src/build/mod.rs:742:18

error: internal compiler error: mir_const_qualif: MIR had errors
 --> src/lib.rs:3:49
  |
3 | type NpOne<T, const N: usize, const NP: usize = {N+1usize}> = [T; NP];
  |                                                 ^^^^^^^^^^
  |
  = note: delayed at compiler/rustc_mir/src/transform/mod.rs:237:18

error: internal compiler error: PromoteTemps: MIR had errors
 --> src/lib.rs:3:49
  |
3 | type NpOne<T, const N: usize, const NP: usize = {N+1usize}> = [T; NP];
  |                                                 ^^^^^^^^^^
  |
  = note: delayed at compiler/rustc_mir/src/transform/promote_consts.rs:55:22

error: internal compiler error: broken MIR in DefId(0:7 ~ playground[e970]::NpOne::{constant#0}) ("return type"): bad type [type error]
 --> src/lib.rs:3:49
  |
3 | type NpOne<T, const N: usize, const NP: usize = {N+1usize}> = [T; NP];
  |                                                 ^^^^^^^^^^
  |
  = note: delayed at compiler/rustc_mir/src/borrow_check/type_check/mod.rs:252:27

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler/rustc_mir/src/borrow_check/type_check/mod.rs:721:20

error: internal compiler error: broken MIR in DefId(0:7 ~ playground[e970]::NpOne::{constant#0}) (LocalDecl { mutability: Mut, local_info: None, internal: false, is_block_tail: None, ty: [type error], user_ty: None, source_info: SourceInfo { span: src/lib.rs:3:49: 3:59 (#0), scope: scope[0] } }): bad type [type error]
 --> src/lib.rs:3:49
  |
3 | type NpOne<T, const N: usize, const NP: usize = {N+1usize}> = [T; NP];
  |                                                 ^^^^^^^^^^
  |
  = note: delayed at compiler/rustc_mir/src/borrow_check/type_check/mod.rs:252:27

error: internal compiler error: PromoteTemps: MIR had errors
 --> src/lib.rs:5:1
  |
5 | / pub fn push<T, const N: usize>(_: [T; N], _: T)
6 | |     -> NpOne<T, N>
  | |__________________^
  |
  = note: delayed at compiler/rustc_mir/src/transform/promote_consts.rs:55:22

error: internal compiler error: broken MIR in DefId(0:9 ~ playground[e970]::push) ("return type"): bad type [type error]
 --> src/lib.rs:5:1
  |
5 | / pub fn push<T, const N: usize>(_: [T; N], _: T)
6 | |     -> NpOne<T, N>
  | |__________________^
  |
  = note: delayed at compiler/rustc_mir/src/borrow_check/type_check/mod.rs:252:27

error: internal compiler error: broken MIR in DefId(0:9 ~ playground[e970]::push) (LocalDecl { mutability: Mut, local_info: None, internal: false, is_block_tail: None, ty: [type error], user_ty: None, source_info: SourceInfo { span: src/lib.rs:5:1: 6:19 (#0), scope: scope[0] } }): bad type [type error]
 --> src/lib.rs:5:1
  |
5 | / pub fn push<T, const N: usize>(_: [T; N], _: T)
6 | |     -> NpOne<T, N>
  | |__________________^
  |
  = note: delayed at compiler/rustc_mir/src/borrow_check/type_check/mod.rs:252:27

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler/rustc_errors/src/lib.rs:1018:13
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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.53.0-nightly (d32238532 2021-04-05) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type lib

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
error: could not compile `playground`

To learn more, run the command again with --verbose.

Metadata

Metadata

Assignees

Labels

A-const-genericsArea: const generics (parameters and arguments)C-bugCategory: This is a bug.F-const_generics`#![feature(const_generics)]`F-const_generics_defaults`#![feature(const_generics_defaults)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions