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

[ICE] with const generics array #71169

Closed
leonardo-m opened this issue Apr 15, 2020 · 1 comment · Fixed by #74159
Closed

[ICE] with const generics array #71169

leonardo-m opened this issue Apr 15, 2020 · 1 comment · Fixed by #74159
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@leonardo-m
Copy link

#![feature(const_generics)]
#![allow(incomplete_features)]
fn foo<const LEN: usize, const DATA: [u8; LEN]>() {}
fn main() {
    const DATA: [u8; 4] = *b"ABCD";
    foo::<4, DATA>();
}

Gives:

error: internal compiler error: src\librustc_middle\ty\subst.rs:613: const parameter `LEN/#0` (Const { ty: usize, val: Param(LEN/#0) }/0) out of range when substituting substs=[]

thread 'rustc' panicked at 'Box<Any>', /rustc/edc02580e4e80476ac1ded2cc1008eaf8b8400e6\src\libstd\macros.rs:13:23
...

note: rustc 1.44.0-nightly (edc02580e 2020-04-14) running on x86_64-pc-windows-gnu

query stack during panic:
#0 [resolve_instance] resolving instance `DefId(0:11 ~ const_text_test[317d]::main[0]::{{constant}}[1])` `[]` with ParamEnv { caller_bounds: [], reveal: All, def_id: None }
#1 [typeck_tables_of] type-checking `main`
#2 [typeck_item_bodies] type-checking all item bodies
#3 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error
@leonardo-m leonardo-m added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 15, 2020
@jonas-schievink jonas-schievink added A-const-generics Area: const generics (parameters and arguments) F-const_generics `#![feature(const_generics)]` requires-nightly This issue requires a nightly compiler in some way. labels Apr 15, 2020
@elichai
Copy link
Contributor

elichai commented Apr 15, 2020

I assume this is the same as: https://play.rust-lang.org/?&gist=485702f1094102226682c7e28f1c848d

use std::mem::size_of;
use std::marker::PhantomData;

struct Raw<T: ?Sized> {
    d: [u8; size_of::<&T>()],
    _p: PhantomData<T>,
}

and: #43408 (comment)

@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Apr 16, 2020
lcnr added a commit to lcnr/rust that referenced this issue Jul 16, 2020
Manishearth added a commit to Manishearth/rust that referenced this issue Jul 16, 2020
forbid generic params in the type of const params

implements and closes rust-lang#74152

fixes rust-lang#74101, closes rust-lang#71169, fixes rust-lang#73491, closes rust-lang#62878

@eddyb and I talked [on zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/type.20of.20const.20parameters/near/203405696) about this and we probably want to also forbid generic consts in the default
type of a parameter, e.g. `struct Foo<T, U = [u8; std::mem::size_of::<T>()]>`, this is currently still allowed
and I will probably fix that in a followup PR.

r? @varkor @eddyb
Manishearth added a commit to Manishearth/rust that referenced this issue Jul 16, 2020
forbid generic params in the type of const params

implements and closes rust-lang#74152

fixes rust-lang#74101, closes rust-lang#71169, fixes rust-lang#73491, closes rust-lang#62878

@eddyb and I talked [on zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/type.20of.20const.20parameters/near/203405696) about this and we probably want to also forbid generic consts in the default
type of a parameter, e.g. `struct Foo<T, U = [u8; std::mem::size_of::<T>()]>`, this is currently still allowed
and I will probably fix that in a followup PR.

r? @varkor @eddyb
@bors bors closed this as completed in 6ef0dfa Jul 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants