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 “unexpected bound ty in binder” involving type binder, Fn-family trait and closure #108814

Open
fmease opened this issue Mar 6, 2023 · 5 comments
Assignees
Labels
C-bug Category: This is a bug. F-non_lifetime_binders `#![feature(non_lifetime_binders)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@fmease
Copy link
Member

fmease commented Mar 6, 2023

#![feature(non_lifetime_binders)]

fn take(_: impl for<T> FnOnce(T) -> T) {}

fn main() {
    take(|x| x)
}

Error output

warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes
 --> take_id.rs:1:12
  |
1 | #![feature(non_lifetime_binders)]
  |            ^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information
  = note: `#[warn(incomplete_features)]` on by default

error: internal compiler error: /rustc/ac4379fea9e83465d814bb05005689f49bd2141e/compiler/rustc_middle/src/ty/fold.rs:297:33: unexpected bound ty in binder: BoundTy { var: 0, kind: Anon(0) }

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/ac4379fea9e83465d814bb05005689f49bd2141e/compiler/rustc_errors/src/lib.rs:1644:9
Backtrace

stack backtrace:
   0:     0x7f1e8f56653a - std::backtrace_rs::backtrace::libunwind::trace::ha7277b97837a680e
                               at /rustc/ac4379fea9e83465d814bb05005689f49bd2141e/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f1e8f56653a - std::backtrace_rs::backtrace::trace_unsynchronized::h2eae6446df1fb3c7
                               at /rustc/ac4379fea9e83465d814bb05005689f49bd2141e/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f1e8f56653a - std::sys_common::backtrace::_print_fmt::hcce758637ada6e5e
                               at /rustc/ac4379fea9e83465d814bb05005689f49bd2141e/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7f1e8f56653a - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h048020a39b1c8541
                               at /rustc/ac4379fea9e83465d814bb05005689f49bd2141e/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f1e8f5c9cee - core::fmt::write::h8cb0e60463f917ed
                               at /rustc/ac4379fea9e83465d814bb05005689f49bd2141e/library/core/src/fmt/mod.rs:1232:17
   5:     0x7f1e8f5593e5 - std::io::Write::write_fmt::h6a4bf43ae33fb5c2
                               at /rustc/ac4379fea9e83465d814bb05005689f49bd2141e/library/std/src/io/mod.rs:1684:15
   6:     0x7f1e8f566305 - std::sys_common::backtrace::_print::h01686671a8f910e8
                               at /rustc/ac4379fea9e83465d814bb05005689f49bd2141e/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x7f1e8f566305 - std::sys_common::backtrace::print::hb036d568178720fa
                               at /rustc/ac4379fea9e83465d814bb05005689f49bd2141e/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x7f1e8f56907f - std::panicking::default_hook::{{closure}}::hac5f47cee0e06043
                               at /rustc/ac4379fea9e83465d814bb05005689f49bd2141e/library/std/src/panicking.rs:271:22
   9:     0x7f1e8f568dbb - std::panicking::default_hook::hc30c65fb62dafbb3
                               at /rustc/ac4379fea9e83465d814bb05005689f49bd2141e/library/std/src/panicking.rs:290:9
  10:     0x7f1e927e25c5 - rustc_driver_impl[1bafdf3e8b0cbe0c]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7f1e8f5698bd - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hec34b5992590fa06
                               at /rustc/ac4379fea9e83465d814bb05005689f49bd2141e/library/alloc/src/boxed.rs:2001:9
  12:     0x7f1e8f5698bd - std::panicking::rust_panic_with_hook::h44e2196c38854f66
                               at /rustc/ac4379fea9e83465d814bb05005689f49bd2141e/library/std/src/panicking.rs:696:13
  13:     0x7f1e92d3e671 - std[f869becc71c6b456]::panicking::begin_panic::<rustc_errors[d0ebe06311983455]::ExplicitBug>::{closure#0}
  14:     0x7f1e92d36fe6 - std[f869becc71c6b456]::sys_common::backtrace::__rust_end_short_backtrace::<std[f869becc71c6b456]::panicking::begin_panic<rustc_errors[d0ebe06311983455]::ExplicitBug>::{closure#0}, !>
  15:     0x7f1e92daba26 - std[f869becc71c6b456]::panicking::begin_panic::<rustc_errors[d0ebe06311983455]::ExplicitBug>
  16:     0x7f1e92d8a1a6 - std[f869becc71c6b456]::panic::panic_any::<rustc_errors[d0ebe06311983455]::ExplicitBug>
  17:     0x7f1e92d85ba6 - <rustc_errors[d0ebe06311983455]::HandlerInner>::bug::<&alloc[56a1e614eb299497]::string::String>
  18:     0x7f1e92d85870 - <rustc_errors[d0ebe06311983455]::Handler>::bug::<&alloc[56a1e614eb299497]::string::String>
  19:     0x7f1e92d7cb7b - rustc_middle[6b96750649b9b523]::util::bug::opt_span_bug_fmt::<rustc_span[481fe46353bf1cdc]::span_encoding::Span>::{closure#0}
  20:     0x7f1e92d7b4ca - rustc_middle[6b96750649b9b523]::ty::context::tls::with_opt::<rustc_middle[6b96750649b9b523]::util::bug::opt_span_bug_fmt<rustc_span[481fe46353bf1cdc]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0x7f1e92d7b496 - rustc_middle[6b96750649b9b523]::ty::context::tls::with_context_opt::<rustc_middle[6b96750649b9b523]::ty::context::tls::with_opt<rustc_middle[6b96750649b9b523]::util::bug::opt_span_bug_fmt<rustc_span[481fe46353bf1cdc]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0x7f1e92d7cac6 - rustc_middle[6b96750649b9b523]::util::bug::opt_span_bug_fmt::<rustc_span[481fe46353bf1cdc]::span_encoding::Span>
  23:     0x7f1e90eeec13 - rustc_middle[6b96750649b9b523]::util::bug::bug_fmt
  24:     0x7f1e92a4230c - <rustc_middle[6b96750649b9b523]::ty::context::TyCtxt>::replace_late_bound_regions_uncached::<rustc_middle[6b96750649b9b523]::ty::sty::FnSig, <rustc_middle[6b96750649b9b523]::ty::context::TyCtxt>::replace_late_bound_regions<rustc_middle[6b96750649b9b523]::ty::sty::FnSig, <rustc_middle[6b96750649b9b523]::ty::context::TyCtxt>::erase_late_bound_regions<rustc_middle[6b96750649b9b523]::ty::sty::FnSig>::{closure#0}>::{closure#0}>::{closure#0}
  25:     0x7f1e90e228fd - <&rustc_middle[6b96750649b9b523]::ty::list::List<rustc_middle[6b96750649b9b523]::ty::Ty> as rustc_type_ir[52d4fefb1527696e]::fold::TypeFoldable<rustc_middle[6b96750649b9b523]::ty::context::TyCtxt>>::try_fold_with::<rustc_middle[6b96750649b9b523]::ty::fold::BoundVarReplacer<rustc_middle[6b96750649b9b523]::ty::fold::FnMutDelegate>>
  26:     0x7f1e90c1236b - <rustc_hir_typeck[b98449f9e1a7a434]::fn_ctxt::FnCtxt>::closure_sigs
  27:     0x7f1e90c10183 - <rustc_hir_typeck[b98449f9e1a7a434]::fn_ctxt::FnCtxt>::check_expr_closure
  28:     0x7f1e90b9f3fc - <rustc_hir_typeck[b98449f9e1a7a434]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  29:     0x7f1e90e86ebd - <rustc_hir_typeck[b98449f9e1a7a434]::fn_ctxt::FnCtxt>::check_argument_types
  30:     0x7f1e90b6d7bb - <rustc_hir_typeck[b98449f9e1a7a434]::fn_ctxt::FnCtxt>::check_call
  31:     0x7f1e90b9b6ad - <rustc_hir_typeck[b98449f9e1a7a434]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  32:     0x7f1e90bcacbe - <rustc_hir_typeck[b98449f9e1a7a434]::fn_ctxt::FnCtxt>::check_block_with_expected
  33:     0x7f1e90b9bbdf - <rustc_hir_typeck[b98449f9e1a7a434]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  34:     0x7f1e9166f7d4 - <rustc_hir_typeck[b98449f9e1a7a434]::fn_ctxt::FnCtxt>::check_return_expr
  35:     0x7f1e91667bc7 - rustc_hir_typeck[b98449f9e1a7a434]::check::check_fn
  36:     0x7f1e91651c37 - rustc_hir_typeck[b98449f9e1a7a434]::typeck
  37:     0x7f1e90a2052c - rustc_query_system[5157c2c547c7c596]::query::plumbing::try_execute_query::<rustc_query_impl[1c38571c4f3dd9ba]::queries::typeck, rustc_query_impl[1c38571c4f3dd9ba]::plumbing::QueryCtxt>
  38:     0x7f1e91faf34f - rustc_data_structures[afc619c2eff4eef5]::sync::par_for_each_in::<&[rustc_span[481fe46353bf1cdc]::def_id::LocalDefId], <rustc_middle[6b96750649b9b523]::hir::map::Map>::par_body_owners<rustc_hir_typeck[b98449f9e1a7a434]::typeck_item_bodies::{closure#0}>::{closure#0}>
  39:     0x7f1e91faf10f - rustc_hir_typeck[b98449f9e1a7a434]::typeck_item_bodies
  40:     0x7f1e91e2c55d - rustc_query_system[5157c2c547c7c596]::query::plumbing::try_execute_query::<rustc_query_impl[1c38571c4f3dd9ba]::queries::typeck_item_bodies, rustc_query_impl[1c38571c4f3dd9ba]::plumbing::QueryCtxt>
  41:     0x7f1e91e2c24b - <rustc_query_impl[1c38571c4f3dd9ba]::Queries as rustc_middle[6b96750649b9b523]::ty::query::QueryEngine>::typeck_item_bodies
  42:     0x7f1e90b68493 - <rustc_session[d491f4b0c10bdfb9]::session::Session>::time::<(), rustc_hir_analysis[717970e329447c82]::check_crate::{closure#7}>
  43:     0x7f1e90b64f4d - rustc_hir_analysis[717970e329447c82]::check_crate
  44:     0x7f1e90b5b072 - rustc_interface[841154c2f5280d71]::passes::analysis
  45:     0x7f1e92033d9d - rustc_query_system[5157c2c547c7c596]::query::plumbing::try_execute_query::<rustc_query_impl[1c38571c4f3dd9ba]::queries::analysis, rustc_query_impl[1c38571c4f3dd9ba]::plumbing::QueryCtxt>
  46:     0x7f1e92033a9f - <rustc_query_impl[1c38571c4f3dd9ba]::Queries as rustc_middle[6b96750649b9b523]::ty::query::QueryEngine>::analysis
  47:     0x7f1e91e63616 - <rustc_middle[6b96750649b9b523]::ty::context::GlobalCtxt>::enter::<rustc_driver_impl[1bafdf3e8b0cbe0c]::run_compiler::{closure#1}::{closure#2}::{closure#4}, core[c7837a1117e32cc5]::result::Result<(), rustc_span[481fe46353bf1cdc]::ErrorGuaranteed>>
  48:     0x7f1e91a47f48 - rustc_span[481fe46353bf1cdc]::with_source_map::<core[c7837a1117e32cc5]::result::Result<(), rustc_span[481fe46353bf1cdc]::ErrorGuaranteed>, rustc_interface[841154c2f5280d71]::interface::run_compiler<core[c7837a1117e32cc5]::result::Result<(), rustc_span[481fe46353bf1cdc]::ErrorGuaranteed>, rustc_driver_impl[1bafdf3e8b0cbe0c]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  49:     0x7f1e91a3f4dc - std[f869becc71c6b456]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[841154c2f5280d71]::util::run_in_thread_pool_with_globals<rustc_interface[841154c2f5280d71]::interface::run_compiler<core[c7837a1117e32cc5]::result::Result<(), rustc_span[481fe46353bf1cdc]::ErrorGuaranteed>, rustc_driver_impl[1bafdf3e8b0cbe0c]::run_compiler::{closure#1}>::{closure#0}, core[c7837a1117e32cc5]::result::Result<(), rustc_span[481fe46353bf1cdc]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[c7837a1117e32cc5]::result::Result<(), rustc_span[481fe46353bf1cdc]::ErrorGuaranteed>>
  50:     0x7f1e91a3ef0a - <<std[f869becc71c6b456]::thread::Builder>::spawn_unchecked_<rustc_interface[841154c2f5280d71]::util::run_in_thread_pool_with_globals<rustc_interface[841154c2f5280d71]::interface::run_compiler<core[c7837a1117e32cc5]::result::Result<(), rustc_span[481fe46353bf1cdc]::ErrorGuaranteed>, rustc_driver_impl[1bafdf3e8b0cbe0c]::run_compiler::{closure#1}>::{closure#0}, core[c7837a1117e32cc5]::result::Result<(), rustc_span[481fe46353bf1cdc]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[c7837a1117e32cc5]::result::Result<(), rustc_span[481fe46353bf1cdc]::ErrorGuaranteed>>::{closure#1} as core[c7837a1117e32cc5]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  51:     0x7f1e8f5737b3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hc371c06232f0c824
                               at /rustc/ac4379fea9e83465d814bb05005689f49bd2141e/library/alloc/src/boxed.rs:1987:9
  52:     0x7f1e8f5737b3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h7dc3758286df85d1
                               at /rustc/ac4379fea9e83465d814bb05005689f49bd2141e/library/alloc/src/boxed.rs:1987:9
  53:     0x7f1e8f5737b3 - std::sys::unix::thread::Thread::new::thread_start::h64782255c7c71ccd
                               at /rustc/ac4379fea9e83465d814bb05005689f49bd2141e/library/std/src/sys/unix/thread.rs:108:17
  54:     0x7f1e8f3068fd - <unknown>
  55:     0x7f1e8f388a60 - <unknown>
  56:                0x0 - <unknown>

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 (ac4379fea 2023-03-06) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [typeck] type-checking `main`
#1 [typeck_item_bodies] type-checking all item bodies
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error; 1 warning emitted

Meta

Latest master (ac4379f).

rustc -Vv:

rustc 1.70.0-nightly (ac4379fea 2023-03-06)
binary: rustc
commit-hash: ac4379fea9e83465d814bb05005689f49bd2141e
commit-date: 2023-03-06
host: x86_64-unknown-linux-gnu
release: 1.70.0-nightly
LLVM version: 15.0.7

@rustbot label F-non_lifetime_binders

@fmease fmease 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 Mar 6, 2023
@rustbot rustbot added the F-non_lifetime_binders `#![feature(non_lifetime_binders)]` label Mar 6, 2023
@fmease
Copy link
Member Author

fmease commented Mar 6, 2023

Doesn't actually need ITIAP, a normal bound works just as well:

#![feature(non_lifetime_binders)]

fn take<F>(_: F) where F: for<T> FnOnce(T) -> T {}

fn main() {
    take(|x| x)
}

@fmease fmease changed the title ICE “unexpected bound ty in binder” with closure and type binder in impl Trait in arg pos ICE “unexpected bound ty in binder” involving type binder, FnOnce and closure Mar 6, 2023
@compiler-errors compiler-errors self-assigned this Mar 6, 2023
@fmease
Copy link
Member Author

fmease commented Mar 6, 2023

|x| x should probably be rejected since we don't support type-generic closures (yet).

It's probably fine that the following is well-typed under non_lifetime_binders since it's impossible to call take at this time anyway.

fn take(id: impl for<T> Fn(T) -> T) {
    id(0);
    id("");
}

@compiler-errors
Copy link
Member

compiler-errors commented Mar 7, 2023

@fmease no need to, I've got a more minimal repro of that issue here:

#![feature(non_lifetime_binders)]

trait Foo: for<T> Bar<T> {}

trait Bar<T> {
    fn method() -> T;
}

fn x<T: Foo>() {
    let _: i32 = T::method();
}

fn main() {}

I'll need to fix this in a couple of steps.

@matthiaskrgr
Copy link
Member

another one, possibly

#![crate_type="lib"]

pub trait Foo<T> {
    type A;
    fn get::A
}


struct YetAnotherStruct<'a, I: for<isize> Foo<&'x &isize>> {
    field: I::A,
}

@compiler-errors
Copy link
Member

That ^ is a separate bug, also doesn't ICE with the code provided. I did minimize it tho:

#![feature(non_lifetime_binders)]

pub trait Foo<T> {
    type A;
}

struct YetAnotherStruct<'a, I: for<T> Foo<T>> {
    field: I::A,
}

fn main() {}

@fmease fmease changed the title ICE “unexpected bound ty in binder” involving type binder, FnOnce and closure ICE “unexpected bound ty in binder” involving type binder, Fn-family trait and closure Jun 17, 2023
@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Apr 15, 2024
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. F-non_lifetime_binders `#![feature(non_lifetime_binders)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. 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.

5 participants