ICE: issue-69398.rs with mir-opt-level=3 and --crate-type=lib: compiler/rustc_traits/src/normalize_erasing_regions.rs:62:32: could not fully normalize `<() as Foo>::Bar`

This issue has been created since 2021-12-10.

code from ./src/test/ui/associated-types/issue-69398.rs
cc #69398

Code

// check-pass

pub trait Foo {
    type Bar;
}

pub trait Broken {
    type Assoc;
    fn broken(&self) where Self::Assoc: Foo;
}

impl<T> Broken for T {
    type Assoc = ();
    fn broken(&self) where Self::Assoc: Foo {
        let _x: <Self::Assoc as Foo>::Bar;
    }
}

fn main() {
    let _m: &dyn Broken<Assoc=()> = &();
}

Meta

rustc --version --verbose:

rustc 1.59.0-nightly (0b42deacc 2021-12-09)
binary: rustc
commit-hash: 0b42deaccc2cbe17a68067aa5fdb76104369e1fd
commit-date: 2021-12-09
host: x86_64-unknown-linux-gnu
release: 1.59.0-nightly
LLVM version: 13.0.0

Error output

rustc ./src/test/ui/associated-types/issue-69398.rs -Zmir-opt-level=3 --crate-type lib

Note that --crate-type lib is required to reproduce the ICE

warning: function is never used: `main`
  --> ./src/test/ui/associated-types/issue-69398.rs:19:4
   |
