Change:
<!-- Thank you for finding an Internal Compiler Error! If possible, try to provide a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for how to create smaller examples. --When creating this I found that it did not error if the function was not called and it also seemed to require it to be a function not just an argument of type T or (from what I tested) a different impl Trait although it could be any Fn* trait <!-- If you're using the stable version of the compiler, you should also check if the bug also exists in the beta or nightly versions. --: This appears to only happen on nightly while stable and beta generate useful error reports <!-- Include a backtrace in the code block by setting in your environment. E.g. . --<details<summary<strongBacktrace</strong</summary<p</p</details<!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOTEND --
label regression-from-stable-to-nightly
does not ICE but errors correctly while does ICE
glacier ""
searched nightlies: from nightly-2021-09-17 to nightly-2021-09-18 regressed nightly: nightly-2021-09-18 searched commits: from to regressed commit: <details<summarybisected with <a href=''cargo-bisect-rustc</av0.6.0</summaryHost triple: x86_64-apple-darwin Reproduce with: </detailsThat's , so cc
I've got this. claim Interestingly, this is precisely the kind of thing that is hopefully going to help harden against: "hidden" s when calling and such
Assigning priority as discussed in the of the Prioritization Working Group. label -I-prioritize +P-medium

Discussion:
&self, obligation: &PredicateObligation<'tcx>, err: &mut DiagnosticBuilder<'_>, <del> trait_ref: &ty::Binder<'tcx, ty::TraitRef<'tcx>>, </del> <ins> poly_trait_ref: &ty::Binder<'tcx, ty::TraitRef<'tcx>>, </ins> has_custom_message: bool, ) -> bool { let span = obligation.cause.span;

never_suggest_borrow.push(self.tcx.get_diagnostic_item(sym::send_trait).unwrap()); let param_env = obligation.param_env; <del> let trait_ref = trait_ref.skip_binder(); </del> <ins> let trait_ref = poly_trait_ref.skip_binder(); </ins> let found_ty = trait_ref.self_ty(); let found_ty_str = found_ty.to_string();

let mut_substs = self.tcx.mk_substs_trait(mut_borrowed_found_ty, &[]); // Try to apply the original trait binding obligation by borrowing. <del> let mut try_borrowing = |new_imm_trait_ref: ty::TraitRef<'tcx>, new_mut_trait_ref: ty::TraitRef<'tcx>, expected_trait_ref: ty::TraitRef<'tcx>, </del> <ins> let mut try_borrowing = |new_imm_trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>, new_mut_trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>, expected_trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>, </ins> blacklist: &[DefId]| -> bool { <del> if blacklist.contains(&expected_trait_ref.def_id) { </del> <ins> if blacklist.contains(&expected_trait_ref.def_id()) { </ins> return false; } let imm_result = self.predicate_must_hold_modulo_regions(&Obligation::new( ObligationCause::dummy(), param_env, <del> ty::Binder::dummy(new_imm_trait_ref).without_const().to_predicate(self.tcx), </del> <ins> new_imm_trait_ref.without_const().to_predicate(self.tcx), </ins> )); let mut_result = self.predicate_must_hold_modulo_regions(&Obligation::new( ObligationCause::dummy(), param_env, <del> ty::Binder::dummy(new_mut_trait_ref).without_const().to_predicate(self.tcx), </del> <ins> new_mut_trait_ref.without_const().to_predicate(self.tcx), </ins> )); if imm_result || mut_result {

}; if let ObligationCauseCode::ImplDerivedObligation(obligation) = &*code { <del> let expected_trait_ref = obligation.parent_trait_ref.skip_binder(); let new_imm_trait_ref = ty::TraitRef::new(obligation.parent_trait_ref.def_id(), imm_substs); let new_mut_trait_ref = ty::TraitRef::new(obligation.parent_trait_ref.def_id(), mut_substs); </del> <ins> let expected_trait_ref = obligation.parent_trait_ref; let new_imm_trait_ref = poly_trait_ref .rebind(ty::TraitRef::new(obligation.parent_trait_ref.def_id(), imm_substs)); let new_mut_trait_ref = poly_trait_ref .rebind(ty::TraitRef::new(obligation.parent_trait_ref.def_id(), mut_substs)); </ins> return try_borrowing(new_imm_trait_ref, new_mut_trait_ref, expected_trait_ref, &[]); } else if let ObligationCauseCode::BindingObligation(_, _) | ObligationCauseCode::ItemObligation(_) = &*code { return try_borrowing( <del> ty::TraitRef::new(trait_ref.def_id, imm_substs), ty::TraitRef::new(trait_ref.def_id, mut_substs), trait_ref, </del> <ins> poly_trait_ref.rebind(ty::TraitRef::new(trait_ref.def_id, imm_substs)), poly_trait_ref.rebind(ty::TraitRef::new(trait_ref.def_id, mut_substs)), *poly_trait_ref, </ins> &never_suggest_borrow[..], ); } else {

<ins> // check-fail // Ensure we don't error when emitting trait bound not satisfied when self type // has late bound var fn main() { test(&|| 0); //~ ERROR the trait bound } trait Trait {} fn test<T>(arg: &impl Fn() -> T) where for<'a> &'a T: Trait {} </ins>

<ins> error[E0277]: the trait bound `for<'a> &'a _: Trait` is not satisfied --> $DIR/issue-89333.rs:6:5 | LL |     test(&|| 0); |     ^^^^ the trait `for<'a> Trait` is not implemented for `&'a _` | note: required by a bound in `test` --> $DIR/issue-89333.rs:11:55 | LL | fn test<T>(arg: &impl Fn() -> T) where for<'a> &'a T: Trait {} |                                                       ^^^^^ required by this bound in `test` error: aborting due to previous error For more information about this error, try `rustc --explain E0277`. </ins>