rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.57k stars 12.74k forks source link

`Failed to normalize` closure with TAIT #109020

Closed Jules-Bertholet closed 7 months ago

Jules-Bertholet commented 1 year ago

Code

#![feature(type_alias_impl_trait)]

use core::marker::PhantomData;

type WithEmplacableForFn<'a> = impl EmplacableFn + 'a;

fn with_emplacable_for<'a, F, R>(mut f: F) -> R
where
    F: for<'b> FnMut(Emplacable<WithEmplacableForFn<'b>>) -> R,
{
    fn with_emplacable_for_inner<'a, R>(
        _: &'a (),
        _: &mut dyn FnMut(Emplacable<WithEmplacableForFn<'a>>) -> R,
    ) -> R {
        fn _constrain(_: &mut ()) -> WithEmplacableForFn<'_> {
            ()
        }
        loop {}
    }

    with_emplacable_for_inner(&(), &mut f)
}

trait EmplacableFn {}

impl EmplacableFn for () {}

struct Emplacable<F>
where
    F: EmplacableFn,
{
    phantom: PhantomData<F>,
}

fn main() {
    with_emplacable_for(|_| {});
}

Meta

rustc --version --verbose:

rustc 1.70.0-nightly (ff4b772f8 2023-03-10) running on x86_64-unknown-linux-gnu

Error output

error: internal compiler error: compiler/rustc_middle/src/ty/normalize_erasing_regions.rs:195:90: Failed to normalize <[closure@src/main.rs:36:25: 36:28] as std::ops::FnOnce<(Emplacable<()>,)>>::Output, maybe try to call `try_normalize_erasing_regions` instead
Backtrace

``` thread 'rustc' panicked at 'Box', /rustc/ff4b772f805ec1e1c1bd7e189ab8d5a4e3a6ef13/compiler/rustc_errors/src/lib.rs:1644:9 stack backtrace: 0: 0x7f555112651a - std::backtrace_rs::backtrace::libunwind::trace::hdf463920cb9883c6 at /rustc/ff4b772f805ec1e1c1bd7e189ab8d5a4e3a6ef13/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5 1: 0x7f555112651a - std::backtrace_rs::backtrace::trace_unsynchronized::hb1af812137cf3f3c at /rustc/ff4b772f805ec1e1c1bd7e189ab8d5a4e3a6ef13/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x7f555112651a - std::sys_common::backtrace::_print_fmt::h6b1baa3b67580720 at /rustc/ff4b772f805ec1e1c1bd7e189ab8d5a4e3a6ef13/library/std/src/sys_common/backtrace.rs:65:5 3: 0x7f555112651a - ::fmt::h2d9377ba074b9531 at /rustc/ff4b772f805ec1e1c1bd7e189ab8d5a4e3a6ef13/library/std/src/sys_common/backtrace.rs:44:22 4: 0x7f5551189c5e - core::fmt::write::h852d00ad4ee2aeb3 at /rustc/ff4b772f805ec1e1c1bd7e189ab8d5a4e3a6ef13/library/core/src/fmt/mod.rs:1232:17 5: 0x7f55511194c5 - std::io::Write::write_fmt::hcea4b1a61e3aab77 at /rustc/ff4b772f805ec1e1c1bd7e189ab8d5a4e3a6ef13/library/std/src/io/mod.rs:1684:15 6: 0x7f55511262e5 - std::sys_common::backtrace::_print::hd824f24a945752af at /rustc/ff4b772f805ec1e1c1bd7e189ab8d5a4e3a6ef13/library/std/src/sys_common/backtrace.rs:47:5 7: 0x7f55511262e5 - std::sys_common::backtrace::print::h8c438a1def0cf610 at /rustc/ff4b772f805ec1e1c1bd7e189ab8d5a4e3a6ef13/library/std/src/sys_common/backtrace.rs:34:9 8: 0x7f555112905f - std::panicking::default_hook::{{closure}}::hca9c2fb94ed37c32 at /rustc/ff4b772f805ec1e1c1bd7e189ab8d5a4e3a6ef13/library/std/src/panicking.rs:271:22 9: 0x7f5551128d9b - std::panicking::default_hook::h06237af56f487f7e at /rustc/ff4b772f805ec1e1c1bd7e189ab8d5a4e3a6ef13/library/std/src/panicking.rs:290:9 10: 0x7f5554448935 - rustc_driver_impl[fadf77a465939c7e]::DEFAULT_HOOK::{closure#0}::{closure#0} 11: 0x7f555112989d - as core::ops::function::Fn>::call::hd1c3deff0a8cf6e8 at /rustc/ff4b772f805ec1e1c1bd7e189ab8d5a4e3a6ef13/library/alloc/src/boxed.rs:2001:9 12: 0x7f555112989d - std::panicking::rust_panic_with_hook::h454607ef681fc36c at /rustc/ff4b772f805ec1e1c1bd7e189ab8d5a4e3a6ef13/library/std/src/panicking.rs:696:13 13: 0x7f55549a3fa1 - std[b4a766eaf44c2ca8]::panicking::begin_panic::::{closure#0} 14: 0x7f555499f6f6 - std[b4a766eaf44c2ca8]::sys_common::backtrace::__rust_end_short_backtrace::::{closure#0}, !> 15: 0x7f5554a25a56 - std[b4a766eaf44c2ca8]::panicking::begin_panic:: 16: 0x7f55549f1d76 - std[b4a766eaf44c2ca8]::panic::panic_any:: 17: 0x7f55549ed986 - ::bug::<&alloc[6e59c1986ef941dc]::string::String> 18: 0x7f55549ed650 - ::bug::<&alloc[6e59c1986ef941dc]::string::String> 19: 0x7f55549d9c5b - rustc_middle[d72fdf6c6b2250dd]::util::bug::opt_span_bug_fmt::::{closure#0} 20: 0x7f55549d86ba - rustc_middle[d72fdf6c6b2250dd]::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0} 21: 0x7f55549d8686 - rustc_middle[d72fdf6c6b2250dd]::ty::context::tls::with_context_opt::::{closure#0}, !>::{closure#0}, !> 22: 0x7f55549d9ba6 - rustc_middle[d72fdf6c6b2250dd]::util::bug::opt_span_bug_fmt:: 23: 0x7f5552ab5453 - rustc_middle[d72fdf6c6b2250dd]::util::bug::bug_fmt 24: 0x7f55525d0668 - >::fold_ty 25: 0x7f555244cc3a - rustc_middle[d72fdf6c6b2250dd]::ty::util::fold_list:: as rustc_type_ir[564c8b4ab48cfb63]::fold::TypeFoldable>::try_fold_with::{closure#0}> 26: 0x7f555245954d - rustc_ty_utils[4d21410b90b11ab4]::abi::fn_abi_new_uncached 27: 0x7f555244b9d3 - rustc_ty_utils[4d21410b90b11ab4]::abi::fn_abi_of_instance 28: 0x7f5552447418 - rustc_query_system[80421863a267aa4a]::query::plumbing::try_execute_query:: 29: 0x7f55528363b4 - ::predefine_fn 30: 0x7f5553870492 - rustc_codegen_llvm[97721b0dbde85cfe]::base::compile_codegen_unit::module_codegen 31: 0x7f555386f7ca - rustc_codegen_llvm[97721b0dbde85cfe]::base::compile_codegen_unit 32: 0x7f5553b252f6 - rustc_codegen_ssa[339876f8f01653dd]::base::codegen_crate:: 33: 0x7f5553b24b71 - ::codegen_crate 34: 0x7f5553676401 - ::time::, rustc_interface[5de5436d20c61019]::passes::start_codegen::{closure#0}> 35: 0x7f5553675f49 - rustc_interface[5de5436d20c61019]::passes::start_codegen 36: 0x7f5553672af8 - ::enter::<::ongoing_codegen::{closure#0}::{closure#0}, core[3f771377e3383c20]::result::Result, rustc_span[36b4d2a6b64dd9a9]::ErrorGuaranteed>> 37: 0x7f5553670924 - ::ongoing_codegen 38: 0x7f555366f66c - rustc_span[36b4d2a6b64dd9a9]::with_source_map::, rustc_interface[5de5436d20c61019]::interface::run_compiler, rustc_driver_impl[fadf77a465939c7e]::run_compiler::{closure#1}>::{closure#0}::{closure#0}> 39: 0x7f5553666b1c - std[b4a766eaf44c2ca8]::sys_common::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[fadf77a465939c7e]::run_compiler::{closure#1}>::{closure#0}, core[3f771377e3383c20]::result::Result<(), rustc_span[36b4d2a6b64dd9a9]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[3f771377e3383c20]::result::Result<(), rustc_span[36b4d2a6b64dd9a9]::ErrorGuaranteed>> 40: 0x7f555366654a - <::spawn_unchecked_, rustc_driver_impl[fadf77a465939c7e]::run_compiler::{closure#1}>::{closure#0}, core[3f771377e3383c20]::result::Result<(), rustc_span[36b4d2a6b64dd9a9]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[3f771377e3383c20]::result::Result<(), rustc_span[36b4d2a6b64dd9a9]::ErrorGuaranteed>>::{closure#1} as core[3f771377e3383c20]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 41: 0x7f5551133793 - as core::ops::function::FnOnce>::call_once::h302a99ca9b0b5ec7 at /rustc/ff4b772f805ec1e1c1bd7e189ab8d5a4e3a6ef13/library/alloc/src/boxed.rs:1987:9 42: 0x7f5551133793 - as core::ops::function::FnOnce>::call_once::h4a906cac1587b7da at /rustc/ff4b772f805ec1e1c1bd7e189ab8d5a4e3a6ef13/library/alloc/src/boxed.rs:1987:9 43: 0x7f5551133793 - std::sys::unix::thread::Thread::new::thread_start::heb9513f4b22d271f at /rustc/ff4b772f805ec1e1c1bd7e189ab8d5a4e3a6ef13/library/std/src/sys/unix/thread.rs:108:17 44: 0x7f5550ff8609 - start_thread 45: 0x7f5550f1b133 - clone 46: 0x0 - 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.70.0-nightly (ff4b772f8 2023-03-10) running on x86_64-unknown-linux-gnu note: compiler flags: --crate-type bin -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 note: some of the compiler flags provided by cargo are hidden query stack during panic: #0 [fn_abi_of_instance] computing call ABI of `<[closure@src/main.rs:36:25: 36:28] as core::ops::function::FnOnce<(Emplacable<()>,)>>::call_once - shim(vtable)` end of query stack ```

Jules-Bertholet commented 1 year ago

@rustbot label +F-type_alias_impl_trait +requires-nightly

langston-barrett commented 1 year ago

Triaged with Icemelter. Steps performed:

Regression in nightly-2022-11-20

searched nightlies: from nightly-2022-11-18 to nightly-2023-03-18 regressed nightly: nightly-2022-11-20 searched commit range: https://github.com/rust-lang/rust/compare/b833ad56f46a0bbe0e8729512812a161e7dae28a...c5d82ed7a4ad94a538bb87e5016e7d5ce0bd434b regressed commit: https://github.com/rust-lang/rust/commit/5e6de2369c82ed0b36e6b651b041bad5cb5e1ef8

bisected with cargo-bisect-rustc v0.6.5 Host triple: x86_64-unknown-linux-gnu Reproduce with: ```bash cargo bisect-rustc /tmp/bisect-qI7jgs.sh --preserve ```
Details

rustc version: ``` rustc 1.70.0-nightly (13afbdaa0 2023-03-17) binary: rustc commit-hash: 13afbdaa0655dda23d7129e59ac48f1ec88b2084 commit-date: 2023-03-17 host: x86_64-unknown-linux-gnu release: 1.70.0-nightly LLVM version: 15.0.7 ``` Icemelter version: v0.2.0 Icemelter command line: ```sh 'icemelter' '--markdown' '--bisect' 'ice.rs' '--' 'rustc' '+nightly' '--crate-type' 'bin' '-C' 'embed-bitcode=no' '-C' 'codegen-units=1' '-C' 'debuginfo=2' ``` @rustbot label +S-bug-has-mcve Do you have feedback about this report? Please [file an issue](https://github.com/langston-barrett/icemelter/issues)!

Alexendoo commented 1 year ago

No longer ICEs since #113108