Skip to content

ICE: Normalizing Binder without wrapping in a Binder #95421

Description

@QuineDot

Code

Library version (choose "Build" from the pulldown):

// Compile as library
fn h5<T>(_: T)
where
    for<'x> fn(&'x u32): Fn(&'x u32),
{
}

Binary version:

// Compile as binary
fn h5<T>(_: T)
where
    for<'x> fn(&'x u32): Fn(&'x u32),
{
}

fn main(){
    h5(|_|{})
}

The two have (slightly) differing output. Note: If you compile as a binary but don't call the problematic function, compilation succeeds. Compiling as a library ICEs even when the function is private.

Meta

  • Stable Playground 1.59.0
  • Beta Playground 1.60.0-beta.5 (2022-03-18 6ee5a40)
  • Nightly Playground 1.61.0-nightly (2022-03-19 8d60bf4)
  • Godbolt 1.42.0 -- present (spot checked)

Error output

Library version

warning: function is never used: `h5`
 [--> src/lib.rs:1:4
](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021#)  |
1 | fn h5<T>(_: T)
  |    ^^
  |
  = note: `#[warn(dead_code)]` on by defaulterror: internal compiler error: unexpected panic

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 (9d1b2106e 2022-02-23) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type lib

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

query stack during panic:
#0 [evaluate_obligation] evaluating trait selection obligation `for<'x> for<'x> fn(&'x u32): core::ops::function::Fn<(&'x u32,)>`
#1 [optimized_mir] optimizing MIR for `h5`
end of query stack

Binary version

error: internal compiler error: unexpected panic

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 (9d1b2106e 2022-02-23) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type bin

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

query stack during panic:
#0 [evaluate_obligation] evaluating trait selection obligation `for<'x> for<'x> fn(&'x u32): core::ops::function::Fn<(&'x u32,)>`
#1 [typeck] type-checking `main`
#2 [typeck] type-checking `main::{closure#0}`
#3 [typeck_item_bodies] type-checking all item bodies
#4 [analysis] running analysis passes on this crate
end of query stack
Backtrace (Library version)


thread 'rustc' panicked at 'Normalizing Binder(<for<'x> fn(&'x u32) as std::ops::Fn<(&'x u32,)>>, []) without wrapping in a `Binder`', compiler/rustc_trait_selection/src/traits/project.rs:333:9
stack backtrace:
   0: rust_begin_unwind
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:116:14
   2: rustc_data_structures::stack::ensure_sufficient_stack::<rustc_middle::ty::sty::Binder<rustc_middle::ty::sty::TraitRef>, rustc_trait_selection::traits::project::normalize_with_depth_to<rustc_middle::ty::sty::Binder<rustc_middle::ty::sty::TraitRef>>::{closure#0}>
   3: rustc_trait_selection::traits::project::normalize_with_depth::<rustc_middle::ty::sty::Binder<rustc_middle::ty::sty::TraitRef>>
   4: rustc_data_structures::stack::ensure_sufficient_stack::<rustc_infer::traits::project::Normalized<rustc_middle::ty::sty::Binder<rustc_middle::ty::sty::TraitRef>>, <rustc_trait_selection::traits::select::SelectionContext>::confirm_fn_pointer_candidate::{closure#1}>
   5: <rustc_trait_selection::traits::select::SelectionContext>::confirm_candidate
   6: <rustc_trait_selection::traits::select::SelectionContext>::evaluate_stack
   7: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_anon_task::<rustc_middle::ty::context::TyCtxt, <rustc_trait_selection::traits::select::SelectionContext>::in_task<<rustc_trait_selection::traits::select::SelectionContext>::evaluate_trait_predicate_recursively::{closure#2}, core::result::Result<rustc_middle::traits::select::EvaluationResult, rustc_middle::traits::select::OverflowError>>::{closure#0}, core::result::Result<rustc_middle::traits::select::EvaluationResult, rustc_middle::traits::select::OverflowError>>
   8: <rustc_trait_selection::traits::select::SelectionContext>::evaluate_trait_predicate_recursively
   9: rustc_data_structures::stack::ensure_sufficient_stack::<core::result::Result<rustc_middle::traits::select::EvaluationResult, rustc_middle::traits::select::OverflowError>, <rustc_trait_selection::traits::select::SelectionContext>::evaluate_predicate_recursively::{closure#0}>
  10: <rustc_trait_selection::traits::select::SelectionContext>::evaluate_root_obligation
  11: <rustc_infer::infer::InferCtxtBuilder>::enter_with_canonical::<rustc_middle::ty::ParamEnvAnd<rustc_middle::ty::Predicate>, core::result::Result<rustc_middle::traits::select::EvaluationResult, rustc_middle::traits::select::OverflowError>, rustc_traits::evaluate_obligation::evaluate_obligation::{closure#0}>
  12: rustc_traits::evaluate_obligation::evaluate_obligation
  13: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::evaluate_obligation, rustc_query_impl::plumbing::QueryCtxt>
  14: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::evaluate_obligation
  15: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt>::predicate_must_hold_considering_regions
  16: <rustc_trait_selection::traits::fulfill::FulfillProcessor>::progress_changed_obligations
  17: <rustc_data_structures::obligation_forest::ObligationForest<rustc_trait_selection::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection::traits::fulfill::FulfillProcessor, rustc_data_structures::obligation_forest::Outcome<rustc_trait_selection::traits::fulfill::PendingPredicateObligation, rustc_infer::traits::FulfillmentErrorCode>>
  18: <rustc_trait_selection::traits::fulfill::FulfillmentContext as rustc_infer::traits::engine::TraitEngine>::select_all_or_error
  19: <rustc_infer::infer::InferCtxtBuilder>::enter::<bool, rustc_trait_selection::traits::impossible_predicates::{closure#0}>
  20: rustc_trait_selection::traits::impossible_predicates
  21: <rustc_mir_transform::const_prop::ConstProp as rustc_middle::mir::MirPass>::run_pass
  22: rustc_mir_transform::pass_manager::run_passes
  23: rustc_mir_transform::optimized_mir
  24: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::DefId, &rustc_middle::mir::Body>>
  25: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::optimized_mir
  26: <rustc_metadata::rmeta::encoder::EncodeContext>::encode_crate_root
  27: rustc_metadata::rmeta::encoder::encode_metadata_impl
  28: rustc_data_structures::sync::join::<rustc_metadata::rmeta::encoder::encode_metadata::{closure#0}, rustc_metadata::rmeta::encoder::encode_metadata::{closure#1}, rustc_metadata::rmeta::encoder::EncodedMetadata, ()>
  29: rustc_metadata::rmeta::encoder::encode_metadata
  30: <rustc_interface::queries::Queries>::ongoing_codegen
  31: <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>>
  32: 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}>
  33: rustc_interface::interface::create_compiler_and_run::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>
  34: <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.

Backtrace (Binary version)

thread 'rustc' panicked at 'Normalizing Binder(<for<'x> fn(&'x u32) as std::ops::Fn<(&'x u32,)>>, []) without wrapping in a `Binder`', compiler/rustc_trait_selection/src/traits/project.rs:333:9
stack backtrace:
   0: rust_begin_unwind
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:116:14
   2: rustc_data_structures::stack::ensure_sufficient_stack::<rustc_middle::ty::sty::Binder<rustc_middle::ty::sty::TraitRef>, rustc_trait_selection::traits::project::normalize_with_depth_to<rustc_middle::ty::sty::Binder<rustc_middle::ty::sty::TraitRef>>::{closure#0}>
   3: rustc_trait_selection::traits::project::normalize_with_depth::<rustc_middle::ty::sty::Binder<rustc_middle::ty::sty::TraitRef>>
   4: rustc_data_structures::stack::ensure_sufficient_stack::<rustc_infer::traits::project::Normalized<rustc_middle::ty::sty::Binder<rustc_middle::ty::sty::TraitRef>>, <rustc_trait_selection::traits::select::SelectionContext>::confirm_fn_pointer_candidate::{closure#1}>
   5: <rustc_trait_selection::traits::select::SelectionContext>::confirm_candidate
   6: <rustc_trait_selection::traits::select::SelectionContext>::evaluate_stack
   7: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_anon_task::<rustc_middle::ty::context::TyCtxt, <rustc_trait_selection::traits::select::SelectionContext>::in_task<<rustc_trait_selection::traits::select::SelectionContext>::evaluate_trait_predicate_recursively::{closure#2}, core::result::Result<rustc_middle::traits::select::EvaluationResult, rustc_middle::traits::select::OverflowError>>::{closure#0}, core::result::Result<rustc_middle::traits::select::EvaluationResult, rustc_middle::traits::select::OverflowError>>
   8: <rustc_trait_selection::traits::select::SelectionContext>::evaluate_trait_predicate_recursively
   9: rustc_data_structures::stack::ensure_sufficient_stack::<core::result::Result<rustc_middle::traits::select::EvaluationResult, rustc_middle::traits::select::OverflowError>, <rustc_trait_selection::traits::select::SelectionContext>::evaluate_predicate_recursively::{closure#0}>
  10: <rustc_trait_selection::traits::select::SelectionContext>::evaluate_root_obligation
  11: <rustc_infer::infer::InferCtxtBuilder>::enter_with_canonical::<rustc_middle::ty::ParamEnvAnd<rustc_middle::ty::Predicate>, core::result::Result<rustc_middle::traits::select::EvaluationResult, rustc_middle::traits::select::OverflowError>, rustc_traits::evaluate_obligation::evaluate_obligation::{closure#0}>
  12: rustc_traits::evaluate_obligation::evaluate_obligation
  13: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::evaluate_obligation, rustc_query_impl::plumbing::QueryCtxt>
  14: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::evaluate_obligation
  15: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt>::predicate_must_hold_considering_regions
  16: <rustc_trait_selection::traits::fulfill::FulfillProcessor>::progress_changed_obligations
  17: <rustc_data_structures::obligation_forest::ObligationForest<rustc_trait_selection::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection::traits::fulfill::FulfillProcessor, rustc_data_structures::obligation_forest::Outcome<rustc_trait_selection::traits::fulfill::PendingPredicateObligation, rustc_infer::traits::FulfillmentErrorCode>>
  18: <rustc_trait_selection::traits::fulfill::FulfillmentContext as rustc_infer::traits::engine::TraitEngine>::select_where_possible
  19: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_call
  20: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  21: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  22: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_block_with_expected
  23: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  24: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_return_expr
  25: rustc_typeck::check::check::check_fn
  26: <rustc_infer::infer::InferCtxtBuilder>::enter::<&rustc_middle::ty::context::TypeckResults, <rustc_typeck::check::inherited::InheritedBuilder>::enter<rustc_typeck::check::typeck_with_fallback<rustc_typeck::check::typeck::{closure#0}>::{closure#1}, &rustc_middle::ty::context::TypeckResults>::{closure#0}>
  27: rustc_typeck::check::typeck
  28: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalDefId, &rustc_middle::ty::context::TypeckResults>>
  29: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck
  30: rustc_typeck::check::typeck
  31: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalDefId, &rustc_middle::ty::context::TypeckResults>>
  32: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck
  33: <rustc_middle::hir::map::Map>::par_body_owners::<rustc_typeck::check::typeck_item_bodies::{closure#0}>
  34: rustc_typeck::check::typeck_item_bodies
  35: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<(), ()>>
  36: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::typeck_item_bodies, rustc_query_impl::plumbing::QueryCtxt>
  37: <rustc_session::session::Session>::time::<(), rustc_typeck::check_crate::{closure#7}>
  38: rustc_typeck::check_crate
  39: rustc_interface::passes::analysis
  40: 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>>>
  41: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
  42: <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>>
  43: 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}>
  44: rustc_interface::interface::create_compiler_and_run::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>
  45: <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.

Version it worked on

Works on 1.41.0. Works on versions prior to this down to 1.7.0 (spot checked). (Version 1.6.0 gives obsoleted error E0193.)

Versions with regression

Versions 1.42.0 and up (spot checked). The error changes between 1.54.0 and 1.55.0.

@rustbot modify labels: +regression-from-stable-to-stable -regression-untriaged

Activity

  1. added
    C-bugCategory: This is a bug.
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Mar 28, 2022
  2. added
    regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Mar 28, 2022
  3. Dylan-DPC commented on Mar 29, 2022

    @Dylan-DPC
    Member

    output from bisect:

    looking for regression commit between 2021-09-01 and 2021-09-02
    cloning rust repository
    fetching (via local git) commits from 29ef6cf1637aa8317f8911f93f14e18d404c1b0e to 50171c310cd15e1b2d3723766ce64e2e4d6696fc
    refreshing repository at "rust.git"
    From https://github.com/rust-lang/rust
     * branch                    HEAD       -> FETCH_HEAD
    opening existing repository at "rust.git"
    looking up first commit
    looking up second commit
    checking that commits are by bors and thus have ci artifacts...
    finding bors merge commits
    found 9 bors merge commits in the specified range
      commit[0] 2021-08-31UTC: Auto merge of #88506 - Mark-Simulacrum:fix-rlibs, r=ehuss
      commit[1] 2021-08-31UTC: Auto merge of #88533 - oli-obk:tait_🧊, r=spastorino
      commit[2] 2021-09-01UTC: Auto merge of #87688 - camsteffen:let-else, r=cjgillot
      commit[3] 2021-09-01UTC: Auto merge of #88121 - camelid:better-recursive-alias-error, r=estebank
      commit[4] 2021-09-01UTC: Auto merge of #88272 - willcrichton:mutable-sparse-matrix, r=ecstatic-morse
      commit[5] 2021-09-01UTC: Auto merge of #88556 - m-ou-se:rollup-q636wyd, r=m-ou-se
      commit[6] 2021-09-01UTC: Auto merge of #88395 - ricky26:llvm-submodule, r=nikic
      commit[7] 2021-09-01UTC: Auto merge of #88269 - prconrad:doctest-persist-binaries, r=jyn514
      commit[8] 2021-09-01UTC: Auto merge of #88563 - ehuss:update-cargo-books, r=ehuss
    
  4. compiler-errors commented on Mar 29, 2022

    @compiler-errors
    Contributor

    @Dylan-DPC, I got the same bisection as you, but then realized it was because #88563 added support for edition = "2021" in cargo, and before 2021-09-01, it wasn't ICEing but failing to cargo-build (which makes bisect-rustc think it regressed there).

    I don't think this code ever worked. Before 1.56 (when @jackh726 added the wonderful #85499), rustc ICEs with failure to relate late-bound and placeholder regions, and after 1.56, we fail with this binder variable issue. The library example provided above only newly begins to fail between 1.41 and 1.42 because someone added a check related to const prop that caused the predicate to be evaluated eagerly, but the binary version has always ICEd in some form.

    The bug

    This is probably a bug because we overwrite the late-bound regions we collect here in the where-clause (which we attach to the HIR id of the type in the LHS of Ty: Trait + Trait) with the ones we collect here when visiting the fn type.

    Not exactly sure what the best way to fix this bug is. I'll play around with solutions, but don't want to claim the issue because I think it's a bit above my pay-grade, so to speak, since I know very little about rustc_resolve::late::lifetimes.

  5. jackh726 commented on Mar 29, 2022

    @jackh726
    Member

    Heh this is weird. I was actually confused for a bit, because it looked like 'x was bound everywhere. But it's it a bit ambiguous where the for<'x> should go: on the fn or on the TraitRef.

  6. apiraino commented on Mar 30, 2022

    @apiraino
    Contributor

    Assigning priority as discussed in the Zulip thread of the Prioritization Working Group.

    @rustbot label -I-prioritize +P-medium

  7. added and removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Mar 30, 2022
  8. QuineDot commented on Apr 3, 2022

    @QuineDot
    Author

    I don't think this code ever worked. Before 1.56 (when @jackh726 added the wonderful #85499), rustc ICEs with failure to relate late-bound and placeholder regions, and after 1.56, we fail with this binder variable issue. The library example provided above only newly begins to fail between 1.41 and 1.42 because someone added a check related to const prop that caused the predicate to be evaluated eagerly, but the binary version has always ICEd in some form.

    Ah, sorry for not catching that -- I probably wouldn't have filed it as a regression if I had (though I guess it is still technically one).

  9. compiler-errors commented on Mar 11, 2023

    @compiler-errors
    Contributor

    I think this is "fixed" (ICE -> error) by #108834. It's probably actually fixed by #108918 (error -> compiles), though.

  10. removed
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    on Sep 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions