diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2025-08-06 21:29:27 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-06 21:29:27 +0200 |
| commit | 940a003985e354e5977e38dd588d0977d43f8622 (patch) | |
| tree | ce1f75aa53a047108290c159263762affbba62f6 | |
| parent | 96a41c5abadd83e7404134c48dd4440c9c193e5c (diff) | |
| parent | f6ce4ac9d38fca2df5bc408de8f4c2567d2f2709 (diff) | |
| download | rust-940a003985e354e5977e38dd588d0977d43f8622.tar.gz rust-940a003985e354e5977e38dd588d0977d43f8622.zip | |
Rollup merge of #144835 - compiler-errors:tail-call-sig-binder, r=WaffleLapkin
Anonymize binders in tail call sig See the comment for explanation Fixes rust-lang/rust#144826 r? WaffleLapkin
| -rw-r--r-- | compiler/rustc_mir_build/src/check_tail_calls.rs | 6 | ||||
| -rw-r--r-- | tests/ui/explicit-tail-calls/higher-ranked-arg.rs | 13 |
2 files changed, 18 insertions, 1 deletions
diff --git a/compiler/rustc_mir_build/src/check_tail_calls.rs b/compiler/rustc_mir_build/src/check_tail_calls.rs index b4c8b20e50f..3ecccb422c4 100644 --- a/compiler/rustc_mir_build/src/check_tail_calls.rs +++ b/compiler/rustc_mir_build/src/check_tail_calls.rs @@ -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:?}") diff --git a/tests/ui/explicit-tail-calls/higher-ranked-arg.rs b/tests/ui/explicit-tail-calls/higher-ranked-arg.rs new file mode 100644 index 00000000000..e60686ab511 --- /dev/null +++ b/tests/ui/explicit-tail-calls/higher-ranked-arg.rs @@ -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() {} |
