Anonymize binders in tail call sig

This commit is contained in:
Michael Goulet 2025-08-02 17:36:34 +00:00
parent e1b9081e69
commit f6ce4ac9d3
2 changed files with 18 additions and 1 deletions

View file

@ -60,9 +60,13 @@ impl<'tcx> TailCallCkVisitor<'_, 'tcx> {
let BodyTy::Fn(caller_sig) = self.thir.body_type else {
span_bug!(
call.span,
"`become` outside of functions should have been disallowed by hit_typeck"
"`become` outside of functions should have been disallowed by hir_typeck"
)
};
// While the `caller_sig` does have its regions erased, it does not have its
// binders anonymized. We call `erase_regions` once again to anonymize any binders
// within the signature, such as in function pointer or `dyn Trait` args.
let caller_sig = self.tcx.erase_regions(caller_sig);
let ExprKind::Scope { value, .. } = call.kind else {
span_bug!(call.span, "expected scope, found: {call:?}")

View file

@ -0,0 +1,13 @@
// Regression test for <https://github.com/rust-lang/rust/issues/144826>.
//@ check-pass
#![feature(explicit_tail_calls)]
#![expect(incomplete_features)]
fn foo(x: fn(&i32)) {
become bar(x);
}
fn bar(_: fn(&i32)) {}
fn main() {}