rust-lang / rust

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

ICE: `unsize_into: invalid conversion` in `rustc_const_eval/src/interpret/cast.rs` #126269

Open cushionbadak opened 3 months ago

cushionbadak commented 3 months ago

Code

(hand-reduced)

#![feature(coerce_unsized)]

pub enum Foo<T> {
    Bar([T; usize::MAX]),
}

use std::ops::CoerceUnsized;

impl<T, U> CoerceUnsized<U> for T {}

fn main() {}
(original)

```Rust // Make sure the compiler does not ICE when trying to generate the debuginfo name of a type that // causes a layout error. // This version of the test already ICE'd before the commit that introduce the ICE described in // https://github.com/rust-lang/rust/issues/94961. //@ compile-flags:-C debuginfo=2 //@ build-fail //@ error-pattern: too big for the current architecture //@ normalize-stderr-64bit "18446744073709551615" -> "SIZE" //@ normalize-stderr-32bit "4294967295" -> "SIZE" #![crate_type = "rlib"] pub enum Foo { Bar([T; usize::MAX]), } pub fn foo() -> usize { std::mem::size_of::>() } #![feature(coerce_unsized)] use std::ops::CoerceUnsized; struct Foo { a: T, } impl CoerceUnsized for T {} //~ ERROR E0376 fn main() {} ```

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

<output>
Backtrace

``` error: internal compiler error: compiler/rustc_const_eval/src/interpret/cast.rs:476:17: unsize_into: invalid conversion: TyAndLayout { ty: usize, layout: Layout { size: Size(8 bytes), align: AbiAndPrefAlign { abi: Align(8 bytes), pref: Align(8 bytes) }, abi: Scalar(Initialized { value: Int(I64, false), valid_range: 0..=18446744073709551615 }), fields: Primitive, largest_niche: None, variants: Single { index: 0 }, max_repr_align: None, unadjusted_abi_align: Align(8 bytes) } } -> TyAndLayout { ty: usize, layout: Layout { size: Size(8 bytes), align: AbiAndPrefAlign { abi: Align(8 bytes), pref: Align(8 bytes) }, abi: Scalar(Initialized { value: Int(I64, false), valid_range: 0..=18446744073709551615 }), fields: Primitive, largest_niche: None, variants: Single { index: 0 }, max_repr_align: None, unadjusted_abi_align: Align(8 bytes) } } --> r_unsize_into_5CF554F2.rs:4:13 | 4 | Bar([T; usize::MAX]), | ^^^^^^^^^^ thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/cast.rs:476:17: Box stack backtrace: 0: std::panicking::begin_panic:: 1: ::emit_producing_guarantee 2: ::span_bug:: 3: rustc_middle::util::bug::opt_span_bug_fmt::::{closure#0} 4: rustc_middle::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0} 5: rustc_middle::ty::context::tls::with_context_opt::::{closure#0}, !>::{closure#0}, !> 6: rustc_middle::util::bug::span_bug_fmt:: 7: >::unsize_into 8: >::statement 9: rustc_const_eval::const_eval::eval_queries::eval_to_allocation_raw_provider [... omitted 2 frames ...] 10: rustc_middle::query::plumbing::query_get_at::, rustc_middle::query::erase::Erased<[u8; 24]>>> 11: rustc_const_eval::const_eval::valtrees::eval_to_valtree 12: )>>::call_once [... omitted 2 frames ...] 13: rustc_middle::query::plumbing::query_get_at::, rustc_middle::query::erase::Erased<[u8; 24]>>> 14: ::const_eval_global_id_for_typeck 15: ::const_eval_resolve_for_typeck 16: ::eval 17: rustc_trait_selection::traits::util::with_replaced_escaping_bound_vars::>::fold_const::{closure#0}> 18: >::try_super_fold_with:: 19: ::normalize:: 20: rustc_hir_analysis::check::wfcheck::check_type_defn 21: rustc_hir_analysis::check::wfcheck::check_well_formed [... omitted 1 frame ...] 22: rustc_middle::query::plumbing::query_ensure_error_guaranteed::>, ()> 23: rustc_hir_analysis::check::wfcheck::check_mod_type_wf [... omitted 1 frame ...] 24: rustc_hir_analysis::check_crate 25: rustc_interface::passes::run_required_analyses 26: rustc_interface::passes::analysis [... omitted 1 frame ...] 27: >::enter::, rustc_driver_impl::run_compiler::{closure#0}::{closure#1}::{closure#3}> 28: rustc_interface::interface::run_compiler::, 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-11T11_46_53-81599.txt` to your bug report query stack during panic: #0 [eval_to_allocation_raw] const-evaluating + checking `Foo::Bar::0::{constant#0}` #1 [eval_to_valtree] evaluating type-level constant #2 [check_well_formed] checking that `Foo` is well-formed #3 [check_mod_type_wf] checking that types are well-formed in top-level module #4 [analysis] running analysis passes on this crate end of query stack error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct`) --> r_unsize_into_5CF554F2.rs:9:6 | 9 | impl CoerceUnsized for T {} | ^ type parameter `T` must be used as the type parameter for some local type | = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local = note: only traits defined in the current crate can be implemented for a type parameter error[E0376]: the trait `CoerceUnsized` may only be implemented for a coercion between structures --> r_unsize_into_5CF554F2.rs:9:1 | 9 | impl CoerceUnsized for T {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 3 previous errors Some errors have detailed explanations: E0210, E0376. For more information about an error, try `rustc --explain E0210`. ```

Notes

@rustbot label +F-coerce_unsized

cushionbadak commented 3 months ago

searched nightlies: from nightly-2023-01-01 to nightly-2024-05-30 regressed nightly: nightly-2024-02-09 searched commit range: https://github.com/rust-lang/rust/compare/8ace7ea1f7cbba7b4f031e66c54ca237a0d65de6...98aa3624be70462d6a25ed5544333e3df62f4c66 regressed commit: https://github.com/rust-lang/rust/commit/870a01a30e45d73b8e922a91850919e03f772636

bisected with cargo-bisect-rustc v0.6.8 Host triple: x86_64-unknown-linux-gnu Reproduce with: ```bash cargo bisect-rustc --start=2023-01-01 --end=2024-05-30 --regress=ice --script=rustc --preserve -- 126269.rs ```