rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.2k stars 12.7k forks source link

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

Open matthiaskrgr opened 3 months ago

matthiaskrgr commented 3 months ago

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 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 = &'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 = &'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 = &'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 = &'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 = &'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 = &'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 = &'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 commented 3 months ago

126620