Skip to content

ICE when using const generics with associated items #70273

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
jendrikw opened this issue Mar 22, 2020 · 4 comments · Fixed by #70284
Closed

ICE when using const generics with associated items #70273

jendrikw opened this issue Mar 22, 2020 · 4 comments · Fixed by #70284
Assignees
Labels
A-associated-items Area: Associated items (types, constants & functions) 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.

Comments

@jendrikw
Copy link
Contributor

jendrikw commented Mar 22, 2020

Code

#![feature(const_generics)]

trait T<const A: usize> {
    type Item;
}
struct S;

impl<const A: usize> T<A> for S {
    type Item = i32;
}

fn main() {
    let _err: <S as T<0usize>>::Item;
}

Meta

rustc --version --verbose:

rustc 1.44.0-nightly (f509b26a7 2020-03-18)
binary: rustc
commit-hash: f509b26a7730d721ef87423a72b3fdf8724b4afa
commit-date: 2020-03-18
host: x86_64-unknown-linux-gnu
release: 1.44.0-nightly
LLVM version: 9.0

Error output

   Compiling bug v0.1.0 (/tmp/bug)
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
 --> src/main.rs:1:12
  |
1 | #![feature(const_generics)]
  |            ^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default

warning: Error finalizing incremental compilation session directory `/tmp/bug/target/debug/incremental/bug-19qm6gngth5a1/s-flslgmhmjy-18wc5w7-working`: No such file or directory (os error 2)

error: internal compiler error: mir_const_qualif: MIR had errors
  --> src/main.rs:13:23
   |
13 |     let _err: <S as T<0usize>>::Item;
   |                       ^^^^^^

error: internal compiler error: PromoteTemps: MIR had errors
  --> src/main.rs:13:23
   |
13 |     let _err: <S as T<0usize>>::Item;
   |                       ^^^^^^

error: internal compiler error: broken MIR in DefId(0:12 ~ bug[538c]::main[0]::{{constant}}[0]) ("return type"): bad type [type error]
  --> src/main.rs:13:23
   |
13 |     let _err: <S as T<0usize>>::Item;
   |                       ^^^^^^

error: internal compiler error: broken MIR in DefId(0:12 ~ bug[538c]::main[0]::{{constant}}[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:13:23: 13:29, scope: scope[0] } }): bad type [type error]
  --> src/main.rs:13:23
   |
13 |     let _err: <S as T<0usize>>::Item;
   |                       ^^^^^^

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:360: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.44.0-nightly (f509b26a7 2020-03-18) 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

error: could not compile `bug`.

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


Backtrace

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:360:17
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.heygears.com-1ecc6299db9ec823/backtrace-0.3.44/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.heygears.com-1ecc6299db9ec823/backtrace-0.3.44/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:78
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1069
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1427
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:198
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:218
  10: rustc_driver::report_ice
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:515
  12: std::panicking::begin_panic
  13: <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop
  14: core::ptr::drop_in_place
  15: <alloc::rc::Rc<T> as core::ops::drop::Drop>::drop
  16: core::ptr::drop_in_place
  17: rustc_interface::interface::run_compiler_in_existing_thread_pool

This issue has been assigned to @lcnr via this comment.

@jendrikw jendrikw 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 Mar 22, 2020
@jonas-schievink jonas-schievink added A-associated-items Area: Associated items (types, constants & functions) A-const-generics Area: const generics (parameters and arguments) F-const_generics `#![feature(const_generics)]` labels Mar 22, 2020
@jendrikw
Copy link
Contributor Author

managed to reduce the test case a bit.

@jendrikw
Copy link
Contributor Author

Also happens for this code using a function instead of an associated type:

Code

#![feature(const_generics)]

trait T<const A: usize> {
    fn f();
}
struct S;

impl T<0usize> for S {
    fn f() {}
}

fn main() {
    let _err = <S as T<0usize>>::f();
}

Error output

   Compiling bug v0.1.0 (/tmp/bug)
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
 --> src/main.rs:1:12
  |
1 | #![feature(const_generics)]
  |            ^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default

warning: Error finalizing incremental compilation session directory `/tmp/bug/target/debug/incremental/bug-19qm6gngth5a1/s-flslstafo1-1loj99m-working`: No such file or directory (os error 2)

error: internal compiler error: mir_const_qualif: MIR had errors
  --> src/main.rs:13:13
   |
13 |     <S as T<0usize>>::f();
   |             ^^^^^^

error: internal compiler error: PromoteTemps: MIR had errors
  --> src/main.rs:13:13
   |
13 |     <S as T<0usize>>::f();
   |             ^^^^^^

error: internal compiler error: broken MIR in DefId(0:12 ~ bug[538c]::main[0]::{{constant}}[0]) ("return type"): bad type [type error]
  --> src/main.rs:13:13
   |
13 |     <S as T<0usize>>::f();
   |             ^^^^^^

error: internal compiler error: broken MIR in DefId(0:12 ~ bug[538c]::main[0]::{{constant}}[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:13:13: 13:19, scope: scope[0] } }): bad type [type error]
  --> src/main.rs:13:13
   |
13 |     <S as T<0usize>>::f();
   |             ^^^^^^

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:360:17
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.heygears.com-1ecc6299db9ec823/backtrace-0.3.44/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.heygears.com-1ecc6299db9ec823/backtrace-0.3.44/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:78
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1069
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1427
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:198
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:218
  10: rustc_driver::report_ice
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:515
  12: std::panicking::begin_panic
  13: <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop
  14: core::ptr::drop_in_place
  15: <alloc::rc::Rc<T> as core::ops::drop::Drop>::drop
  16: core::ptr::drop_in_place
  17: rustc_interface::interface::run_compiler_in_existing_thread_pool
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose 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.44.0-nightly (f509b26a7 2020-03-18) 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

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

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

@lcnr
Copy link
Contributor

lcnr commented Mar 22, 2020

@rustbot claim

@lcnr
Copy link
Contributor

lcnr commented Mar 22, 2020

initial example fixed by #70223,
associated function fixed by #70276 #70284 instead

@Centril Centril added the requires-nightly This issue requires a nightly compiler in some way. label Mar 23, 2020
Centril added a commit to Centril/rust that referenced this issue Mar 24, 2020
…r=eddyb

correctly handle const params in type_of

extends rust-lang#70223, retry of rust-lang#70276

fixes rust-lang#70273

r? @eddyb cc @varkor
Centril added a commit to Centril/rust that referenced this issue Mar 24, 2020
…r=eddyb

correctly handle const params in type_of

extends rust-lang#70223, retry of rust-lang#70276

fixes rust-lang#70273

r? @eddyb cc @varkor
@bors bors closed this as completed in d309058 Mar 24, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) 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.
Projects
None yet
5 participants