Repository: rust
Issue: ICE: Normalizing Binder without wrapping in a Binder
Labels: P-medium,T-compiler,regression-from-stable-to-stable,C-bug,glacier

### Code

[Library version (choose "Build" from the pulldown):](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=f340049395bb2407b90ac46c5e243471)
```Rust
// Compile as library
fn h5<T>(_: T)
where
    for<'x> fn(&'x u32): Fn(&'x u32),
{
}
```
[Binary version:](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=43e99506a54b2e64f9ebc56d5520dd0b)
```Rust
// 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 6ee5a408a3bbc7659863)
* Nightly Playground 1.61.0-nightly (2022-03-19 8d60bf427a4b055f4641)
* 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
```

<details><summary><strong>Backtrace (Library version)</strong></summary>
<p>

```

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.
```

</p>
</details>

<details><summary><strong>Backtrace (Binary version)</strong></summary>
<p>

```
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.
```

</p>
</details>

### Version it worked on

[Works on `1.41.0`.](https://rust.godbolt.org/z/aT6z6ehxe)  Works on versions prior to this down to [`1.7.0`](https://rust.godbolt.org/z/e5nf31rzj) (spot checked).  (Version [`1.6.0`](https://rust.godbolt.org/z/fdPPbnazG) gives obsoleted error [`E0193`](https://doc.rust-lang.org/error-index.html#E0193).)

### Versions with regression
Versions [`1.42.0`](https://rust.godbolt.org/z/6qzMjsb4o) and up (spot checked).  The error changes between [`1.54.0`](https://rust.godbolt.org/z/ebMq6acr8) and [`1.55.0`](https://rust.godbolt.org/z/WccE9GdEz).

@rustbot modify labels: +regression-from-stable-to-stable -regression-untriaged