rust/compiler
Matthias Krüger ade745e214
Rollup merge of #140593 - m-ou-se:some-temp, r=Nadrieril
Temporary lifetime extension through tuple struct and tuple variant constructors

This makes temporary lifetime extension work for tuple struct and tuple variant constructors, such as `Some()`.

Before:
```rust
let a = &temp(); // Extended
let a = Some(&temp()); // Not extended :(
let a = Some { 0: &temp() }; // Extended
```

After:
```rust
let a = &temp(); // Extended
let a = Some(&temp()); // Extended
let a = Some { 0: &temp() }; // Extended
```

So, with this change, this works:

```rust
let a = Some(&String::from("hello")); // New: String lifetime now extended!

println!("{a:?}");
```

Until now, we did not extend through tuple struct/variant constructors (like `Some`), because they are function calls syntactically, and we do not want to extend the String lifetime in:

```rust
let a = some_function(&String::from("hello")); // String not extended!
```

However, it turns out to be very easy to distinguish between regular functions and constructors at the point where we do lifetime extension.

In practice, constructors nearly always use UpperCamelCase while regular functions use lower_snake_case, so it should still be easy to for a human programmer at the call site to see whether something qualifies for lifetime extension or not.

This needs a lang fcp.

---

More examples of what will work after this change:

```rust
let x = Person {
    name: "Ferris",
    job: Some(&Job { // `Job` now extended!
        title: "Chief Rustacean",
        organisation: "Acme Ltd.",
    }),
};

dbg!(x);
```

```rust
let file = if use_stdout {
    None
} else {
    Some(&File::create("asdf")?) // `File` now extended!
};

set_logger(file);
```

```rust
use std::path::Component;

let c = Component::Normal(&OsString::from(format!("test-{num}"))); // OsString now extended!

assert_eq!(path.components.first().unwrap(), c);
```
2025-06-14 11:27:09 +02:00
..
rustc Revert "Use workspace lints for crates in compiler/ #138084" 2025-03-10 18:12:47 +08:00
rustc_abi add extern "custom" functions 2025-06-12 20:27:10 +02:00
rustc_arena Introduce Arena::try_alloc_from_iter. 2025-04-19 01:13:18 +00:00
rustc_ast Auto merge of #142443 - matthiaskrgr:rollup-l1l6d0v, r=matthiaskrgr 2025-06-13 17:44:15 +00:00
rustc_ast_ir Use -Wunused_crate_dependencies for compiler crates. 2025-03-20 08:59:43 +11:00
rustc_ast_lowering Rollup merge of #142449 - oli-obk:missing-mgca-args, r=BoxyUwU 2025-06-13 20:59:19 -07:00
rustc_ast_passes Auto merge of #142443 - matthiaskrgr:rollup-l1l6d0v, r=matthiaskrgr 2025-06-13 17:44:15 +00:00
rustc_ast_pretty Rollup merge of #142069 - nnethercote:Zmacro-stats, r=petrochenkov 2025-06-13 05:16:56 +02:00
rustc_attr_data_structures Rollup merge of #142158 - xizheyin:141617, r=jdonszelmann 2025-06-13 05:16:56 +02:00
rustc_attr_parsing Rollup merge of #142158 - xizheyin:141617, r=jdonszelmann 2025-06-13 05:16:56 +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 #141069 - chenyukang:yukang-fix-137486-suggest-mut, r=davidtwco 2025-06-12 22:09:41 +02:00
rustc_builtin_macros introduce new lint infra 2025-06-12 09:56:47 +02:00
rustc_codegen_cranelift Auto merge of #142443 - matthiaskrgr:rollup-l1l6d0v, r=matthiaskrgr 2025-06-13 17:44:15 +00:00
rustc_codegen_gcc Auto merge of #142443 - matthiaskrgr:rollup-l1l6d0v, r=matthiaskrgr 2025-06-13 17:44:15 +00:00
rustc_codegen_llvm Rollup merge of #140770 - folkertdev:custom-abi, r=tgross35 2025-06-13 05:19:14 +02:00
rustc_codegen_ssa Auto merge of #142443 - matthiaskrgr:rollup-l1l6d0v, r=matthiaskrgr 2025-06-13 17:44:15 +00:00
rustc_const_eval Rollup merge of #142405 - oli-obk:type-once, r=RalfJung 2025-06-13 20:59:17 -07:00
rustc_data_structures Overhaul the thousands module. 2025-06-12 15:26:06 +10:00
rustc_driver Remove recursion_limit increases. 2025-04-02 16:25:27 +11:00
rustc_driver_impl Add documentation for init_logger_with_additional_layer 2025-06-12 12:11:15 +02:00
rustc_error_codes intrinsics: use const generic to set atomic ordering 2025-06-07 21:45:58 +02:00
rustc_error_messages Fix review comments 2025-06-06 14:20:48 +00:00
rustc_errors introduce new lint infra 2025-06-12 09:56:47 +02:00
rustc_expand Auto merge of #142443 - matthiaskrgr:rollup-l1l6d0v, r=matthiaskrgr 2025-06-13 17:44:15 +00:00
rustc_feature Auto merge of #142443 - matthiaskrgr:rollup-l1l6d0v, r=matthiaskrgr 2025-06-13 17:44:15 +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 introduce new lint infra 2025-06-12 09:56:47 +02:00
rustc_hir_analysis Rollup merge of #140593 - m-ou-se:some-temp, r=Nadrieril 2025-06-14 11:27:09 +02:00
rustc_hir_pretty Reorder hir fn stuff. 2025-05-30 02:28:35 +10:00
rustc_hir_typeck Rollup merge of #140770 - folkertdev:custom-abi, r=tgross35 2025-06-13 05:19:14 +02:00
rustc_incremental Auto merge of #139758 - Zoxc:thread-local-graph, r=oli-obk 2025-05-07 12:39:54 +00:00
rustc_index index: add method for checking range on DenseBitSet 2025-06-04 00:47:12 +02:00
rustc_index_macros In rustc_mir_tranform, iterate over index newtypes instead of ints 2025-04-12 11:53:07 +00:00
rustc_infer Auto merge of #141763 - lcnr:fixme-gamer, r=BoxyUwU 2025-06-11 11:47:05 +00:00
rustc_interface Introduce -Zmacro-stats. 2025-06-12 21:17:17 +10:00
rustc_lexer rustc_lexer: typo fix + small cleanups 2025-06-06 13:08:16 +00:00
rustc_lint Rollup merge of #142441 - compiler-errors:lazier-binder-value-folding, r=lcnr 2025-06-13 20:59:19 -07:00
rustc_lint_defs Auto merge of #142443 - matthiaskrgr:rollup-l1l6d0v, r=matthiaskrgr 2025-06-13 17:44:15 +00:00
rustc_llvm rustc_llvm: add Windows system libs only when cross-compiling from Windows 2025-05-31 15:47:14 +02:00
rustc_log Add documentation for init_logger_with_additional_layer 2025-06-12 12:11:15 +02:00
rustc_macros Remove all unused feature gates from the compiler 2025-06-08 14:50:42 +00:00
rustc_metadata Rollup merge of #142069 - nnethercote:Zmacro-stats, r=petrochenkov 2025-06-13 05:16:56 +02:00
rustc_middle Rollup merge of #142441 - compiler-errors:lazier-binder-value-folding, r=lcnr 2025-06-13 20:59:19 -07:00
rustc_mir_build Rollup merge of #142047 - cuviper:s390x-stack, r=oli-obk 2025-06-06 00:58:45 +02:00
rustc_mir_dataflow update cfg(bootstrap) 2025-05-12 15:33:37 +02:00
rustc_mir_transform intrinsics: rename min_align_of to align_of 2025-06-12 17:50:25 +02:00
rustc_monomorphize Rollup merge of #141558 - Diggsey:db-limit-cgu-name-length, r=matthewjasper 2025-06-07 07:05:45 +02:00
rustc_next_trait_solver TypeVisiting binders no longer requires TypeFolding its interior 2025-06-13 17:54:45 +00:00
rustc_parse Rework how the disallowed qualifier lints are generated 2025-06-13 18:13:34 +02:00
rustc_parse_format Add ParseMode::Diagnostic unit tests 2025-06-09 16:28:58 +02:00
rustc_passes Rollup merge of #142158 - xizheyin:141617, r=jdonszelmann 2025-06-13 05:16:56 +02:00
rustc_pattern_analysis Use builin_index instead of hand-rolling it 2025-05-28 10:03:01 +00:00
rustc_privacy Reorder fields in hir::ItemKind variants. 2025-05-30 02:23:20 +10:00
rustc_proc_macro Do not get proc_macro from the sysroot in rustc 2025-05-27 15:49:28 +00:00
rustc_query_impl Auto merge of #140145 - Zoxc:job-server-proxy, r=SparrowLii 2025-05-01 04:11:52 +00:00
rustc_query_system Remove all unused feature gates from the compiler 2025-06-08 14:50:42 +00:00
rustc_resolve Auto merge of #134841 - estebank:serde-attr-4, r=wesleywiser 2025-06-13 22:59:24 +00:00
rustc_sanitizers Replace some Option<Span> with Span and use DUMMY_SP instead of None 2025-06-05 14:14:59 +00:00
rustc_serialize Zero the buffer passed from write_with 2025-04-25 07:14:27 +02:00
rustc_session Auto merge of #142443 - matthiaskrgr:rollup-l1l6d0v, r=matthiaskrgr 2025-06-13 17:44:15 +00:00
rustc_smir Rollup merge of #140770 - folkertdev:custom-abi, r=tgross35 2025-06-13 05:19:14 +02:00
rustc_span Auto merge of #142443 - matthiaskrgr:rollup-l1l6d0v, r=matthiaskrgr 2025-06-13 17:44:15 +00:00
rustc_symbol_mangling Rename unpack to kind 2025-05-27 11:14:45 +00:00
rustc_target Rollup merge of #142248 - heiher:loong32-asm-types, r=Amanieu 2025-06-13 05:19:15 +02:00
rustc_trait_selection Rollup merge of #142441 - compiler-errors:lazier-binder-value-folding, r=lcnr 2025-06-13 20:59:19 -07:00
rustc_traits FIXME(-Znext-solver) triage 2025-06-03 14:23:56 +02:00
rustc_transmute transmutability: shift abstraction boundary 2025-06-09 14:08:12 +00:00
rustc_ty_utils TypeVisiting binders no longer requires TypeFolding its interior 2025-06-13 17:54:45 +00:00
rustc_type_ir Rollup merge of #142460 - lcnr:search_graph-3, r=BoxyUwU 2025-06-13 20:59:21 -07:00
rustc_type_ir_macros Split TypeFolder and FallibleTypeFolder 2025-04-15 18:30:35 +00:00
stable_mir Change rustc_driver dependency on stable_mir crate 2025-04-30 15:39:52 -07:00