Skip to content

Failed to normalize struct with generic const expression parameter as associated type #93946

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
zyansheep opened this issue Feb 12, 2022 · 1 comment
Labels
C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@zyansheep
Copy link

Code

// subcrate, lib.rs
#![feature(generic_const_exprs)]
#![feature(adt_const_params)]

#[derive(PartialEq, Eq)]
pub struct Const {}
impl Const {
	pub const fn func(self) -> usize { 1 }
}

pub struct Foo<const C: Const>
where
	[(); C.func()]: Sized
{}

pub trait Bar {
	type Associated;
	fn associated() -> Self::Associated;
}

impl<const C: Const> Bar for Foo<C>
where
	[(); C.func()]: Sized
{
	type Associated = [(); C.func()];
	fn associated() -> Self::Associated {
		[(); C.func()]
	}
}
// main.rs
use subcrate::*;

fn main() {
	<Foo::<{Const{}}> as Bar>::associated();
}

Meta

rustc --version --verbose:

rustc 1.60.0-nightly (bd3cb5256 2022-01-16)
binary: rustc
commit-hash: bd3cb52565faab2755ff1bdb54d88bc91f47b4b9
commit-date: 2022-01-16
host: x86_64-unknown-linux-gnu
release: 1.60.0-nightly
LLVM version: 13.0.0

Error output

error: internal compiler error: compiler/rustc_middle/src/ty/normalize_erasing_regions.rs:179:90: Failed to normalize <subcrate::Foo<C> as subcrate::Bar>::Associated, maybe try to call `try_normalize_erasing_regions` instead

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1169:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

note: the compiler unexpectedly panicked. this is a bug.

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: rustc 1.60.0-nightly (bd3cb5256 2022-01-16) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type bin

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [fn_abi_of_instance] computing call ABI of `<subcrate::Foo<subcrate::Const {  }> as subcrate::Bar>::associated`
end of query stack
error: could not compile `rust_cargo_rkyv_bug`
Backtrace

error: internal compiler error: compiler/rustc_middle/src/ty/normalize_erasing_regions.rs:179:90: Failed to normalize <subcrate::Foo<C> as subcrate::Bar>::Associated, maybe try to call `try_normalize_erasing_regions` instead

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1169:9
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: std::panic::panic_any::<rustc_errors::ExplicitBug>
   2: <rustc_errors::HandlerInner>::bug
   3: <rustc_errors::Handler>::bug
   4: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, ()>
   5: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>
   6: rustc_middle::util::bug::bug_fmt
   7: rustc_middle::ty::util::fold_list::<rustc_middle::ty::normalize_erasing_regions::NormalizeAfterErasingRegionsFolder, &rustc_middle::ty::TyS, <&rustc_middle::ty::list::List<&rustc_middle::ty::TyS> as rustc_middle::ty::fold::TypeFoldable>::try_super_fold_with<rustc_middle::ty::normalize_erasing_regions::NormalizeAfterErasingRegionsFolder>::{closure#0}>
   8: rustc_middle::ty::layout::fn_abi_of_instance
   9: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, rustc_middle::ty::ParamEnvAnd<(rustc_middle::ty::instance::Instance, &rustc_middle::ty::list::List<&rustc_middle::ty::TyS>)>, core::result::Result<&rustc_target::abi::call::FnAbi<&rustc_middle::ty::TyS>, rustc_middle::ty::layout::FnAbiError>>
  10: rustc_data_structures::stack::ensure_sufficient_stack::<(core::result::Result<&rustc_target::abi::call::FnAbi<&rustc_middle::ty::TyS>, rustc_middle::ty::layout::FnAbiError>, rustc_query_system::dep_graph::graph::DepNodeIndex), rustc_query_system::query::plumbing::execute_job<rustc_query_impl::plumbing::QueryCtxt, rustc_middle::ty::ParamEnvAnd<(rustc_middle::ty::instance::Instance, &rustc_middle::ty::list::List<&rustc_middle::ty::TyS>)>, core::result::Result<&rustc_target::abi::call::FnAbi<&rustc_middle::ty::TyS>, rustc_middle::ty::layout::FnAbiError>>::{closure#3}>
  11: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_middle::ty::ParamEnvAnd<(rustc_middle::ty::instance::Instance, &rustc_middle::ty::list::List<&rustc_middle::ty::TyS>)>, core::result::Result<&rustc_target::abi::call::FnAbi<&rustc_middle::ty::TyS>, rustc_middle::ty::layout::FnAbiError>>>
  12: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::fn_abi_of_instance
  13: rustc_codegen_ssa::mir::codegen_mir::<rustc_codegen_llvm::builder::Builder>
  14: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
  15: rustc_codegen_llvm::base::compile_codegen_unit
  16: rustc_codegen_ssa::base::codegen_crate::<rustc_codegen_llvm::LlvmCodegenBackend>
  17: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  18: <rustc_session::session::Session>::time::<alloc::boxed::Box<dyn core::any::Any>, rustc_interface::passes::start_codegen::{closure#0}>
  19: <rustc_interface::queries::Queries>::ongoing_codegen
  20: <rustc_interface::interface::Compiler>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_errors::ErrorReported>>
  21: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#1}>
  22: rustc_interface::interface::create_compiler_and_run::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>
  23: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

note: the compiler unexpectedly panicked. this is a bug.

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: rustc 1.60.0-nightly (bd3cb5256 2022-01-16) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type bin

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [fn_abi_of_instance] computing call ABI of `<subcrate::Foo<subcrate::Const {  }> as subcrate::Bar>::associated`
end of query stack
error: could not compile `rust_cargo_rkyv_bug`

One weird thing is that it only works if the offending code is in a subcrate, not in the main crate.
Example code is here: https://github.com/zyansheep/rust_const_rkyv_bug

@zyansheep zyansheep added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 12, 2022
fanninpm added a commit to fanninpm/glacier that referenced this issue Feb 15, 2022
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Feb 15, 2022
@zyansheep
Copy link
Author

I have reran the test on nightly with the most recent compiler:

rustc 1.66.0-nightly (a6b7274a4 2022-10-10)
binary: rustc
commit-hash: a6b7274a462829f8ef08a1ddcdcec7ac80dbf3e1
commit-date: 2022-10-10
host: x86_64-unknown-linux-gnu
release: 1.66.0-nightly
LLVM version: 15.0.2

and it seems to not error anymore.

Just in case it was a fluke, I went back to where I originally discovered the bug and everything seems to work just fine :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants