Closed
Description
Code
(hand-reduced)
#![feature(adt_const_params)]
#![allow(incomplete_features)]
use std::marker::ConstParamTy;
#[derive(Debug, PartialEq, Eq, ConstParamTy)]
struct Foo {
value: i32,
nested: &'static Bar<std::fmt::Debug>,
}
#[derive(Debug, PartialEq, Eq, ConstParamTy)]
struct Bar<T>(T);
struct Test<const F: Foo>;
fn main() {
let x: Test<
{
Foo {
value: 3,
nested: &Bar(4),
}
},
> = Test;
}
It seems that the above example may not be minimal, as it generates multiple errors.
(original)
trait A {
type Type;
const CONST: usize;
fn foo(&self);
}
trait B {
type ;
const CONST: usize;
fn foo(&self);
}
#[derive(Debug)]
struct S;
impl<T: std::fmt::Debug> A for T {
type Type = ();
const CONST: usize = 1; //~ NOTE candidate #1
fn foo(&self) {} //~ NOTE candidate #1
}
impl<T: std::fmt::Debug> B for T {
type Type = ();
const CONST: usize = 2; //~ NOTE candidate #2
fn foo(&self) {} //~ NOTE candidate #2
}
fn main() {
let s = S;
S::foo(&s); //~ ERROR multiple applicable items in scope
//~^ NOTE multiple `foo` found
//~| HELP use fully-qualified syntax to disambiguate
S::CONST; //~ ERROR multiple applicable items in scope
//~^ NOTE multiple `CONST` found
//~| HELP use fully-qualified syntax to disambiguate
let _: S::Type; //~ ERROR ambiguous associated type
//~^ HELP use fully-qualified syntax
}
#![feature(adt_const_params)]
#![allow(incomplete_features)]
use std::marker::ConstParamTy;
#[derive(Debug, PartialEq, Eq, ConstParamTy)]
struct Foo {
value: i32,
nested: &'static Bar<std::fmt::Debug>,
}
#[derive(Debug, PartialEq, Eq, ConstParamTy)]
struct Bar<T>(T);
struct Test<const F: Foo>;
fn main() {
let x: Test<{
Foo {
value: 3,
nested: &Bar(4),
}
}> = Test;
let y: Test<{
Foo {
value: 3,
nested: &Bar(5),
}
}> = x; //~ ERROR mismatched types
}
Meta
rustc --version --verbose
:
rustc 1.81.0-nightly (b5b13568f 2024-06-10)
binary: rustc
commit-hash: b5b13568fb5da4ac988bde370008d6134d3dfe6c
commit-date: 2024-06-10
host: x86_64-apple-darwin
release: 1.81.0-nightly
LLVM version: 18.1.7
Error output
Command: rustc
warning: trait objects without an explicit `dyn` are deprecated
--> r_write_imm_FF5A9D2D.rs:9:26
|
9 | nested: &'static Bar<std::fmt::Debug>,
| ^^^^^^^^^^^^^^^
|
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
= note: `#[warn(bare_trait_objects)]` on by default
help: if this is an object-safe trait, use `dyn`
|
9 | nested: &'static Bar<dyn std::fmt::Debug>,
| +++
error[E0277]: the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time
--> r_write_imm_FF5A9D2D.rs:9:13
|
9 | nested: &'static Bar<std::fmt::Debug>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `(dyn Debug + 'static)`
note: required by an implicit `Sized` bound in `Bar`
--> r_write_imm_FF5A9D2D.rs:13:12
|
13 | struct Bar<T>(T);
| ^ required by the implicit `Sized` requirement on this type parameter in `Bar`
help: you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box<T>`
--> r_write_imm_FF5A9D2D.rs:13:12
|
13 | struct Bar<T>(T);
| ^ - ...if indirection were used here: `Box<T>`
| |
| this could be changed to `T: ?Sized`...
error[E0204]: the trait `ConstParamTy` cannot be implemented for this type
--> r_write_imm_FF5A9D2D.rs:6:32
|
6 | #[derive(Debug, PartialEq, Eq, ConstParamTy)]
| ^^^^^^^^^^^^
...
9 | nested: &'static Bar<std::fmt::Debug>,
| ------------------------------------- this field does not implement `ConstParamTy`
|
note: the `ConstParamTy` impl for `&'static Bar<(dyn Debug + 'static)>` requires that `(dyn Debug + 'static): ConstParamTy`
--> r_write_imm_FF5A9D2D.rs:9:13
|
9 | nested: &'static Bar<std::fmt::Debug>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the `ConstParamTy` impl for `&'static Bar<(dyn Debug + 'static)>` requires that `(dyn Debug + 'static): Eq`
--> r_write_imm_FF5A9D2D.rs:9:13
|
9 | nested: &'static Bar<std::fmt::Debug>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the `ConstParamTy` impl for `&'static Bar<(dyn Debug + 'static)>` requires that `(dyn Debug + 'static): Sized`
--> r_write_imm_FF5A9D2D.rs:9:13
|
9 | nested: &'static Bar<std::fmt::Debug>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: this error originates in the derive macro `ConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time
--> r_write_imm_FF5A9D2D.rs:9:5
|
6 | #[derive(Debug, PartialEq, Eq, ConstParamTy)]
| ----- in this derive macro expansion
...
9 | nested: &'static Bar<std::fmt::Debug>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `(dyn Debug + 'static)`, which is required by `&&'static Bar<(dyn Debug + 'static)>: Debug`
= help: the trait `Debug` is implemented for `Bar<T>`
note: required for `Bar<(dyn Debug + 'static)>` to implement `Debug`
--> r_write_imm_FF5A9D2D.rs:12:10
|
12 | #[derive(Debug, PartialEq, Eq, ConstParamTy)]
| ^^^^^
13 | struct Bar<T>(T);
| - unsatisfied trait bound introduced in this `derive` macro
= note: 2 redundant requirements hidden
= note: required for `&&'static Bar<(dyn Debug + 'static)>` to implement `Debug`
= note: required for the cast from `&&&'static Bar<(dyn Debug + 'static)>` to `&dyn Debug`
= note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0369]: binary operation `==` cannot be applied to type `&Bar<dyn Debug>`
--> r_write_imm_FF5A9D2D.rs:9:5
|
6 | #[derive(Debug, PartialEq, Eq, ConstParamTy)]
| --------- in this derive macro expansion
...
9 | nested: &'static Bar<std::fmt::Debug>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `dyn Debug: Eq` is not satisfied
--> r_write_imm_FF5A9D2D.rs:9:5
|
6 | #[derive(Debug, PartialEq, Eq, ConstParamTy)]
| -- in this derive macro expansion
...
9 | nested: &'static Bar<std::fmt::Debug>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Eq` is not implemented for `dyn Debug`, which is required by `&'static Bar<dyn Debug>: Eq`
|
= help: the trait `Eq` is implemented for `Bar<T>`
note: required for `Bar<dyn Debug>` to implement `Eq`
--> r_write_imm_FF5A9D2D.rs:12:28
|
12 | #[derive(Debug, PartialEq, Eq, ConstParamTy)]
| ^^ unsatisfied trait bound introduced in this `derive` macro
= note: 1 redundant requirement hidden
= note: required for `&'static Bar<dyn Debug>` to implement `Eq`
note: required by a bound in `AssertParamIsEq`
--> /Users/jb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/cmp.rs:360:31
|
360 | pub struct AssertParamIsEq<T: Eq + ?Sized> {
| ^^ required by this bound in `AssertParamIsEq`
= note: this error originates in the derive macro `Eq` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the size for values of type `dyn Debug` cannot be known at compilation time
--> r_write_imm_FF5A9D2D.rs:9:5
|
6 | #[derive(Debug, PartialEq, Eq, ConstParamTy)]
| -- in this derive macro expansion
...
9 | nested: &'static Bar<std::fmt::Debug>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `dyn Debug`
note: required by an implicit `Sized` bound in `Bar`
--> r_write_imm_FF5A9D2D.rs:13:12
|
13 | struct Bar<T>(T);
| ^ required by the implicit `Sized` requirement on this type parameter in `Bar`
help: you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box<T>`
--> r_write_imm_FF5A9D2D.rs:13:12
|
13 | struct Bar<T>(T);
| ^ - ...if indirection were used here: `Box<T>`
| |
| this could be changed to `T: ?Sized`...
= note: this error originates in the derive macro `Eq` (in Nightly builds, run with -Z macro-backtrace for more info)
Backtrace
error: internal compiler error: compiler/rustc_const_eval/src/interpret/place.rs:710:21: write_immediate_to_mplace: invalid ScalarPair layout: TyAndLayout {
ty: &Bar<dyn Debug>,
layout: Layout {
size: Size(8 bytes),
align: AbiAndPrefAlign {
abi: Align(8 bytes),
pref: Align(8 bytes),
},
abi: Scalar(
Initialized {
value: Pointer(
AddressSpace(
0,
),
),
valid_range: 1..=18446744073709551615,
},
),
fields: Primitive,
largest_niche: Some(
Niche {
offset: Size(0 bytes),
value: Pointer(
AddressSpace(
0,
),
),
valid_range: 1..=18446744073709551615,
},
),
variants: Single {
index: 0,
},
max_repr_align: None,
unadjusted_abi_align: Align(8 bytes),
},
}
--> r_write_imm_FF5A9D2D.rs:20:13
|
20 | / Foo {
21 | | value: 3,
22 | | nested: &Bar(4),
23 | | }
| |_____________^
thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/place.rs:710:21:
Box<dyn Any>
stack backtrace:
0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
1: <rustc_errors::diagnostic::BugAbort as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
2: <rustc_errors::DiagCtxt>::span_bug::<rustc_span::span_encoding::Span, alloc::string::String>
3: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
4: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
5: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
6: rustc_middle::util::bug::span_bug_fmt::<rustc_span::span_encoding::Span>
7: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_const_eval::const_eval::machine::CompileTimeInterpreter>>::write_immediate_to_mplace_no_validate
8: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_const_eval::const_eval::machine::CompileTimeInterpreter>>::write_immediate_no_validate::<rustc_const_eval::interpret::place::PlaceTy>
9: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_const_eval::const_eval::machine::CompileTimeInterpreter>>::copy_op_no_validate::<rustc_const_eval::interpret::operand::OpTy, rustc_const_eval::interpret::place::PlaceTy>
10: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_const_eval::const_eval::machine::CompileTimeInterpreter>>::statement
11: rustc_const_eval::const_eval::eval_queries::eval_to_allocation_raw_provider
[... omitted 2 frames ...]
12: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::DefaultCache<rustc_middle::ty::ParamEnvAnd<rustc_middle::mir::interpret::GlobalId>, rustc_middle::query::erase::Erased<[u8; 24]>>>
13: rustc_const_eval::const_eval::valtrees::eval_to_valtree
14: <rustc_const_eval::provide::{closure#0} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_middle::ty::ParamEnvAnd<rustc_middle::mir::interpret::GlobalId>)>>::call_once
[... omitted 2 frames ...]
15: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::DefaultCache<rustc_middle::ty::ParamEnvAnd<rustc_middle::mir::interpret::GlobalId>, rustc_middle::query::erase::Erased<[u8; 24]>>>
16: <rustc_middle::ty::context::TyCtxt>::const_eval_global_id_for_typeck
17: <rustc_middle::ty::context::TyCtxt>::const_eval_resolve_for_typeck
18: <rustc_middle::ty::consts::Const>::eval
19: rustc_trait_selection::traits::util::with_replaced_escaping_bound_vars::<rustc_middle::ty::consts::Const, rustc_middle::ty::consts::Const, <rustc_trait_selection::traits::normalize::AssocTypeNormalizer as rustc_type_ir::fold::TypeFolder<rustc_middle::ty::context::TyCtxt>>::fold_const::{closure#0}>
20: <rustc_middle::ty::generic_args::GenericArg as rustc_type_ir::fold::TypeFoldable<rustc_middle::ty::context::TyCtxt>>::try_fold_with::<rustc_trait_selection::traits::normalize::AssocTypeNormalizer>
21: <&rustc_middle::ty::list::RawList<(), rustc_middle::ty::generic_args::GenericArg> as rustc_type_ir::fold::TypeFoldable<rustc_middle::ty::context::TyCtxt>>::try_fold_with::<rustc_trait_selection::traits::normalize::AssocTypeNormalizer>
22: <rustc_middle::ty::Ty as rustc_type_ir::fold::TypeSuperFoldable<rustc_middle::ty::context::TyCtxt>>::try_super_fold_with::<rustc_trait_selection::traits::normalize::AssocTypeNormalizer>
23: <rustc_infer::infer::at::At as rustc_trait_selection::traits::normalize::NormalizeExt>::normalize::<rustc_middle::ty::Ty>
24: <rustc_hir_typeck::fn_ctxt::FnCtxt>::normalize::<rustc_middle::ty::Ty>
25: <rustc_hir_typeck::fn_ctxt::FnCtxt as rustc_hir_analysis::hir_ty_lowering::HirTyLowerer>::record_ty
26: <dyn rustc_hir_analysis::hir_ty_lowering::HirTyLowerer>::lower_ty_common::{closure#0}
27: <rustc_hir_typeck::gather_locals::GatherLocalsVisitor>::declare
28: <rustc_hir_typeck::gather_locals::GatherLocalsVisitor as rustc_hir::intravisit::Visitor>::visit_local
29: <rustc_hir_typeck::gather_locals::GatherLocalsVisitor as rustc_hir::intravisit::Visitor>::visit_expr
30: rustc_hir_typeck::check::check_fn
31: rustc_hir_typeck::typeck
[... omitted 1 frame ...]
32: <rustc_middle::hir::map::Map>::par_body_owners::<rustc_hir_analysis::check_crate::{closure#4}>::{closure#0}
33: rustc_hir_analysis::check_crate
34: rustc_interface::passes::run_required_analyses
35: rustc_interface::passes::analysis
[... omitted 1 frame ...]
36: <rustc_interface::queries::QueryResult<&rustc_middle::ty::context::GlobalCtxt>>::enter::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}::{closure#1}::{closure#3}>
37: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
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: please attach the file at `/Volumes/T7/workspace/240607_100chaos_tree_combine_typ/icefiles/rustc-ice-2024-06-11T12_18_18-3341.txt` to your bug report
query stack during panic:
#0 [eval_to_allocation_raw] const-evaluating + checking `main::{constant#0}`
#1 [eval_to_valtree] evaluating type-level constant
#2 [typeck] type-checking `main`
#3 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 7 previous errors; 1 warning emitted
Some errors have detailed explanations: E0204, E0277, E0369.
For more information about an error, try `rustc --explain E0204`.
Notes
- ICE location:
rustc_const_eval/src/interpret/place.rs L710
rust/compiler/rustc_const_eval/src/interpret/place.rs
Lines 708 to 715 in b5b1356
- (might be) related issues can be found at github issue query "write_immediate_to_mplace"
- ICE triggering code is mutated from
tests/ui/const-generics/issue-66451.rs
@rustbot label +F-adt_const_params +requires-incomplete-features
Metadata
Metadata
Assignees
Labels
Category: This is a bug.`#![feature(adt_const_params)]`Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Status: This bug is tracked inside the repo by a `known-bug` test.Relevant to the compiler team, which will review and decide on the PR/issue.This issue requires the use of incomplete features.
Type
Projects
Status
Done