Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 08d46c5

Browse files
Unrolled build for rust-lang#133607
Rollup merge of rust-lang#133607 - WaffleLapkin:tail-call-checks, r=compiler-errors implement checks for tail calls Quoting the [RFC draft](https://github.com/phi-go/rfcs/blob/guaranteed-tco/text/0000-explicit-tail-calls.md): > The argument to become is a function (or method) call, that exactly matches the function signature and calling convention of the callee. The intent is to ensure a matching ABI. Note that lifetimes may differ as long as they pass borrow checking, see [below](https://github.com/phi-go/rfcs/blob/guaranteed-tco/text/0000-explicit-tail-calls.md#return-type-coercion) for specifics on the return type. > Tail calling closures and tail calling from closures is not allowed. This is due to the high implementation effort, see below, this restriction can be lifted by a future RFC. > Invocations of operators were considered as valid targets but were rejected on grounds of being too error-prone. In any case, these can still be called as methods. > Tail calling [variadic functions](https://doc.rust-lang.org/beta/unstable-book/language-features/c-variadic.html) and tail calling from variadic functions is not allowed. As support for variadic function is stabilized on a per target level, support for tail-calls regarding variadic functions would need to follow a similar approach. To avoid this complexity and to minimize implementation effort for backends, this interaction is currently not allowed but support can be added with a future RFC. ----- The checks are implemented as a query, similarly to `check_unsafety`. The code is cherry-picked straight out of rust-lang#112657 which was written more than a year ago, so I expect we might need to change some things ^^"
2 parents c94848c + 144d6cc commit 08d46c5

30 files changed

+859
-12
lines changed

‎compiler/rustc_middle/src/query/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,12 @@ rustc_queries! {
916916
cache_on_disk_if { true }
917917
}
918918

919+
/// Checks well-formedness of tail calls (`become f()`).
920+
query check_tail_calls(key: LocalDefId) -> Result<(), rustc_errors::ErrorGuaranteed> {
921+
desc { |tcx| "tail-call-checking `{}`", tcx.def_path_str(key) }
922+
cache_on_disk_if { true }
923+
}
924+
919925
/// Returns the types assumed to be well formed while "inside" of the given item.
920926
///
921927
/// Note that we've liberated the late bound regions of function signatures, so

‎compiler/rustc_mir_build/src/build/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ pub(crate) fn mir_build<'tcx>(tcx: TyCtxtAt<'tcx>, def: LocalDefId) -> Body<'tcx
5050
return construct_error(tcx, def, e);
5151
}
5252

53+
if let Err(err) = tcx.check_tail_calls(def) {
54+
return construct_error(tcx, def, err);
55+
}
56+
5357
let body = match tcx.thir_body(def) {
5458
Err(error_reported) => construct_error(tcx, def, error_reported),
5559
Ok((thir, expr)) => {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /