Skip to content

adt_const_params: ICE when using reference to user-defined unsized type as const generic #119299

Closed as not planned
@fcard

Description

@fcard

Code

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

use std::marker::ConstParamTy;

#[derive(Eq, PartialEq)]
struct ConstStrU(*const u8, usize);

impl ConstParamTy for &'static ConstStrU {}

impl ConstStrU {
  const fn from_bytes(bytes: &'static [u8]) -> Self {
    Self(bytes.as_ptr(), bytes.len())
  }
}

const fn chars_s<const S: &'static ConstStrU>() -> [char; 3] {
  ['a','b','c']
}

fn main() {
  const A: &'static ConstStrU = &ConstStrU::from_bytes(b"abc");
  chars_s::<A>();
}

Removing the pointer from ConstStrU unbreaks the code.

Meta

rustc --version --verbose:

rustc 1.77.0-nightly (3d0e6bed6 2023-12-21)
binary: rustc
commit-hash: 3d0e6bed600c0175628e96f1118293cf44fb97bd
commit-date: 2023-12-21
host: x86_64-unknown-linux-gnu
release: 1.77.0-nightly
LLVM version: 17.0.6

Error output

error: internal compiler error: no errors encountered even though `span_delayed_bug` issued

error: internal compiler error: `ty::Const::eval` called on a non-valtree-compatible type
  |
  = note: delayed at /rustc/3d0e6bed600c0175628e96f1118293cf44fb97bd/compiler/rustc_middle/src/ty/consts.rs:325:38
             0: <rustc_errors::DiagCtxtInner>::emit_diagnostic_without_consuming
             1: <rustc_errors::DiagCtxtInner>::emit_diagnostic
             2: <rustc_errors::DiagCtxt>::span_delayed_bug::<rustc_span::span_encoding::Span, &str>
             3: <rustc_middle::ty::consts::Const>::eval.cold.0
             4: <rustc_trait_selection::traits::project::AssocTypeNormalizer as rustc_type_ir::fold::TypeFolder<rustc_middle::ty::context::TyCtxt>>::fold_const
             5: <&rustc_middle::ty::list::List<rustc_middle::ty::generic_args::GenericArg> as rustc_type_ir::fold::TypeFoldable<rustc_middle::ty::context::TyCtxt>>::try_fold_with::<rustc_trait_selection::traits::project::AssocTypeNormalizer>
             6: <rustc_hir_typeck::fn_ctxt::FnCtxt>::normalize::<&rustc_middle::ty::list::List<rustc_middle::ty::generic_args::GenericArg>>
             7: <rustc_hir_typeck::fn_ctxt::FnCtxt>::instantiate_value_path
             8: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_path
             9: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_call
            10: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
            11: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_block_with_expected
            12: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
            13: rustc_hir_typeck::check::check_fn
            14: rustc_hir_typeck::typeck
            15: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
            16: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
            17: rustc_query_impl::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
            18: <rustc_middle::hir::map::Map>::par_body_owners::<rustc_hir_analysis::check_crate::{closure#7}>::{closure#0}
            19: rustc_hir_analysis::check_crate
            20: rustc_interface::passes::analysis
            21: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
            22: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
            23: rustc_query_impl::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
            24: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}
            25: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
            26: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
            27: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                       at /rustc/3d0e6bed600c0175628e96f1118293cf44fb97bd/library/alloc/src/boxed.rs:2015:9
            28: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                       at /rustc/3d0e6bed600c0175628e96f1118293cf44fb97bd/library/alloc/src/boxed.rs:2015:9
            29: std::sys::unix::thread::Thread::new::thread_start
                       at /rustc/3d0e6bed600c0175628e96f1118293cf44fb97bd/library/std/src/sys/unix/thread.rs:108:17
            30: start_thread
                       at ./nptl/pthread_create.c:444:8
            31: __GI___clone3
                       at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
          

error: internal compiler error: `ty::Const::eval` called on a non-valtree-compatible type
  |
  = note: delayed at /rustc/3d0e6bed600c0175628e96f1118293cf44fb97bd/compiler/rustc_middle/src/ty/consts.rs:325:38
             0: <rustc_errors::DiagCtxtInner>::emit_diagnostic_without_consuming
             1: <rustc_errors::DiagCtxtInner>::emit_diagnostic
             2: <rustc_errors::DiagCtxt>::span_delayed_bug::<rustc_span::span_encoding::Span, &str>
             3: <rustc_middle::ty::consts::Const>::eval.cold.0
             4: <rustc_trait_selection::traits::project::AssocTypeNormalizer as rustc_type_ir::fold::TypeFolder<rustc_middle::ty::context::TyCtxt>>::fold_const
             5: <rustc_trait_selection::traits::fulfill::FulfillProcessor as rustc_data_structures::obligation_forest::ObligationProcessor>::process_obligation
             6: <rustc_data_structures::obligation_forest::ObligationForest<rustc_trait_selection::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection::traits::fulfill::FulfillProcessor>
             7: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_argument_types
             8: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_call
             9: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
            10: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_block_with_expected
            11: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
            12: rustc_hir_typeck::check::check_fn
            13: rustc_hir_typeck::typeck
            14: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
            15: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
            16: rustc_query_impl::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
            17: <rustc_middle::hir::map::Map>::par_body_owners::<rustc_hir_analysis::check_crate::{closure#7}>::{closure#0}
            18: rustc_hir_analysis::check_crate
            19: rustc_interface::passes::analysis
            20: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
            21: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
            22: rustc_query_impl::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
            23: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}
            24: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
            25: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
            26: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                       at /rustc/3d0e6bed600c0175628e96f1118293cf44fb97bd/library/alloc/src/boxed.rs:2015:9
            27: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                       at /rustc/3d0e6bed600c0175628e96f1118293cf44fb97bd/library/alloc/src/boxed.rs:2015:9
            28: std::sys::unix::thread::Thread::new::thread_start
                       at /rustc/3d0e6bed600c0175628e96f1118293cf44fb97bd/library/std/src/sys/unix/thread.rs:108:17
            29: start_thread
                       at ./nptl/pthread_create.c:444:8
            30: __GI___clone3
                       at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
          