19 | fn main() {
   |    ^^^^
   |
   = note: `#[warn(dead_code)]` on by default

error: internal compiler error: compiler/rustc_traits/src/normalize_erasing_regions.rs:62:32: could not fully normalize `<() as Foo>::Bar`

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1170: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.59.0-nightly (0b42deacc 2021-12-09) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z mir-opt-level=3 --crate-type lib

query stack during panic:
#0 [normalize_generic_arg_after_erasing_regions] normalizing `<() as Foo>::Bar`
#1 [optimized_mir] optimizing MIR for `<impl at ./src/test/ui/associated-types/issue-69398.rs:12:1: 17:2>::broken`
end of query stack
error: aborting due to previous error; 1 warning emitted

Backtrace

error: internal compiler error: compiler/rustc_traits/src/normalize_erasing_regions.rs:62:32: could not fully normalize `<() as Foo>::Bar`

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1170:9
stack backtrace:
   0:     0x7f2e30bd535c - std::backtrace_rs::backtrace::libunwind::trace::hf7449935ead7573e
                               at /rustc/0b42deaccc2cbe17a68067aa5fdb76104369e1fd/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f2e30bd535c - std::backtrace_rs::backtrace::trace_unsynchronized::h221aa2d88d72372a
                               at /rustc/0b42deaccc2cbe17a68067aa5fdb76104369e1fd/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f2e30bd535c - std::sys_common::backtrace::_print_fmt::h1c77e8983e1df895
                               at /rustc/0b42deaccc2cbe17a68067aa5fdb76104369e1fd/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7f2e30bd535c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hd4ec41a9a6b0d22c
                               at /rustc/0b42deaccc2cbe17a68067aa5fdb76104369e1fd/library/std/src/sys_common/backtrace.rs:46:22
   4:     0x7f2e30c3237c - core::fmt::write::h72801a82c94e6ff1
                               at /rustc/0b42deaccc2cbe17a68067aa5fdb76104369e1fd/library/core/src/fmt/mod.rs:1149:17
   5:     0x7f2e30bc5a65 - std::io::Write::write_fmt::haf74340a8cbeaa88
                               at /rustc/0b42deaccc2cbe17a68067aa5fdb76104369e1fd/library/std/src/io/mod.rs:1660:15
   6:     0x7f2e30bd8520 - std::sys_common::backtrace::_print::h2d15cd157796a64a
                               at /rustc/0b42deaccc2cbe17a68067aa5fdb76104369e1fd/library/std/src/sys_common/backtrace.rs:49:5
   7:     0x7f2e30bd8520 - std::sys_common::backtrace::print::h52d286d22e2398eb
                               at /rustc/0b42deaccc2cbe17a68067aa5fdb76104369e1fd/library/std/src/sys_common/backtrace.rs:36:9
   8:     0x7f2e30bd8520 - std::panicking::default_hook::{{closure}}::h6da08fba6306daf2
                               at /rustc/0b42deaccc2cbe17a68067aa5fdb76104369e1fd/library/std/src/panicking.rs:211:50
   9:     0x7f2e30bd80cb - std::panicking::default_hook::h266f67a22e76b11a
                               at /rustc/0b42deaccc2cbe17a68067aa5fdb76104369e1fd/library/std/src/panicking.rs:228:9
  10:     0x7f2e316fc291 - rustc_driver[feb513e6adc957d8]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7f2e30bd8d39 - std::panicking::rust_panic_with_hook::he55698a957f4fb6d
                               at /rustc/0b42deaccc2cbe17a68067aa5fdb76104369e1fd/library/std/src/panicking.rs:610:17
  12:     0x7f2e3282ae6b - std[f24903a91e569aa2]::panicking::begin_panic::<rustc_errors[248f3f311c690252]::ExplicitBug>::{closure#0}
  13:     0x7f2e3282ae06 - std[f24903a91e569aa2]::sys_common::backtrace::__rust_end_short_backtrace::<std[f24903a91e569aa2]::panicking::begin_panic<rustc_errors[248f3f311c690252]::ExplicitBug>::{closure#0}, !>
  14:     0x7f2e3282df5f - std[f24903a91e569aa2]::panicking::begin_panic::<rustc_errors[248f3f311c690252]::ExplicitBug>
  15:     0x7f2e32838ead - std[f24903a91e569aa2]::panic::panic_any::<rustc_errors[248f3f311c690252]::ExplicitBug>
  16:     0x7f2e3283a56d - <rustc_errors[248f3f311c690252]::HandlerInner>::bug
  17:     0x7f2e3283a010 - <rustc_errors[248f3f311c690252]::Handler>::bug
  18:     0x7f2e326be5b6 - rustc_middle[f720485c3bb04922]::ty::context::tls::with_opt::<rustc_middle[f720485c3bb04922]::util::bug::opt_span_bug_fmt<rustc_span[dda57b1885b40b9a]::span_encoding::Span>::{closure#0}, ()>
  19:     0x7f2e326beae0 - rustc_middle[f720485c3bb04922]::util::bug::opt_span_bug_fmt::<rustc_span[dda57b1885b40b9a]::span_encoding::Span>
  20:     0x7f2e326bea56 - rustc_middle[f720485c3bb04922]::util::bug::bug_fmt
  21:     0x7f2e32f9d466 - <rustc_infer[7479c472c492593c]::infer::InferCtxtBuilder>::enter::<rustc_middle[f720485c3bb04922]::ty::subst::GenericArg, rustc_traits[3a05bb033114c414]::normalize_erasing_regions::normalize_after_erasing_regions<rustc_middle[f720485c3bb04922]::ty::subst::GenericArg>::{closure#0}>
  22:     0x7f2e32f99bba - <rustc_traits[3a05bb033114c414]::normalize_erasing_regions::provide::{closure#0} as core[cc79c391059f8e46]::ops::function::FnOnce<(rustc_middle[f720485c3bb04922]::ty::context::TyCtxt, rustc_middle[f720485c3bb04922]::ty::ParamEnvAnd<rustc_middle[f720485c3bb04922]::ty::subst::GenericArg>)>>::call_once
  23:     0x7f2e32fbfd19 - rustc_query_system[27ba240b72fd7978]::query::plumbing::try_execute_query::<rustc_query_impl[9c2ccd6b3a0df356]::plumbing::QueryCtxt, rustc_query_system[27ba240b72fd7978]::query::caches::DefaultCache<rustc_middle[f720485c3bb04922]::ty::ParamEnvAnd<rustc_middle[f720485c3bb04922]::ty::subst::GenericArg>, rustc_middle[f720485c3bb04922]::ty::subst::GenericArg>>
  24:     0x7f2e33067924 - <rustc_query_impl[9c2ccd6b3a0df356]::Queries as rustc_middle[f720485c3bb04922]::ty::query::QueryEngine>::normalize_generic_arg_after_erasing_regions
  25:     0x7f2e3343cef6 - <rustc_middle[f720485c3bb04922]::ty::normalize_erasing_regions::NormalizeAfterErasingRegionsFolder as rustc_middle[f720485c3bb04922]::ty::fold::TypeFolder>::fold_ty
  26:     0x7f2e32ab8c40 - <rustc_middle[f720485c3bb04922]::ty::context::TyCtxt>::normalize_erasing_regions::<&rustc_middle[f720485c3bb04922]::ty::TyS>
  27:     0x7f2e3198285b - <rustc_mir_transform[f9737dd6152db8c1]::reveal_all::RevealAll as rustc_middle[f720485c3bb04922]::mir::MirPass>::run_pass
  28:     0x7f2e32aa443f - rustc_mir_transform[f9737dd6152db8c1]::pass_manager::run_passes
  29:     0x7f2e337808e7 - rustc_mir_transform[f9737dd6152db8c1]::optimized_mir
  30:     0x7f2e32fe1efd - rustc_query_system[27ba240b72fd7978]::query::plumbing::try_execute_query::<rustc_query_impl[9c2ccd6b3a0df356]::plumbing::QueryCtxt, rustc_query_system[27ba240b72fd7978]::query::caches::DefaultCache<rustc_span[dda57b1885b40b9a]::def_id::DefId, &rustc_middle[f720485c3bb04922]::mir::Body>>
  31:     0x7f2e33059b97 - <rustc_query_impl[9c2ccd6b3a0df356]::Queries as rustc_middle[f720485c3bb04922]::ty::query::QueryEngine>::optimized_mir
  32:     0x7f2e330eb609 - <rustc_metadata[b7dbc791ee3c9388]::rmeta::encoder::EncodeContext>::encode_crate_root
  33:     0x7f2e33c39801 - rustc_metadata[b7dbc791ee3c9388]::rmeta::encoder::encode_metadata_impl
  34:     0x7f2e33c4bfe1 - rustc_data_structures[740a91d2eeb9710d]::sync::join::<rustc_metadata[b7dbc791ee3c9388]::rmeta::encoder::encode_metadata::{closure#0}, rustc_metadata[b7dbc791ee3c9388]::rmeta::encoder::encode_metadata::{closure#1}, rustc_metadata[b7dbc791ee3c9388]::rmeta::encoder::EncodedMetadata, ()>
  35:     0x7f2e33c38fe6 - rustc_metadata[b7dbc791ee3c9388]::rmeta::encoder::encode_metadata
  36:     0x7f2e335c09a1 - <rustc_interface[4c4b5644b43577f1]::queries::Queries>::ongoing_codegen
  37:     0x7f2e3359081d - <rustc_interface[4c4b5644b43577f1]::interface::Compiler>::enter::<rustc_driver[feb513e6adc957d8]::run_compiler::{closure#1}::{closure#2}, core[cc79c391059f8e46]::result::Result<core[cc79c391059f8e46]::option::Option<rustc_interface[4c4b5644b43577f1]::queries::Linker>, rustc_errors[248f3f311c690252]::ErrorReported>>
  38:     0x7f2e3358d14d - rustc_span[dda57b1885b40b9a]::with_source_map::<core[cc79c391059f8e46]::result::Result<(), rustc_errors[248f3f311c690252]::ErrorReported>, rustc_interface[4c4b5644b43577f1]::interface::create_compiler_and_run<core[cc79c391059f8e46]::result::Result<(), rustc_errors[248f3f311c690252]::ErrorReported>, rustc_driver[feb513e6adc957d8]::run_compiler::{closure#1}>::{closure#1}>
  39:     0x7f2e335917ef - <scoped_tls[3fea4c3dcac147b1]::ScopedKey<rustc_span[dda57b1885b40b9a]::SessionGlobals>>::set::<rustc_interface[4c4b5644b43577f1]::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustc_interface[4c4b5644b43577f1]::interface::run_compiler<core[cc79c391059f8e46]::result::Result<(), rustc_errors[248f3f311c690252]::ErrorReported>, rustc_driver[feb513e6adc957d8]::run_compiler::{closure#1}>::{closure#0}, core[cc79c391059f8e46]::result::Result<(), rustc_errors[248f3f311c690252]::ErrorReported>>::{closure#0}::{closure#0}, core[cc79c391059f8e46]::result::Result<(), rustc_errors[248f3f311c690252]::ErrorReported>>
  40:     0x7f2e3358f995 - std[f24903a91e569aa2]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[4c4b5644b43577f1]::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustc_interface[4c4b5644b43577f1]::interface::run_compiler<core[cc79c391059f8e46]::result::Result<(), rustc_errors[248f3f311c690252]::ErrorReported>, rustc_driver[feb513e6adc957d8]::run_compiler::{closure#1}>::{closure#0}, core[cc79c391059f8e46]::result::Result<(), rustc_errors[248f3f311c690252]::ErrorReported>>::{closure#0}, core[cc79c391059f8e46]::result::Result<(), rustc_errors[248f3f311c690252]::ErrorReported>>
  41:     0x7f2e335afffa - <<std[f24903a91e569aa2]::thread::Builder>::spawn_unchecked<rustc_interface[4c4b5644b43577f1]::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustc_interface[4c4b5644b43577f1]::interface::run_compiler<core[cc79c391059f8e46]::result::Result<(), rustc_errors[248f3f311c690252]::ErrorReported>, rustc_driver[feb513e6adc957d8]::run_compiler::{closure#1}>::{closure#0}, core[cc79c391059f8e46]::result::Result<(), rustc_errors[248f3f311c690252]::ErrorReported>>::{closure#0}, core[cc79c391059f8e46]::result::Result<(), rustc_errors[248f3f311c690252]::ErrorReported>>::{closure#1} as core[cc79c391059f8e46]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  42:     0x7f2e30be3e23 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h4beb69a85f7fb16c
                               at /rustc/0b42deaccc2cbe17a68067aa5fdb76104369e1fd/library/alloc/src/boxed.rs:1811:9
  43:     0x7f2e30be3e23 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hef865a799f44aaf2
                               at /rustc/0b42deaccc2cbe17a68067aa5fdb76104369e1fd/library/alloc/src/boxed.rs:1811:9
  44:     0x7f2e30be3e23 - std::sys::unix::thread::Thread::new::thread_start::hee0b2d4e2414fa96
                               at /rustc/0b42deaccc2cbe17a68067aa5fdb76104369e1fd/library/std/src/sys/unix/thread.rs:108:17
  45:     0x7f2e30af1259 - start_thread
  46:     0x7f2e30a065e3 - __GI___clone
  47:                0x0 - <unknown>

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.59.0-nightly (0b42deacc 2021-12-09) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z mir-opt-level=3 --crate-type lib

query stack during panic:
#0 [normalize_generic_arg_after_erasing_regions] normalizing `<() as Foo>::Bar`
#1 [optimized_mir] optimizing MIR for `<impl at ./src/test/ui/associated-types/issue-69398.rs:12:1: 17:2>::broken`
end of query stack
error: aborting due to previous error; 1 warning emitted

matthiaskrgr wrote this answer on 2021-12-10

cc @b-naber maybe you have an idea why this still crashes with --crate-type lib ?

b-naber wrote this answer on 2021-12-10

No, I don't unfortunately. The version of normalize_erasing_regions version I worked on is meant to be called before typecheck has finished and where normalization could still fail. This call seems to occur during codegen, where normalization should (in theory) always succeed (or rather errors should have been caught earlier), but I'm not that familiar with the later stages of the compiler, so I might be missing something.

Aaron1011 wrote this answer on 2021-12-12

@b-naber This normalization is happening in an optimization pass (RevealAll) which can run on MIR that can never be codegenned. In this case, the broken method impl has an impossible-to-satisfy where clause, so it can never actually be called or codegenned.

The optimization pass should be changed to use try_normalize_erasing_regions - it can just do nothing if it fails.

b-naber wrote this answer on 2021-12-13

@Aaron1011 Thanks for pointing out the problem. Would you like to open a PR for this or are you ok with me trying to fix this?

Aaron1011 wrote this answer on 2021-12-13

@b-naber Feel free to open a PR

More Details About Repo
Owner Name rust-lang
Repo Name rust
Full Name rust-lang/rust
Language Rust
Created Date 2010-06-16
Updated Date 2022-09-26
Star Count 72359
Watcher Count 1477
Fork Count 9797
Issue Count 9012

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
Does it support go module? 4 2021-07-07 2022-09-01
v0.0.13 can't be installed on MacOS Monterey (arm64 => M1 CPU) 4 2022-03-10 2022-09-04
Background Image is wrong 2 2021-11-15 2022-02-16
[BUG] - by_username() TikTok returned a response indicating the entity is invalid 9 2021-09-23 2022-08-04
[BUG] - Be trending is getting only the first 6 items 5 2021-09-20 2022-01-31
Split init & init-minimal to have a prettier module 4 2022-08-24 2022-09-22
Add possibility to switch case for filenames 0 2022-02-09 2022-09-26
Tensorflow error when running demo.py file with pretrained model. 1 2022-02-08 2022-09-08
Getting CDN error/ Connection timeout 3 2021-10-06 2022-08-09
Dependabot couldn't authenticate with https://dl.bintray.com/jerady/maven 0 2021-06-15 2022-08-20
Change GUI to be clearer about which side is local vs. remote. 8 2021-05-07 2022-09-03
[BUG] Multiple instance creation VMs do not match the set number 2 2021-11-03 2022-01-14
Unable to set_client while making a custom WebClient in order to set custom connection_timeout 2 2021-12-13 2022-09-11
Connecting the application 11 2021-09-15 2022-08-29
Improve error reporting and use pre-defined token 1 2021-11-18 2022-05-21
Expanding the Frost Palette to support charts 1 2019-10-26 2022-09-10
Login issue on WinServer 2019 & IIS 3 2022-03-10 2022-09-18
Dockerhub rate limit causes test failures 1 2021-09-22 2022-02-01
Clipboard copy keyboard shortcut is not working 6 2022-04-02 2022-09-14
Remove superfluous rendering ??? 9 2022-04-10 2022-09-28
Double-click to edit a message 1 2022-06-30 2022-08-04
Input NG rollout tracker issue 2 2021-07-10 2022-08-18
Unable to add images to an image field after update to 9.12.2 3 2022-06-27 2022-08-28
[Icon Request] Zoom 1 2021-05-13 2022-01-14
Clarification of Permissions for network account 1 2022-03-03 2022-09-25
helm_resource - feedback: examples and documentation. 1 2022-05-28 2022-09-07
How to asynchronous return response 1 2021-12-24 2022-09-28
Investigate port scanning instead of always attempting to bind to a specific port within tests 0 2021-06-29 2022-09-28
guarded region reverse thinking 2 2021-11-03 2022-08-27
In the pointed head module, did you use the corner pooling? 3 2020-11-15 2022-09-21
Propel diff ignores first column when auto-generating indexes 2 2022-03-16 2022-09-22
Test run is slowed down tremendously if your file path contains Slipstream 4 2021-11-18 2022-09-01
Use `.ts` extension when creating Playwright config for TypeScript projects 15 2022-03-03 2022-09-01
url-regex-safe should be a peerdependency? 0 2022-01-11 2022-09-02
Kaniko build fails : too many levels of symbolic links 0 2022-08-19 2022-09-22
[UI] StatViewer: fix displayed unit 0 2021-10-07 2022-02-02
关于知乎用户数据的爬虫我确实想过一个用途 0 2021-09-25 2022-09-15
retire Finish this mini sudoku? 0 2021-03-12 2022-09-20
Building for both Intel and Apple Silicon 0 2022-05-25 2022-08-21
Possible difference in behaviour between caffeine and guava for LoadingCache.refresh calls with non-present keys 5 2018-04-27 2022-09-08
func_proxies: dict=None, Type "None" cannot be assigned to type "dict[Unknown, Unknown]" 2 2022-08-02 2022-09-08
Input lag with Fancy Zones - During zone layout changes 4 2022-05-18 2022-08-22
Misleading Picture 0 2021-11-02 2021-12-25
The Incoming shipments page only takes PO's into account, not returns from customers 0 2021-11-02 2022-09-15
Hulk theme listed in Themes.md does not exist in repos 3 2021-01-14 2022-07-22
【V3.9. 版本运营数据迁移后【任务统计-分时间统计】横坐标顺序错误 0 2021-10-18 2022-08-26
Current snapshot shows significant CVE database creation slowdown compared to 6.5.3 6 2022-02-19 2022-08-28
[FP]: spring-security-core-5.5.4.jar CWE-862 6 2022-02-21 2022-09-14
Password Resets Datetime issue 1 2021-06-22 2022-08-10
Add tests to show that tuples are handled correctly in typed data signing 0 2019-06-06 2022-09-24