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 w/ const_generics when trying to use the size of an associated type size as an array length #67739

Closed
petertodd opened this issue Dec 30, 2019 · 3 comments · Fixed by #69966
Labels
A-const-generics Area: const generics (parameters and arguments) A-lazy-normalization Area: lazy normalization (tracking issue: #60471) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. 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

@petertodd
Copy link
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.

@JohnTitor JohnTitor added A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` 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. labels Dec 31, 2019
@csmoe csmoe added the A-lazy-normalization Area: lazy normalization (tracking issue: #60471) label Jan 1, 2020
@Aaron1011
Copy link
Member

I believe this should be fixed by #67800

@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Jan 5, 2020
@JohnTitor
Copy link
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
Copy link
Member

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

@JohnTitor JohnTitor added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Mar 12, 2020
Centril added a commit to Centril/rust that referenced this issue Mar 13, 2020
@bors bors closed this as completed in 93da9d7 Mar 13, 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) A-lazy-normalization Area: lazy normalization (tracking issue: #60471) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. 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.

5 participants