rust/compiler
Guillaume Gomez 65479f7353
Rollup merge of #144917 - compiler-errors:tail-call-linked-lifetimes, r=lcnr
Enforce tail call type is related to body return type in borrowck

Like all call terminators, tail call terminators instantiate the binder of the callee signature with region variables and equate the arg operand types with that signature's args to ensure that the call is valid.

However, unlike normal call terminators, we were forgetting to also relate the return type of the call terminator to anything. In the case of tail call terminators, the correct thing is to relate it to the return type of the caller function (or in other words, the return local `_0`).

This meant that if the caller's return type had some lifetime constraint, then that constraint wouldn't flow through the signature and affect the args.

This is what's happening in the example test I committed:

```rust
fn link(x: &str) -> &'static str {
    become passthrough(x);
}

fn passthrough<T>(t: T) -> T { t }

fn main() {
    let x = String::from("hello, world");
    let s = link(&x);
    drop(x);
    println!("{s}");
}
```

Specifically, the type `x` is `'?0 str`, where `'?0` is some *universal* arg. The type of `passthrough` is `fn(&'?1 str) -> &'?1 str`. Equating the args sets `'?0 = '?1`. However, we need to also equate the return type `&'?1 str` to `&'static str` so that we eventually require that `'?0 = 'static`, which is a borrowck error!

-----

Look at the first commit for the functional change, and the second commit is just a refactor because we don't need to pass `Option<BasicBlock>` to `check_call_dest`, but just whether or not the terminator is expected to be diverging (i.e. if the return type is `!`).

Fixes rust-lang/rust#144916
2025-08-06 21:29:29 +02:00
..
rustc rename stable_mir to rustc_public, and rustc_smir to rustc_public_bridge 2025-07-14 09:25:54 +00:00
rustc_abi Reuse sign_extend helper 2025-07-29 14:17:48 +00:00
rustc_arena Introduce Arena::try_alloc_from_iter. 2025-04-19 01:13:18 +00:00
rustc_ast Deduplicate IntTy/UintTy/FloatTy. 2025-07-31 19:56:11 +10:00
rustc_ast_ir Tidy up Cargo.toml files. 2025-07-31 19:58:04 +10:00
rustc_ast_lowering Port #[coroutine] to the new attribute system 2025-08-04 18:37:40 +02:00
rustc_ast_passes fix: Error on illegal [const]s inside blocks within legal positions 2025-08-04 01:48:28 +09:00
rustc_ast_pretty use let chains in ast, borrowck, codegen, const_eval 2025-07-28 06:08:48 +05:00
rustc_attr_parsing Rollup merge of #144794 - scrabsha:push-noqrrttovmwy, r=jdonszelmann 2025-08-06 21:29:27 +02:00
rustc_baked_icu_data Add unreachable_pub to RUSTC_LINT_FLAGS for compiler/ crates. 2025-03-11 13:14:21 +11:00
rustc_borrowck Rollup merge of #144917 - compiler-errors:tail-call-linked-lifetimes, r=lcnr 2025-08-06 21:29:29 +02:00
rustc_builtin_macros remove rustc_attr_data_structures 2025-07-31 14:19:27 +02:00
rustc_codegen_cranelift Update codegen_{cranelift,gcc} and opt-dist to use build.compiletest-allow-stage0 2025-07-30 19:55:07 +08:00
rustc_codegen_gcc Preserve the .debug_gdb_scripts section 2025-08-05 10:55:07 +02:00
rustc_codegen_llvm Embed GDB pretty printers in rlibs and dylibs 2025-08-06 13:24:43 +02:00
rustc_codegen_ssa Embed GDB pretty printers in rlibs and dylibs 2025-08-06 13:24:43 +02:00
rustc_const_eval Rollup merge of #144890 - WaffleLapkin:project_fields, r=lcnr 2025-08-05 03:51:40 +02:00
rustc_data_structures Allow pretty printing paths with -Zself-profile-events=args 2025-07-25 22:24:21 +02:00
rustc_driver Remove recursion_limit increases. 2025-04-02 16:25:27 +11:00
rustc_driver_impl Tidy up Cargo.toml files. 2025-07-31 19:58:04 +10:00
rustc_error_codes Update E0562 to account for the new impl trait positions 2025-08-02 11:29:04 +02:00
rustc_error_messages Remove unused feature gates 2025-06-28 23:36:46 +00:00
rustc_errors Rollup merge of #144691 - xizheyin:suggest-confuse, r=estebank 2025-08-01 00:38:20 -04:00
rustc_expand Auto merge of #129183 - estebank:cfg-visitor, r=davidtwco 2025-08-02 05:09:31 +00:00
rustc_feature Remove the omit_gdb_pretty_printer_section attribute 2025-08-01 20:04:59 +00:00
rustc_fluent_macro Remove all unused feature gates from the compiler 2025-06-08 14:50:42 +00:00
rustc_fs_util Retry if creating temp fails with access denied 2025-04-25 11:28:36 +00:00
rustc_graphviz Remove #![warn(unreachable_pub)] from all compiler/ crates. 2025-03-11 13:14:21 +11:00
rustc_hashes Revert "Use workspace lints for crates in compiler/ #138084" 2025-03-10 18:12:47 +08:00
rustc_hir Port #[coroutine] to the new attribute system 2025-08-04 18:37:40 +02:00
rustc_hir_analysis Rollup merge of #144694 - compiler-errors:with-self-ty, r=SparrowLii 2025-08-04 14:58:09 +10:00
rustc_hir_pretty remove rustc_attr_data_structures 2025-07-31 14:19:27 +02:00
rustc_hir_typeck Rollup merge of #144694 - compiler-errors:with-self-ty, r=SparrowLii 2025-08-04 14:58:09 +10:00
rustc_incremental Auto merge of #139758 - Zoxc:thread-local-graph, r=oli-obk 2025-05-07 12:39:54 +00:00
rustc_index Tidy up Cargo.toml files. 2025-07-31 19:58:04 +10:00
rustc_index_macros Tidy up Cargo.toml files. 2025-07-31 19:58:04 +10:00
rustc_infer Auto merge of #144677 - nnethercote:bound-const-handling, r=lcnr 2025-08-03 05:26:43 +00:00
rustc_interface coverage: Remove -Zcoverage-options=no-mir-spans 2025-08-04 13:48:40 +10:00
rustc_lexer test(lexer): Add frontmatter unit test 2025-07-10 10:25:29 -05:00
rustc_lint Rollup merge of #144776 - nnethercote:Printer-cleanups, r=cjgillot 2025-08-05 03:51:34 +02:00
rustc_lint_defs add unsupported_calling_conventions to lint list 2025-08-01 09:47:47 +02:00
rustc_llvm Rollup merge of #144712 - nnethercote:dedup-num-types, r=fmease 2025-07-31 17:19:39 +02:00
rustc_log Add documentation for init_logger_with_additional_layer 2025-06-12 12:11:15 +02:00
rustc_macros remove rustc_attr_data_structures 2025-07-31 14:19:27 +02:00
rustc_metadata remove rustc_attr_data_structures 2025-07-31 14:19:27 +02:00
rustc_middle Auto merge of #144863 - cjgillot:live-or-dead, r=Urgau 2025-08-05 18:10:21 +00:00
rustc_mir_build Rollup merge of #144835 - compiler-errors:tail-call-sig-binder, r=WaffleLapkin 2025-08-06 21:29:27 +02:00
rustc_mir_dataflow Rollup merge of #144478 - joshtriplett:doc-code-formatting-prep, r=Amanieu 2025-08-02 11:24:24 +02:00
rustc_mir_transform coverage: Push async special case down into extract_refined_covspans 2025-08-04 13:48:41 +10:00
rustc_monomorphize remove rustc_attr_data_structures 2025-07-31 14:19:27 +02:00
rustc_next_trait_solver Rollup merge of #144694 - compiler-errors:with-self-ty, r=SparrowLii 2025-08-04 14:58:09 +10:00
rustc_parse Rollup merge of #144195 - Kivooeo:bad-attr, r=fmease,compiler-errors 2025-08-06 21:29:26 +02:00
rustc_parse_format update to literal-escaper-0.0.5 2025-07-08 10:16:44 +00:00
rustc_passes Rollup merge of #144794 - scrabsha:push-noqrrttovmwy, r=jdonszelmann 2025-08-06 21:29:27 +02:00
rustc_pattern_analysis Tidy up Cargo.toml files. 2025-07-31 19:58:04 +10:00
rustc_privacy Auto merge of #144554 - cjgillot:no-hir-eff-vis, r=petrochenkov 2025-08-02 09:23:36 +00:00
rustc_proc_macro Tidy up Cargo.toml files. 2025-07-31 19:58:04 +10:00
rustc_public Tidy up Cargo.toml files. 2025-07-31 19:58:04 +10:00
rustc_public_bridge Remove useless lifetime parameter. 2025-07-23 23:54:37 +00:00
rustc_query_impl Remove unused allow attrs 2025-07-07 12:58:16 +00:00
rustc_query_system remove rustc_attr_data_structures 2025-07-31 14:19:27 +02:00
rustc_resolve Rollup merge of #144746 - petrochenkov:extpreltidy, r=b-naber 2025-08-04 11:24:39 +10:00
rustc_sanitizers Tidy up Cargo.toml files. 2025-07-31 19:58:04 +10:00
rustc_serialize use div_ceil instead of manual logic 2025-07-05 10:55:42 +02:00
rustc_session coverage: Simplify access to debug/testing -Zcoverage-options flags 2025-08-04 13:48:41 +10:00
rustc_span Rollup merge of #144478 - joshtriplett:doc-code-formatting-prep, r=Amanieu 2025-08-02 11:24:24 +02:00
rustc_symbol_mangling Remove unused arg from path_append_impl. 2025-08-03 19:58:59 +10:00
rustc_target Rollup merge of #144410 - Gelbpunkt:musl-tier3-dynamic, r=jieyouxu 2025-08-01 09:59:03 +02:00
rustc_thread_pool Drop rust-version from rustc_thread_pool 2025-08-04 15:03:49 -07:00
rustc_trait_selection Rollup merge of #144776 - nnethercote:Printer-cleanups, r=cjgillot 2025-08-05 03:51:34 +02:00
rustc_traits Auto merge of #144446 - nnethercote:opt-region-constraints, r=lcnr 2025-08-01 04:06:21 +00:00
rustc_transmute Tidy up Cargo.toml files. 2025-07-31 19:58:04 +10:00
rustc_ty_utils Extract borrowck coroutine drop-liveness hack 2025-07-31 17:38:28 +00:00
rustc_type_ir Rollup merge of #144694 - compiler-errors:with-self-ty, r=SparrowLii 2025-08-04 14:58:09 +10:00
rustc_type_ir_macros Split TypeFolder and FallibleTypeFolder 2025-04-15 18:30:35 +00:00