Backtrace

delayed span bug: `ty::Const::eval` called on a non-valtree-compatible type
   0: <rustc_errors::DiagCtxtInner>::emit_diagnostic_without_consuming
   1: <rustc_errors::DiagCtxtInner>::emit_diagnostic
   2: <rustc_errors::DiagCtxt>::span_delayed_bug::<rustc_span::span_encoding::Span, &str>
   3: <rustc_middle::ty::consts::Const>::eval.cold.0
   4: <rustc_trait_selection::traits::project::AssocTypeNormalizer as rustc_type_ir::fold::TypeFolder<rustc_middle::ty::context::TyCtxt>>::fold_const
   5: <&rustc_middle::ty::list::List<rustc_middle::ty::generic_args::GenericArg> as rustc_type_ir::fold::TypeFoldable<rustc_middle::ty::context::TyCtxt>>::try_fold_with::<rustc_trait_selection::traits::project::AssocTypeNormalizer>
   6: <rustc_hir_typeck::fn_ctxt::FnCtxt>::normalize::<&rustc_middle::ty::list::List<rustc_middle::ty::generic_args::GenericArg>>
   7: <rustc_hir_typeck::fn_ctxt::FnCtxt>::instantiate_value_path
   8: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_path
   9: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_call
  10: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  11: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_block_with_expected
  12: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  13: rustc_hir_typeck::check::check_fn
  14: rustc_hir_typeck::typeck
  15: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
  16: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
  17: rustc_query_impl::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  18: <rustc_middle::hir::map::Map>::par_body_owners::<rustc_hir_analysis::check_crate::{closure#7}>::{closure#0}
  19: rustc_hir_analysis::check_crate
  20: rustc_interface::passes::analysis
  21: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
  22: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
  23: rustc_query_impl::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  24: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}
  25: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
  26: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  27: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/3d0e6bed600c0175628e96f1118293cf44fb97bd/library/alloc/src/boxed.rs:2015:9
  28: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/3d0e6bed600c0175628e96f1118293cf44fb97bd/library/alloc/src/boxed.rs:2015:9
  29: std::sys::unix::thread::Thread::new::thread_start
             at /rustc/3d0e6bed600c0175628e96f1118293cf44fb97bd/library/std/src/sys/unix/thread.rs:108:17
  30: start_thread
             at ./nptl/pthread_create.c:444:8
  31: __GI___clone3
             at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78

delayed span bug: `ty::Const::eval` called on a non-valtree-compatible type
   0: <rustc_errors::DiagCtxtInner>::emit_diagnostic_without_consuming
   1: <rustc_errors::DiagCtxtInner>::emit_diagnostic
   2: <rustc_errors::DiagCtxt>::span_delayed_bug::<rustc_span::span_encoding::Span, &str>
   3: <rustc_middle::ty::consts::Const>::eval.cold.0
   4: <rustc_trait_selection::traits::project::AssocTypeNormalizer as rustc_type_ir::fold::TypeFolder<rustc_middle::ty::context::TyCtxt>>::fold_const
   5: <rustc_trait_selection::traits::fulfill::FulfillProcessor as rustc_data_structures::obligation_forest::ObligationProcessor>::process_obligation
   6: <rustc_data_structures::obligation_forest::ObligationForest<rustc_trait_selection::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection::traits::fulfill::FulfillProcessor>
   7: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_argument_types
   8: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_call
   9: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  10: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_block_with_expected
  11: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  12: rustc_hir_typeck::check::check_fn
  13: rustc_hir_typeck::typeck
  14: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
  15: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
  16: rustc_query_impl::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  17: <rustc_middle::hir::map::Map>::par_body_owners::<rustc_hir_analysis::check_crate::{closure#7}>::{closure#0}
  18: rustc_hir_analysis::check_crate
  19: rustc_interface::passes::analysis
  20: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
  21: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
  22: rustc_query_impl::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  23: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}
  24: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
  25: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  26: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/3d0e6bed600c0175628e96f1118293cf44fb97bd/library/alloc/src/boxed.rs:2015:9
  27: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/3d0e6bed600c0175628e96f1118293cf44fb97bd/library/alloc/src/boxed.rs:2015:9
  28: std::sys::unix::thread::Thread::new::thread_start
             at /rustc/3d0e6bed600c0175628e96f1118293cf44fb97bd/library/std/src/sys/unix/thread.rs:108:17
  29: start_thread
             at ./nptl/pthread_create.c:444:8
  30: __GI___clone3
             at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78



rustc version: 1.77.0-nightly (3d0e6bed6 2023-12-21)
platform: x86_64-unknown-linux-gnu

query stack during panic:
end of query stack

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️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