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: unexpected const arg parent in type_of() #128176

Closed
matthiaskrgr opened this issue Jul 25, 2024 · 1 comment · Fixed by #133610
Closed

ICE: unexpected const arg parent in type_of() #128176

matthiaskrgr opened this issue Jul 25, 2024 · 1 comment · Fixed by #133610
Labels
C-bug Category: This is a bug. F-dyn_compatible_for_dispatch `#![feature(dyn_compatible_for_dispatch)]`; formerly `object_safe_for_ispatch` F-generic_const_exprs `#![feature(generic_const_exprs)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

#![feature(generic_const_exprs)]
#![feature(object_safe_for_dispatch)]
trait X {
    type Y<const N: i16>;
}

const _: () = {
    fn f2<'a>(arg: Box<dyn X<Y<1> = &'a ()>>) {}
};

fn main() {}

original:

#![feature(generic_const_exprs)]
#![allow(bar_to, bar_from)]

trait X {
    type Y<const N: i16>;
}

const _: () = {
    fn f2<'a>(arg: Box<dyn X<Y<1> = &'a ()>>) {}
    //~^ ERROR associated type takes 1 lifetime argument but 0 lifetime arguments
    //~| ERROR associated type takes 0 generic arguments but 1 generic argument
    //~| ERROR associated type takes 1 lifetime argument but 0 lifetime arguments
    //~| ERROR associated type takes 0 generic arguments but 1 generic argument
    //~| ERROR associated type takes 1 lifetime argument but 0 lifetime arguments
    //~| ERROR associated type takes 0 generic arguments but 1 generic argument
    //~| ERROR `X` cannot be made into an object
};

fn main() {}

Version information

rustc 1.82.0-nightly (004e155c4 2024-07-25)
binary: rustc
commit-hash: 004e155c46a2083d4f73212cc47a6f7fb98fcbd1
commit-date: 2024-07-25
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 18.1.7

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zcrate-attr=feature(object_safe_for_dispatch)

Program output

warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /tmp/icemaker_global_tempdir.IthovrlrGpyV/rustc_testrunner_tmpdir_reporting.lRekHjsPjvYq/mvce.rs:1:12
  |
1 | #![feature(generic_const_exprs)]
  |            ^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
  = note: `#[warn(incomplete_features)]` on by default

warning: unused variable: `arg`
 --> /tmp/icemaker_global_tempdir.IthovrlrGpyV/rustc_testrunner_tmpdir_reporting.lRekHjsPjvYq/mvce.rs:8:15
  |
8 |     fn f2<'a>(arg: Box<dyn X<Y<1> = &'a ()>>) {}
  |               ^^^ help: if this is intentional, prefix it with an underscore: `_arg`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: trait `X` is never used
 --> /tmp/icemaker_global_tempdir.IthovrlrGpyV/rustc_testrunner_tmpdir_reporting.lRekHjsPjvYq/mvce.rs:3:7
  |
3 | trait X {
  |       ^
  |
  = note: `#[warn(dead_code)]` on by default

warning: 3 warnings emitted

note: no errors encountered even though delayed bugs were created

note: those delayed bugs will now be shown as internal compiler errors

error: internal compiler error: unexpected const arg parent in type_of(): AssocItemConstraint(AssocItemConstraint { hir_id: HirId(DefId(0:7 ~ mvce[807a]::_::f2).13), ident: Y#0, gen_args: GenericArgs { args: [Const(ConstArg { hir_id: HirId(DefId(0:7 ~ mvce[807a]::_::f2).9), kind: Anon(AnonConst { hir_id: HirId(DefId(0:7 ~ mvce[807a]::_::f2).7), def_id: DefId(0:9 ~ mvce[807a]::_::f2::{constant#0}), body: BodyId { hir_id: HirId(DefId(0:7 ~ mvce[807a]::_::f2).8) }, span: /tmp/icemaker_global_tempdir.IthovrlrGpyV/rustc_testrunner_tmpdir_reporting.lRekHjsPjvYq/mvce.rs:8:32: 8:33 (#0) }), is_desugared_from_effects: false })], constraints: [], parenthesized: No, span_ext: /tmp/icemaker_global_tempdir.IthovrlrGpyV/rustc_testrunner_tmpdir_reporting.lRekHjsPjvYq/mvce.rs:8:31: 8:34 (#0) }, kind: Equality { term: Ty(Ty { hir_id: HirId(DefId(0:7 ~ mvce[807a]::_::f2).12), kind: Ref(Lifetime { hir_id: HirId(DefId(0:7 ~ mvce[807a]::_::f2).10), ident: 'a#0, res: Param(DefId(0:8 ~ mvce[807a]::_::f2::'a)) }, MutTy { ty: Ty { hir_id: HirId(DefId(0:7 ~ mvce[807a]::_::f2).11), kind: Tup([]), span: /tmp/icemaker_global_tempdir.IthovrlrGpyV/rustc_testrunner_tmpdir_reporting.lRekHjsPjvYq/mvce.rs:8:41: 8:43 (#0) }, mutbl: Not }), span: /tmp/icemaker_global_tempdir.IthovrlrGpyV/rustc_testrunner_tmpdir_reporting.lRekHjsPjvYq/mvce.rs:8:37: 8:43 (#0) }) }, span: /tmp/icemaker_global_tempdir.IthovrlrGpyV/rustc_testrunner_tmpdir_reporting.lRekHjsPjvYq/mvce.rs:8:30: 8:43 (#0) })
 --> /tmp/icemaker_global_tempdir.IthovrlrGpyV/rustc_testrunner_tmpdir_reporting.lRekHjsPjvYq/mvce.rs:8:32
  |
8 |     fn f2<'a>(arg: Box<dyn X<Y<1> = &'a ()>>) {}
  |                                ^
  |
note: delayed at compiler/rustc_hir_analysis/src/collect/type_of.rs:276:20 - disabled backtrace
 --> /tmp/icemaker_global_tempdir.IthovrlrGpyV/rustc_testrunner_tmpdir_reporting.lRekHjsPjvYq/mvce.rs:8:32
  |
8 |     fn f2<'a>(arg: Box<dyn X<Y<1> = &'a ()>>) {}
  |                                ^

error: internal compiler error: Const::from_anon_const: couldn't lit_to_const TypeError
 --> /tmp/icemaker_global_tempdir.IthovrlrGpyV/rustc_testrunner_tmpdir_reporting.lRekHjsPjvYq/mvce.rs:8:32
  |
8 |     fn f2<'a>(arg: Box<dyn X<Y<1> = &'a ()>>) {}
  |                                ^
  |
note: delayed at compiler/rustc_middle/src/ty/consts.rs:309:31 - disabled backtrace
 --> /tmp/icemaker_global_tempdir.IthovrlrGpyV/rustc_testrunner_tmpdir_reporting.lRekHjsPjvYq/mvce.rs:8:32
  |
8 |     fn f2<'a>(arg: Box<dyn X<Y<1> = &'a ()>>) {}
  |                                ^

error: internal compiler error: Trying to feed an already recorded value for query type_of key=DefId(0:9 ~ mvce[807a]::_::f2::{constant#0}):
                                old value: EarlyBinder { value: {type error} }
                                new value: EarlyBinder { value: i16 }
  |
  = note: delayed at compiler/rustc_middle/src/query/mod.rs:2294:1 - disabled backtrace

error: internal compiler error: mir_const_qualif: MIR had errors
 --> /tmp/icemaker_global_tempdir.IthovrlrGpyV/rustc_testrunner_tmpdir_reporting.lRekHjsPjvYq/mvce.rs:8:32
  |
8 |     fn f2<'a>(arg: Box<dyn X<Y<1> = &'a ()>>) {}
  |                                ^
  |
note: delayed at compiler/rustc_mir_transform/src/lib.rs:271:19 - disabled backtrace
 --> /tmp/icemaker_global_tempdir.IthovrlrGpyV/rustc_testrunner_tmpdir_reporting.lRekHjsPjvYq/mvce.rs:8:32
  |
8 |     fn f2<'a>(arg: Box<dyn X<Y<1> = &'a ()>>) {}
  |                                ^

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: please make sure that you have updated to the latest nightly

note: rustc 1.82.0-nightly (004e155c4 2024-07-25) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z crate-attr=feature(object_safe_for_dispatch) -Z dump-mir-dir=dir

query stack during panic:
end of query stack

@rustbot label +F-generic_const_exprs +F-object_safe_for_dispatch

@matthiaskrgr matthiaskrgr added 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. C-bug Category: This is a bug. labels Jul 25, 2024
@rustbot rustbot added needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. F-generic_const_exprs `#![feature(generic_const_exprs)]` F-dyn_compatible_for_dispatch `#![feature(dyn_compatible_for_dispatch)]`; formerly `object_safe_for_ispatch` labels Jul 25, 2024
@matthiaskrgr
Copy link
Member Author

#126620

@Noratrieb Noratrieb removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 5, 2024
@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Aug 5, 2024
bors added a commit to rust-lang-ci/rust that referenced this issue Nov 29, 2024
Move `Const::{from_anon_const,try_from_lit}` to hir_ty_lowering

Fixes rust-lang#128176.
This accomplishes one of the followup items from rust-lang#131081.

These operations are much more about lowering the HIR than about
`Const`s themselves. They fit better in hir_ty_lowering with
`lower_const_arg` (formerly `Const::from_const_arg`) and the rest.

To accomplish this, `const_evaluatable_predicates_of` had to be changed
to not use `from_anon_const` anymore. Instead of visiting the HIR and
lowering anon consts on the fly, it now visits the `rustc_middle::ty`
data structures instead and directly looks for `UnevaluatedConst`s. This
approach was proposed in:
rust-lang#131081 (comment)

r? `@BoxyUwU`
@bors bors closed this as completed in 6f0d15a Dec 3, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Dec 3, 2024
Rollup merge of rust-lang#133610 - camelid:move-from_anon_const, r=BoxyUwU

Move `Const::{from_anon_const,try_from_lit}` to hir_ty_lowering

Fixes rust-lang#128176.
This accomplishes one of the followup items from rust-lang#131081.

These operations are much more about lowering the HIR than about
`Const`s themselves. They fit better in hir_ty_lowering with
`lower_const_arg` (formerly `Const::from_const_arg`) and the rest.

To accomplish this, `const_evaluatable_predicates_of` had to be changed
to not use `from_anon_const` anymore. Instead of visiting the HIR and
lowering anon consts on the fly, it now visits the `rustc_middle::ty`
data structures instead and directly looks for `UnevaluatedConst`s. This
approach was proposed in:
rust-lang#131081 (comment)

r? `@BoxyUwU`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-dyn_compatible_for_dispatch `#![feature(dyn_compatible_for_dispatch)]`; formerly `object_safe_for_ispatch` F-generic_const_exprs `#![feature(generic_const_exprs)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. 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.

3 participants