rust/compiler
bors df8b2e497d Auto merge of #147056 - dianne:fcw-super-let-init-borrow-shortening, r=jackh726
[beta-1.91] Warn on future errors from temporary lifetimes shortening in Rust 1.92

Pursuant to [discussion on Zulip](https://rust-lang.zulipchat.com/#narrow/channel/474880-t-compiler.2Fbackports/topic/.23145838.3A.20beta-nominated/near/540530631), this implements a future-compatibility warning lint `macro_extended_temporary_scopes` for errors in Rust 1.92 caused by rust-lang/rust#145838:

```
warning: temporary lifetime shortening in Rust 1.92
  --> $DIR/macro-extended-temporary-scopes.rs:54:14
   |
LL |             &struct_temp().field
   |              ^^^^^^^^^^^^^ this expression creates a temporary value...
...
LL |         } else {
   |         - ...which will be dropped at the end of this block in Rust 1.92
   |
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
   = note: for more information, see <https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#macro-extended-temporary-scopes>
   = note: consider using a `let` binding to create a longer lived value
```

Implementation-wise, this reuses the existing temporary scoping FCW machinery introduced for the `tail_expr_drop_order` edition lint: this adds `BackwardIncompatibleDropHint` statements to the MIR at the end of the shortened scopes for affected temporaries; these are then checked in borrowck to warn if the temporary is used after the future drop hint. There are trade-offs here: on one hand, I believe this gives some assurance over ad-hoc pattern-recognition that there are no false positives[^1]. On the other hand, this fails to lint on future dangling raw pointers and it complicates the potential addition of explanatory diagnostics or suggestions[^2]. I'm hopeful that the limitation around dangling pointers won't be relevant in real code, though; the only real instance we've seen of breakage so far is future errors in formatting macro invocations, which this should be able to catch.

Release logistics notes:
- This PR targets the beta branch directly, since the breakage it's a FCW for is landing in the next Rust version.
- rust-lang/rust#146098 undoes the breakage this is a FCW for. If that behavior is merged and stabilizes in Rust 1.92, this PR should be reverted (or shouldn't be merged) in order to avoid spurious warnings.

cc `@traviscross`

`@rustbot` label +T-lang

[^1]: In particular, more syntactic approaches are complicated by having to avoid warning on promoted constants; they'd either be full of holes, they'd need a lot of extra logic, or they'd need to hack more MIR-to-HIR mapping into `PromoteTemps`.
[^2]: It's definitely possible to add more context and a suggestion, but the ways I've thought of to do so are either too hacky or too complex to feel appropriate for a last-minute direct-to-beta lint.
2025-10-15 01:35:47 +00:00
..
rustc Revert "compiler: Add Windows resources to rustc-main and rustc_driver" 2025-09-17 16:33:41 -04:00
rustc_abi Rollup merge of #144066 - RalfJung:extern-c-variadics, r=workingjubilee 2025-09-02 17:08:52 +02:00
rustc_arena Introduce Arena::try_alloc_from_iter. 2025-04-19 01:13:18 +00:00
rustc_ast c-variadic: reject functions with unsupported extern ABI 2025-09-09 21:38:38 +02:00
rustc_ast_ir turn pointer width into an integer in target.json 2025-08-27 23:44:49 +02:00
rustc_ast_lowering Introduce hir::ImplItemImplKind 2025-09-12 15:14:15 -05:00
rustc_ast_passes c-variadic: reject functions with unsupported extern ABI 2025-09-09 21:38:38 +02:00
rustc_ast_pretty Revert introduction of [workspace.dependencies]. 2025-09-02 19:12:54 +10:00
rustc_attr_parsing Fix target list of link_section 2025-10-10 09:23:48 -07:00
rustc_baked_icu_data Use default locale fallback data 2025-08-28 09:48:54 +00:00
rustc_borrowck warn on future errors from temporary lifetimes shortening in Rust 1.92 2025-10-13 22:45:09 -07:00
rustc_builtin_macros Use raw fmt str in format macro 2025-09-12 00:01:38 +02:00
rustc_codegen_cranelift Auto merge of #146233 - jieyouxu:run-make-fission, r=Kobzol 2025-09-06 18:37:35 +00:00
rustc_codegen_gcc Rollup merge of #146178 - folkertdev:static-align, r=jdonszelmann,ralfjung,traviscross 2025-09-10 14:17:38 +02:00
rustc_codegen_llvm Revert "Auto merge of #144086 - clubby789:alloc-zeroed, r=nikic" 2025-09-25 16:36:51 +02:00
rustc_codegen_ssa Revert "compiler: Add Windows resources to rustc-main and rustc_driver" 2025-09-17 16:33:41 -04:00
rustc_const_eval Rollup merge of #146178 - folkertdev:static-align, r=jdonszelmann,ralfjung,traviscross 2025-09-10 14:17:38 +02:00
rustc_data_structures Revert introduction of [workspace.dependencies]. 2025-09-02 19:12:54 +10:00
rustc_driver Revert "compiler: Add Windows resources to rustc-main and rustc_driver" 2025-09-17 16:33:41 -04:00
rustc_driver_impl Add --print target-spec-json-schema 2025-09-12 20:53:28 +02:00
rustc_error_codes Changes to the uitests 2025-08-27 20:25:18 +02:00
rustc_error_messages Revert introduction of [workspace.dependencies]. 2025-09-02 19:12:54 +10:00
rustc_errors fix: Filter suggestion parts that match existing code 2025-09-04 17:42:13 -06:00
rustc_expand Rollup merge of #146308 - cyrgani:concat-integer-literals, r=jackh726 2025-09-12 20:02:11 +10:00
rustc_feature Revert "Auto merge of #144086 - clubby789:alloc-zeroed, r=nikic" 2025-09-25 16:36:51 +02:00
rustc_fluent_macro Revert introduction of [workspace.dependencies]. 2025-09-02 19:12:54 +10:00
rustc_fs_util Revert introduction of [workspace.dependencies]. 2025-09-02 19:12:54 +10:00
rustc_graphviz
rustc_hashes
rustc_hir Auto merge of #145186 - camsteffen:assoc-impl-kind, r=petrochenkov 2025-09-13 13:59:48 +00:00
rustc_hir_analysis warn on shortening super let binding lifetimes 2025-10-13 22:45:25 -07:00
rustc_hir_id rustc_hir_id: Add a comment explaining why the crate exists 2025-08-20 15:04:00 -07:00
rustc_hir_pretty Rollup merge of #146102 - fmease:rm-dead-eff-code-iii, r=fee1-dead 2025-09-02 17:08:58 +02:00
rustc_hir_typeck warn on shortening super let binding lifetimes 2025-10-13 22:45:25 -07:00
rustc_incremental Revert introduction of [workspace.dependencies]. 2025-09-02 19:12:54 +10:00
rustc_index Rollup merge of #144765 - Qelxiros:range-inclusive-last, r=jhpratt 2025-09-10 14:17:37 +02:00
rustc_index_macros Revert introduction of [workspace.dependencies]. 2025-09-02 19:12:54 +10:00
rustc_infer erase_regions to erase_and_anonymize_regions 2025-09-09 14:49:16 +02:00
rustc_interface Rollup merge of #146340 - fmease:frontmatter-containment, r=fee1-dead,Urgau 2025-09-10 20:29:09 +02:00
rustc_lexer Rollup merge of #146106 - epage:whitespace, r=fee1-dead 2025-09-03 23:08:10 +10:00
rustc_lint Split AssocContainer::{InherentImpl,TraitImpl} 2025-09-12 15:14:15 -05:00
rustc_lint_defs warn on future errors from temporary lifetimes shortening in Rust 1.92 2025-10-13 22:45:09 -07:00
rustc_llvm Revert "compiler: Add Windows resources to rustc-main and rustc_driver" 2025-09-17 16:33:41 -04:00
rustc_log Update tracing, again 2025-09-08 09:23:37 -07:00
rustc_macros Revert introduction of [workspace.dependencies]. 2025-09-02 19:12:54 +10:00
rustc_metadata Don't store defaultness for inherent impl items 2025-09-12 15:14:15 -05:00
rustc_middle warn on shortening super let binding lifetimes 2025-10-13 22:45:25 -07:00
rustc_mir_build warn on shortening super let binding lifetimes 2025-10-13 22:45:25 -07:00
rustc_mir_dataflow erase_regions to erase_and_anonymize_regions 2025-09-09 14:49:16 +02:00
rustc_mir_transform warn on future errors from temporary lifetimes shortening in Rust 1.92 2025-10-13 22:45:09 -07:00
rustc_monomorphize Auto merge of #145717 - BoxyUwU:erase_regions_rename, r=lcnr 2025-09-09 15:04:44 +00:00
rustc_next_trait_solver incompletely prefer opaque type bounds when self type bottoms out in infer 2025-09-11 12:13:03 +02:00
rustc_parse Rollup merge of #146422 - fmease:less-greedy-maybe-const-bounds, r=estebank 2025-09-11 14:06:32 +10:00
rustc_parse_format Revert introduction of [workspace.dependencies]. 2025-09-02 19:12:54 +10:00
rustc_passes Rollup merge of #146171 - scrabsha:push-wovnxxwltsun, r=WaffleLapkin 2025-09-13 18:55:17 -04:00
rustc_pattern_analysis Revert introduction of [workspace.dependencies]. 2025-09-02 19:12:54 +10:00
rustc_privacy Revert introduction of [workspace.dependencies]. 2025-09-02 19:12:54 +10:00
rustc_proc_macro Revert introduction of [workspace.dependencies]. 2025-09-02 19:12:54 +10:00
rustc_public Split AssocContainer::{InherentImpl,TraitImpl} 2025-09-12 15:14:15 -05:00
rustc_public_bridge Remove useless lifetime parameter. 2025-07-23 23:54:37 +00:00
rustc_query_impl fixup limit handling code 2025-09-08 15:07:12 -07:00
rustc_query_system fixup limit handling code 2025-09-08 15:07:12 -07:00
rustc_resolve Rollup merge of #146254 - yotamofek:pr/itertools-all-equal-value, r=cjgillot 2025-09-07 08:18:59 +02:00
rustc_sanitizers Introduce trait_item_of 2025-09-12 15:10:30 -05:00
rustc_serialize Revert introduction of [workspace.dependencies]. 2025-09-02 19:12:54 +10:00
rustc_session Add --print target-spec-json-schema 2025-09-12 20:53:28 +02:00
rustc_span Make #[link="dl"] a warning rather than an error 2025-10-07 15:41:15 -07:00
rustc_symbol_mangling Add assertion 2025-09-09 14:49:16 +02:00
rustc_target Add --print target-spec-json-schema 2025-09-12 20:53:28 +02:00
rustc_thread_pool Revert introduction of [workspace.dependencies]. 2025-09-02 19:12:54 +10:00
rustc_trait_selection Don't normalize higher-ranked assumptions if they're not used 2025-10-10 09:20:53 -07:00
rustc_traits erase_regions to erase_and_anonymize_regions 2025-09-09 14:49:16 +02:00
rustc_transmute Driveby fixes 2025-09-09 14:49:16 +02:00
rustc_ty_utils Don't store defaultness for inherent impl items 2025-09-12 15:14:15 -05:00
rustc_type_ir incompletely prefer opaque type bounds when self type bottoms out in infer 2025-09-11 12:13:03 +02:00
rustc_type_ir_macros Revert introduction of [workspace.dependencies]. 2025-09-02 19:12:54 +10:00