Skip to content

ICE w/ const_generics when trying to use the size of an associated type size as an array length #67739

@petertodd

Description

@petertodd
Contributor
#![allow(incomplete_features)]
#![feature(const_generics)]

use std::mem;

pub trait Trait {
    type Associated : Sized;

    fn associated_size(&self) -> usize {
        [0u8; mem::size_of::<Self::Associated>()];
        0   
    }   
}

fn main() {
}

results in:

error: internal compiler error: src/librustc_traits/normalize_erasing_regions.rs:34: could not fully normalize `fn() -> usize {std::mem::size_of::<<Self as Trait>::Associated>}`

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:889:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

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 (da3629b05 2019-12-29) running on x86_64-unknown-linux-gnu

error: aborting due to previous error

Removing the const_generics feature flag gets the expected error message:

error[E0220]: associated type `Associated` not found for `Self`
  --> normalize-err.rs:10:36
   |
10 |         [0u8; mem::size_of::<Self::Associated>()];
   |                                    ^^^^^^^^^^ associated type `Associated` not found

error: aborting due to previous error

For more information about this error, try `rustc --explain E0220`.

(IIUC that itself is a bug related to #43408)

Using mem::size_of::<Self::Associated>() directly outside of a const-context works, which I guess is something const_generics enables that isn't otherwise allowed.

Finally, the error message is the same whether or not the code is in a provided method or a impl block; I actually ran into the bug in the later.

Activity

added
A-const-genericsArea: const generics (parameters and arguments)
C-bugCategory: This is a bug.
I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
requires-nightlyThis issue requires a nightly compiler in some way.
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Dec 31, 2019
Aaron1011

Aaron1011 commented on Jan 3, 2020

@Aaron1011
Member

I believe this should be fixed by #67800

JohnTitor

JohnTitor commented on Mar 9, 2020

@JohnTitor
Member

Now, it shows different ICE(s) (playground):

error: internal compiler error: cat_expr Errd
error: internal compiler error: cat_expr Errd
error: internal compiler error: PromoteTemps: MIR had errors
error: internal compiler error: broken MIR in DefId(0:6 ~ playground[a80e]::Trait[0]::associated_size[0]) ("return type"): bad type [type error]
error: internal compiler error: broken MIR in DefId(0:6 ~ playground[a80e]::Trait[0]::associated_size[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:9:5: 12:6, scope: scope[0] } }): bad type [type error]

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:355:17
JohnTitor

JohnTitor commented on Mar 12, 2020

@JohnTitor
Member

Now ICE no longer occurs. I think it's fixed by #69859.

added
E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.
on Mar 12, 2020
added a commit that references this issue on Mar 13, 2020
0a32d24
added a commit that references this issue on Mar 13, 2020
93da9d7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)A-lazy-normalizationArea: Lazy normalization (tracking issue: #60471)C-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.F-const_generics`#![feature(const_generics)]`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.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @petertodd@Aaron1011@JohnTitor@csmoe@rust-lang-glacier-bot

      Issue actions

        ICE w/ const_generics when trying to use the size of an associated type size as an array length · Issue #67739 · rust-lang/rust