Skip to content
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

ICE on stable: could not fully normalize <&Struct as Trait>::Type as enum variant #91234

Closed
mamins1376 opened this issue Nov 25, 2021 · 7 comments · Fixed by #91255
Closed

ICE on stable: could not fully normalize <&Struct as Trait>::Type as enum variant #91234

mamins1376 opened this issue Nov 25, 2021 · 7 comments · Fixed by #91255
Assignees
Labels
A-associated-items Area: Associated items (types, constants & functions) 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.

Comments

@mamins1376
Copy link

mamins1376 commented Nov 25, 2021

The error message strongly suggests that this is coming from the same origin as #91231, but the reproduction is different.

In this one, due to lack of reliance on #![feature(extern_types)] it is possible to trigger it on stable channel as well as nightly.

I made a repo to have both codes at one place.

Code

struct Struct;

trait Trait {
    type Type;
}

enum Enum<'a> where &'a Struct: Trait {
    Variant(<&'a Struct as Trait>::Type)
}

Meta

Stable:

rustc --version --verbose:

rustc 1.56.1 (59eed8a2a 2021-11-01)
binary: rustc
commit-hash: 59eed8a2aac0230a8b53e89d4e99d55912ba6b35
commit-date: 2021-11-01
host: x86_64-unknown-linux-gnu
release: 1.56.1
LLVM version: 13.0.0

Nightly:

rustc --version --verbose
rustc 1.58.0-nightly (b426445c6 2021-11-24)
binary: rustc
commit-hash: b426445c60b4faab6e96d2b866164d478680abf6
commit-date: 2021-11-24
host: x86_64-unknown-linux-gnu
release: 1.58.0-nightly
LLVM version: 13.0.0

Error output

For both nightly and stable it is the same. To keep it short, I removed dead_code warnings.

error: internal compiler error: compiler/rustc_traits/src/normalize_erasing_regions.rs:54:32: could not fully normalize `<&Struct as Trait>::Type`

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.58.0-nightly (b426445c6 2021-11-24) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib

query stack during panic:
#0 [normalize_generic_arg_after_erasing_regions] normalizing `<&Struct as Trait>::Type`
#1 [layout_of] computing layout of `<&Struct as Trait>::Type`
end of query stack
error: aborting due to previous error; 2 warnings emitted
Backtrace

error: internal compiler error: compiler/rustc_traits/src/normalize_erasing_regions.rs:54:32: could not fully normalize `<&Struct as Trait>::Type`

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_infer::infer::InferCtxtBuilder>::enter::<rustc_middle::ty::subst::GenericArg, rustc_traits::normalize_erasing_regions::normalize_after_erasing_regions<rustc_middle::ty::subst::GenericArg>::{closure#0}>
   8: <rustc_traits::normalize_erasing_regions::provide::{closure#0} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_middle::ty::ParamEnvAnd<rustc_middle::ty::subst::GenericArg>)>>::call_once
   9: 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::subst::GenericArg>, rustc_middle::ty::subst::GenericArg>>
  10: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::normalize_generic_arg_after_erasing_regions
  11: <&rustc_middle::ty::TyS as rustc_middle::ty::fold::TypeFoldable>::fold_with::<rustc_middle::ty::normalize_erasing_regions::NormalizeAfterErasingRegionsFolder>
  12: rustc_middle::ty::layout::layout_of
  13: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::layout_of
  14: <alloc::vec::Vec<rustc_target::abi::TyAndLayout<&rustc_middle::ty::TyS>> as alloc::vec::spec_from_iter::SpecFromIter<rustc_target::abi::TyAndLayout<&rustc_middle::ty::TyS>, core::iter::adapters::ResultShunt<core::iter::adapters::map::Map<core::slice::iter::Iter<rustc_middle::ty::FieldDef>, <rustc_middle::ty::layout::LayoutCx<rustc_middle::ty::context::TyCtxt>>::layout_of_uncached::{closure#5}::{closure#0}>, rustc_middle::ty::layout::LayoutError>>>::from_iter
  15: <alloc::vec::Vec<alloc::vec::Vec<rustc_target::abi::TyAndLayout<&rustc_middle::ty::TyS>>> as alloc::vec::spec_from_iter::SpecFromIter<alloc::vec::Vec<rustc_target::abi::TyAndLayout<&rustc_middle::ty::TyS>>, core::iter::adapters::ResultShunt<core::iter::adapters::map::Map<core::slice::iter::Iter<rustc_middle::ty::VariantDef>, <rustc_middle::ty::layout::LayoutCx<rustc_middle::ty::context::TyCtxt>>::layout_of_uncached::{closure#5}>, rustc_middle::ty::layout::LayoutError>>>::from_iter
  16: rustc_middle::ty::layout::layout_of
  17: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::layout_of
  18: <rustc_lint::context::LateContext as rustc_middle::ty::layout::LayoutOf>::layout_of
  19: <rustc_lint::BuiltinCombinedModuleLateLintPass as rustc_lint::passes::LateLintPass>::check_item
  20: <rustc_lint::late::LateContextAndPass<rustc_lint::BuiltinCombinedModuleLateLintPass> as rustc_hir::intravisit::Visitor>::visit_nested_item
  21: rustc_lint::late::late_lint_mod::<rustc_lint::BuiltinCombinedModuleLateLintPass>
  22: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalDefId, ()>>
  23: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::lint_mod, rustc_query_impl::plumbing::QueryCtxt>
  24: <rustc_session::session::Session>::time::<(), rustc_lint::late::check_crate<rustc_lint::BuiltinCombinedLateLintPass, rustc_interface::passes::analysis::{closure#5}::{closure#0}::{closure#3}::{closure#0}::{closure#0}>::{closure#1}::{closure#0}>
  25: <rustc_session::session::Session>::time::<(), rustc_interface::passes::analysis::{closure#5}::{closure#0}::{closure#3}::{closure#0}>
  26: <core::panic::unwind_safe::AssertUnwindSafe<rustc_interface::passes::analysis::{closure#5}::{closure#0}> as core::ops::function::FnOnce<()>>::call_once
  27: <rustc_session::session::Session>::time::<(), rustc_interface::passes::analysis::{closure#5}>
  28: rustc_interface::passes::analysis
  29: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<(), core::result::Result<(), rustc_errors::ErrorReported>>>
  30: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
  31: <rustc_interface::passes::QueryContext>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}::{closure#3}, core::result::Result<(), rustc_errors::ErrorReported>>
  32: <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>>
  33: 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}>
  34: rustc_interface::interface::create_compiler_and_run::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>
  35: <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.58.0-nightly (b426445c6 2021-11-24) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib

query stack during panic:
#0 [normalize_generic_arg_after_erasing_regions] normalizing `<&Struct as Trait>::Type`
#1 [layout_of] computing layout of `<&Struct as Trait>::Type`
#2 [layout_of] computing layout of `Enum`
#3 [lint_mod] linting top-level module
#4 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error; 2 warnings emitted

@mamins1376 mamins1376 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 Nov 25, 2021
@inquisitivecrystal inquisitivecrystal added A-associated-items Area: Associated items (types, constants & functions) I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Nov 26, 2021
@b-naber
Copy link
Contributor

b-naber commented Nov 26, 2021

Seems as if layout_of shouldn't expect the normalization in normalize_erasing_regions to succeed, since normalize_after_erasing_regions, which is internally called by normalize_erasing_regions calls bug if the normalization fails.

This actually results in ICEs whenever layout_of is called on an associated type that isn't provable, e.g. this also ICEs:

#![feature(repr_transparent)]

struct Struct;

trait Trait {
    type Type;
}

#[repr(transparent)]
struct NumberWithUnit<'a>(<&'a Struct as Trait>::Type) where &'a Struct: Trait;

fn main() {}

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=5c81ddf7f591aeef94a97bb7d5957b36

I can try to fix this issue.

@b-naber
Copy link
Contributor

b-naber commented Nov 26, 2021

@rustbot claim

@mamins1376
Copy link
Author

@b-naber There are quite a few of seemingly related issues, so fixing one might eradicate many.

@camelid
Copy link
Member

camelid commented Nov 26, 2021

It looks like adding the impl used in the bound makes compilation succeed:

impl Trait for &Struct {
    type Type = i32;
}

So am I correct that this is an ICE that occurs when an error should've been emitted?

@b-naber
Copy link
Contributor

b-naber commented Nov 26, 2021

@camelid That's what I also thought initially, but it seems we never reject these during typecheck, e.g. this also compiles:

struct Struct;

trait Trait {
    type Type;
}

fn foo<'a>(_arg: <&'a Struct as Trait>::Type) where &'a Struct: Trait {}

Using this function or the enum above would yield an error then.

@camelid
Copy link
Member

camelid commented Nov 26, 2021

Ah, that's a good point! The where bound is impossible to fulfill, but the definition is still valid.

@bors bors closed this as completed in f04a2f4 Dec 1, 2021
@mamins1376
Copy link
Author

@b-naber Thank you!

@inquisitivecrystal inquisitivecrystal removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Dec 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants