Skip to content

ICE: expected int of size 8, but got size 1 in rustc_middle/src/ty/consts/int.rs with feature adt_const_params #131052

Open

Description

Code

(manually reduced)

#![feature(adt_const_params)]
#![allow(incomplete_features)]

struct ConstBytes<const T: &'static [*mut u8; 3]>;

pub fn main() {
    let _: ConstBytes<b"AAA"> = ConstBytes::<b"BBB">;
}
Original Code

//@ revisions: full min

#![cfg_attr(full, feature(adt_const_params))]
#![cfg_attr(full, allow(incomplete_features))]


struct ConstString<const T: &'static str>;
//[min]~^ ERROR
struct ConstBytes<const T: &'static [*mut u8; mem::size_of::<*mut T>() / mem::size_of::<*mut u8>()]>;
//[min]~^ ERROR

pub fn main() {
    let _: ConstString<"Hello"> = ConstString::<"Hello">;
    let _: ConstString<"Hello"> = None::<std::slice::Iter<()>>; //~ ERROR mismatched types
    let _: ConstString<"ℇ㇈↦"> = ConstString::<"ℇ㇈↦">;
    let _: ConstString<"ℇ㇈↦"> = ConstString::<"ℇ㇈↥">; //~ ERROR mismatched types
    let _: ConstBytes<b"AAA"> = ConstBytes::<{&[0x41, 0x41, 0x41]}>;
    let _: ConstBytes<b"AAA"> = ConstBytes::<b"BBB">; //~ ERROR mismatched types
}


// from tests/ui/const-generics/slice-const-param-mismatch.rs

Meta

rustc --version --verbose:

rustc 1.83.0-nightly (7608018cb 2024-09-29)
binary: rustc
commit-hash: 7608018cbdac9e55d0d13529cf43adc33d53efcf
commit-date: 2024-09-29
host: x86_64-apple-darwin
release: 1.83.0-nightly
LLVM version: 19.1.0

Error output

Command: rustc

error[E0741]: `&'static [*mut u8; 3]` can't be used as a const parameter type
 --> r_E364D18BCB8846EE07601029D3F8CBE898970C9D0A44FC6609A112B969C95B8D_2.rs:4:28
  |
4 | struct ConstBytes<const T: &'static [*mut u8; 3]>;
  |                            ^^^^^^^^^^^^^^^^^^^^^

error: internal compiler error: compiler/rustc_middle/src/ty/consts/int.rs:263:13: expected int of size 8, but got size 1
Backtrace

thread 'rustc' panicked at compiler/rustc_middle/src/ty/consts/int.rs:263:13:
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_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   3: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   4: 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}, !>
   5: rustc_middle::util::bug::bug_fmt
   6: <rustc_middle::ty::print::pretty::FmtPrinter as rustc_middle::ty::print::pretty::PrettyPrinter>::pretty_print_const_scalar_int
   7: <rustc_middle::ty::print::pretty::FmtPrinter as rustc_middle::ty::print::pretty::PrettyPrinter>::pretty_print_const_valtree
   8: <rustc_middle::ty::print::pretty::FmtPrinter as rustc_middle::ty::print::pretty::PrettyPrinter>::pretty_print_const
   9: <rustc_middle::ty::print::pretty::FmtPrinter as rustc_middle::ty::print::pretty::PrettyPrinter>::pretty_print_const_valtree
  10: <rustc_middle::ty::print::pretty::FmtPrinter as rustc_middle::ty::print::pretty::PrettyPrinter>::pretty_print_const_valtree
  11: <rustc_middle::ty::print::pretty::FmtPrinter as rustc_middle::ty::print::pretty::PrettyPrinter>::pretty_print_const
  12: <rustc_middle::ty::consts::Const as core::fmt::Display>::fmt
  13: <rustc_trait_selection::error_reporting::TypeErrCtxt>::cmp
  14: <rustc_trait_selection::error_reporting::TypeErrCtxt>::values_str
  15: <rustc_trait_selection::error_reporting::TypeErrCtxt>::note_type_err
  16: <rustc_trait_selection::error_reporting::TypeErrCtxt>::report_and_explain_type_error
  17: <rustc_hir_typeck::fn_ctxt::FnCtxt>::demand_coerce_diag
  18: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_decl
  19: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_block_with_expected
  20: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  21: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_return_expr
  22: rustc_hir_typeck::check::check_fn
  23: rustc_hir_typeck::typeck
      [... omitted 1 frame ...]
  24: <rustc_middle::hir::map::Map>::par_body_owners::<rustc_hir_analysis::check_crate::{closure#4}>::{closure#0}
  25: rustc_hir_analysis::check_crate
  26: rustc_interface::passes::run_required_analyses
  27: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  28: <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#5}>
  29: 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/blackbox icemaker 결과/240926_240401_blackbox_result/rustc-ice-2024-09-30T08_07_24-63216.txt` to your bug report

query stack during panic:
#0 [typeck] type-checking `main`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0741`.

Note

@rustbot label +F-adt_const_params

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-adt_const_params`#![feature(adt_const_params)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions