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

const_generics ICE when propagating const parameter within inherent implementation #64537

Closed
CDirkx opened this issue Sep 17, 2019 · 4 comments
Closed
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. 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

@CDirkx
Copy link
Contributor

CDirkx commented Sep 17, 2019

The following compiles:

#![feature(const_generics)]

pub fn x<const I: usize>() {}
pub fn y<const I: usize>() {
    x::<{I}>();
}

playground

And so does:

#![feature(const_generics)]

struct S;

impl S {
    pub fn x() {}
    pub fn y<const I: usize>() {
        Self::x();
    }
}

playground

However, the following does not:

#![feature(const_generics)]

struct S;

impl S {
    pub fn x<const I: usize>() {}
    pub fn y<const I: usize>() {
        Self::x::<{I}>();
    }
}

playground

error: internal compiler error: unexpected const parent path Expr(expr(HirId { owner: DefIndex(17), local_id: 9 }: <Self>::x::<>))

error: internal compiler error: cat_expr Errd
 --> src\lib.rs:8:19
  |
8 |         Self::x::<{I}>();
  |                   ^^^

error: internal compiler error: mir_const_qualif: MIR had errors
 --> src\lib.rs:8:19
  |
8 |         Self::x::<{I}>();
  |                   ^^^

error: internal compiler error: QualifyAndPromoteConstants: MIR had errors
 --> src\lib.rs:8:19
  |
8 |         Self::x::<{I}>();
  |                   ^^^

error: internal compiler error: broken MIR in DefId(0:19 ~ reproduce[b9f9]::{{impl}}[0]::y[0]::{{constant}}[0]) ("return type"): bad type [type error]
 --> src\lib.rs:8:19
  |
8 |         Self::x::<{I}>();
  |                   ^^^

error: internal compiler error: broken MIR in DefId(0:19 ~ reproduce[b9f9]::{{impl}}[0]::y[0]::{{constant}}[0]) (LocalDecl { mutability: Mut, is_user_variable: None, internal: false, is_block_tail: None, ty: [type error], user_ty: UserTypeProjections { contents: [] }, name: None, source_info: SourceInfo { span: src\lib.rs:8:19: 8:22, scope: scope[0] }, visibility_scope: scope[0] }): bad type [type error]
 --> src\lib.rs:8:19
  |
8 |         Self::x::<{I}>();
  |                   ^^^

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src\librustc_errors\lib.rs:360:17
stack backtrace:
   0:     0x7ffaeae25aa9 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hb20333da0418f90f
   1:     0x7ffaeae541eb - core::fmt::write::he93a8f5e9fe72b9f
   2:     0x7ffaeae189a4 - <std::io::IoSliceMut as core::fmt::Debug>::fmt::hbe3650c5b670aece
   3:     0x7ffaeae2a080 - std::panicking::take_hook::hb08b66bde672a629
   4:     0x7ffaeae29caa - std::panicking::take_hook::hb08b66bde672a629
   5:     0x7ffacd165b1b - rustc_driver::report_ice::hcb418958ffca673b
   6:     0x7ffaeae2a8fd - std::panicking::rust_panic_with_hook::h7312cebf7b30fd61
   7:     0x7ffacee3a8d5 - rustc_errors::annotate_snippet_emitter_writer::AnnotateSnippetEmitterWriter::ui_testing::h250e4c9012a8a178
   8:     0x7ffacee1dbe2 - <rustc_errors::Handler as core::ops::drop::Drop>::drop::h4b24e07dbae1ad74
   9:     0x7ffacd1751c0 - <rustc_driver::Compilation as core::fmt::Debug>::fmt::h7e7b295ba58950ac
  10:     0x7ffacd17c266 - <rustc_driver::Compilation as core::fmt::Debug>::fmt::h7e7b295ba58950ac
  11:     0x7ffacd1331bc - <rustc_driver::args::Error as core::fmt::Debug>::fmt::h42f1798a01c1f811
  12:     0x7ffacd12cbb4 - <rustc_driver::args::Error as core::fmt::Debug>::fmt::h42f1798a01c1f811
  13:     0x7ffacd141ba6 - <rustc_driver::args::Error as core::fmt::Debug>::fmt::h42f1798a01c1f811
  14:     0x7ffacd167ed1 - <rustc_driver::Compilation as core::fmt::Debug>::fmt::h7e7b295ba58950ac
  15:     0x7ffacd184409 - <rustc_driver::Compilation as core::fmt::Debug>::fmt::h7e7b295ba58950ac
  16:     0x7ffacd0e513c - rustc_data_structures::graph::implementation::NodeIndex::node_id::h6bc48a6929e638bf
  17:     0x7ffaeae3c9c2 - _rust_maybe_catch_panic
  18:     0x7ffacd11e612 - <rustc_driver::pretty::UserIdentifiedItem as core::fmt::Debug>::fmt::haefe1a67821b54d1
  19:     0x7ffaeae07af7 - ZN244_$LT$std..error..$LT$impl$u20$core..convert..From$LT$alloc..string..String$GT$$u20$for$u20$alloc..boxed..Box$LT$dyn$u20$std..error..Error$u2b$core..marker..Send$u2b$core..marker..Sync$GT$$GT$..from..StringError$u20$as$u20$core..fmt..Display$GT$3fmt17
  20:     0x7ffaeae3a267 - std::sys::windows::thread::Thread::new::h5c25099711a7639e
  21:     0x7ffb281e4034 - BaseThreadInitThunk
  22:     0x7ffb28333691 - RtlUserThreadStart

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.
@csmoe csmoe added A-const-generics Area: const generics (parameters and arguments) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ labels Sep 17, 2019
@jonas-schievink jonas-schievink added C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. F-const_generics `#![feature(const_generics)]` requires-nightly This issue requires a nightly compiler in some way. labels Sep 17, 2019
@CDirkx CDirkx changed the title const_generics ICE when propagating const parameter within struct const_generics ICE when propagating const parameter within inherent implementation Sep 17, 2019
@CDirkx
Copy link
Contributor Author

CDirkx commented Sep 17, 2019

Updated title to reflect that the ICE occurs in all inherent implementations (struct, union, enum).

Trait implementations however, do compile:

#![feature(const_generics)]

struct S;

trait T {
    fn x<const I: usize>();
    fn y<const I: usize>();
}

impl T for S {
    fn x<const I: usize>() {}
    fn y<const I: usize>() {
        <S as T>::x::<{I}>()
    }
}

playground

Edit: when further experimenting: changing <S as T>::x::<{I}>() to S::x::<{I}>() again causes an ICE.
playground

@CDirkx
Copy link
Contributor Author

CDirkx commented Sep 17, 2019

Slightly reduced error case:

#![feature(const_generics)]

struct S;

impl S {
    pub fn x<const I: usize>() {}
    pub fn y() {
        Self::x::<{3usize}>();
    }
}

playground

@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Oct 15, 2019
@BenLewis-Seequent
Copy link

The cause of this bug is that to type check the expression Self::x::<{3usize}>() it must evaluate the constant, but to evaluate the constant it must know what function Self::x resolves to in able to know the type of the const parameter. Thus this is most likely blocked by lazy normalization(#60471) to avoid the cycle.

@lcnr
Copy link
Contributor

lcnr commented Jul 16, 2020

Fixed by #74113, we already have nearly identical tests here, so I am closing this without adding a regression test for this issue.

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. 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

No branches or pull requests

7 participants