rust/compiler
bors 790309b102 Auto merge of #115315 - RalfJung:field-capture-packed-alignment, r=oli-obk
closure field capturing: don't depend on alignment of packed fields

This fixes the closure field capture part of https://github.com/rust-lang/rust/issues/115305: field capturing always stops at projections into packed structs, no matter the alignment of the field. This means changing a private field type from `u8` to `u64` can never change how closures capture fields, which is probably what we want.

Here's an example where, before this PR, changing the type of a private field in a repr(Rust) struct can change the output of a program:

```rust
#![allow(dead_code)]

mod m {
    // before patch
    #[derive(Default)]
    pub struct S1(u8);
    // after patch
    #[derive(Default)]
    pub struct S2(u64);
}

struct NoisyDrop;
impl Drop for NoisyDrop {
    fn drop(&mut self) {
        eprintln!("dropped!");
    }
}

#[repr(packed)]
struct MyType {
    field: m::S1, // output changes when this becomes S2
    other_field: NoisyDrop,
    third_field: Vec<()>,
}

fn test(r: MyType) {
    let c = || {
        let _val = std::ptr::addr_of!(r.field);
        let _val = r.third_field;
    };
    drop(c);
    eprintln!("before dropping");
}

fn main() {
    test(MyType {
        field: Default::default(),
        other_field: NoisyDrop,
        third_field: Vec::new(),
    });
}
```

Of course this is a breaking change for the same reason that doing field capturing in the first place was a breaking change. Packed fields are relatively rare and depending on drop order is relatively rare, so I don't expect this to have much impact, but it's hard to be sure and even a crater run will only tell us so much.

Also see the [nomination comment](https://github.com/rust-lang/rust/pull/115315#issuecomment-1702807825).

Cc `@rust-lang/wg-rfc-2229` `@ehuss`
2023-09-16 05:29:23 +00:00
..
rustc inline format!() args up to and including rustc_middle 2023-07-30 13:18:33 +02:00
rustc_abi turns out Layout has some more things to worry about -- move ABI comparison into helper function 2023-09-08 09:14:07 +02:00
rustc_arena Bump cfg(bootstrap) 2023-08-23 20:05:14 -04:00
rustc_ast Move let expression checking to parsing 2023-09-11 15:51:18 +00:00
rustc_ast_lowering Auto merge of #115677 - matthewjasper:let-expr-recovery, r=b-naber 2023-09-14 19:56:55 +00:00
rustc_ast_passes Move let expression checking to parsing 2023-09-11 15:51:18 +00:00
rustc_ast_pretty Move let expression checking to parsing 2023-09-11 15:51:18 +00:00
rustc_attr Auto merge of #114201 - Centri3:explicit-repr-rust, r=WaffleLapkin 2023-08-25 00:02:54 +00:00
rustc_baked_icu_data
rustc_borrowck cleanup on messages 2023-09-12 07:27:17 +08:00
rustc_builtin_macros Auto merge of #115677 - matthewjasper:let-expr-recovery, r=b-naber 2023-09-14 19:56:55 +00:00
rustc_codegen_cranelift make it more clear which functions create fresh AllocId 2023-09-14 07:27:31 +02:00
rustc_codegen_gcc treat host effect params as erased generics in codegen 2023-09-14 07:34:35 +00:00
rustc_codegen_llvm Auto merge of #115817 - fee1-dead-contrib:fix-codegen, r=oli-obk 2023-09-14 13:42:30 +00:00
rustc_codegen_ssa Auto merge of #115817 - fee1-dead-contrib:fix-codegen, r=oli-obk 2023-09-14 13:42:30 +00:00
rustc_const_eval Auto merge of #115804 - RalfJung:valtree-to-const-val, r=oli-obk 2023-09-14 15:34:31 +00:00
rustc_data_structures Bring back verbose_generic_activity_with_arg 2023-09-13 13:41:19 +02:00
rustc_driver Update rustix 2023-07-03 07:20:51 +00:00
rustc_driver_impl Auto merge of #115735 - bjorn3:better_list_crate_metadata, r=wesleywiser 2023-09-13 10:23:57 +00:00
rustc_error_codes Auto merge of #114656 - bossmc:rework-no-coverage-attr, r=oli-obk 2023-09-14 01:05:18 +00:00
rustc_error_messages Bump cfg(bootstrap) 2023-08-23 20:05:14 -04:00
rustc_errors Auto merge of #115418 - Zoxc:freeze-source, r=oli-obk 2023-09-08 17:20:23 +00:00
rustc_expand Enable incremental-relative-spans by default. 2023-09-07 20:21:13 +00:00
rustc_feature Auto merge of #114494 - est31:extend_useless_ptr_null_checks, r=jackh726 2023-09-16 03:40:20 +00:00
rustc_fluent_macro
rustc_fs_util
rustc_graphviz
rustc_hir Move let expression checking to parsing 2023-09-11 15:51:18 +00:00
rustc_hir_analysis Auto merge of #115853 - obeis:hir-analysis-migrate-diagnostics-6, r=compiler-errors 2023-09-15 11:55:27 +00:00
rustc_hir_pretty Auto merge of #114545 - fee1-dead-contrib:lower-impl-effect, r=oli-obk 2023-08-08 19:23:41 +00:00
rustc_hir_typeck Auto merge of #115315 - RalfJung:field-capture-packed-alignment, r=oli-obk 2023-09-16 05:29:23 +00:00
rustc_incremental Avoid a source_span query when encoding Spans into query results 2023-09-08 02:08:52 +02:00
rustc_index Auto merge of #115094 - Mark-Simulacrum:bootstrap-update, r=ozkanonur 2023-08-24 11:10:52 +00:00
rustc_infer Canonicalize effect vars in new solver 2023-09-15 05:11:16 +00:00
rustc_interface Auto merge of #115735 - bjorn3:better_list_crate_metadata, r=wesleywiser 2023-09-13 10:23:57 +00:00
rustc_lexer Update lexer emoji diagnostics to Unicode 15.0 2023-07-29 08:47:21 +08:00
rustc_lint Auto merge of #114494 - est31:extend_useless_ptr_null_checks, r=jackh726 2023-09-16 03:40:20 +00:00
rustc_lint_defs Auto merge of #112038 - Nemo157:edition-2024-unsafe_op_in_unsafe_fn, r=RalfJung 2023-09-14 11:52:08 +00:00
rustc_llvm llvm-wrapper: adapt for LLVM API changes 2023-09-15 14:31:43 +00:00
rustc_log inline format!() args up to and including rustc_middle 2023-07-30 13:18:33 +02:00
rustc_macros Bump cfg(bootstrap) 2023-08-23 20:05:14 -04:00
rustc_metadata Auto merge of #115735 - bjorn3:better_list_crate_metadata, r=wesleywiser 2023-09-13 10:23:57 +00:00
rustc_middle Auto merge of #115848 - matthiaskrgr:rollup-lsul9dz, r=matthiaskrgr 2023-09-14 17:22:20 +00:00
rustc_mir_build make it more clear which functions create fresh AllocId 2023-09-14 07:27:31 +02:00
rustc_mir_dataflow Support non-scalar constants. 2023-09-11 16:29:41 +00:00
rustc_mir_transform Auto merge of #115817 - fee1-dead-contrib:fix-codegen, r=oli-obk 2023-09-14 13:42:30 +00:00
rustc_monomorphize Auto merge of #115804 - RalfJung:valtree-to-const-val, r=oli-obk 2023-09-14 15:34:31 +00:00
rustc_parse Auto merge of #115677 - matthewjasper:let-expr-recovery, r=b-naber 2023-09-14 19:56:55 +00:00
rustc_parse_format Replace data_structures dependency with index in rustc_parse_format 2023-09-05 19:11:50 +02:00
rustc_passes Auto merge of #114494 - est31:extend_useless_ptr_null_checks, r=jackh726 2023-09-16 03:40:20 +00:00
rustc_plugin_impl
rustc_privacy Rollup merge of #115727 - fee1-dead-contrib:effect-fallback, r=oli-obk 2023-09-11 17:03:31 +02:00
rustc_query_impl Remove verbose_generic_activity_with_arg 2023-09-10 17:47:16 +02:00
rustc_query_system Auto merge of #115388 - Zoxc:sharded-lock, r=SparrowLii 2023-09-11 01:43:29 +00:00
rustc_resolve Auto merge of #115677 - matthewjasper:let-expr-recovery, r=b-naber 2023-09-14 19:56:55 +00:00
rustc_serialize Use a specialized varint + bitpacking scheme for DepGraph encoding 2023-09-04 12:16:50 -04:00
rustc_session Auto merge of #115735 - bjorn3:better_list_crate_metadata, r=wesleywiser 2023-09-13 10:23:57 +00:00
rustc_smir Rollup merge of #115772 - ouz-a:smir_span2, r=oli-obk 2023-09-14 19:12:31 +02:00
rustc_span Auto merge of #114494 - est31:extend_useless_ptr_null_checks, r=jackh726 2023-09-16 03:40:20 +00:00
rustc_symbol_mangling Auto merge of #115817 - fee1-dead-contrib:fix-codegen, r=oli-obk 2023-09-14 13:42:30 +00:00
rustc_target add helper method for finding the one non-1-ZST field 2023-09-12 20:52:05 +02:00
rustc_trait_selection Canonicalize effect vars in new solver 2023-09-15 05:11:16 +00:00
rustc_traits remove some unused crate deps 2023-09-01 19:13:09 +03:00
rustc_transmute make the eval() functions on our const types return the resulting value 2023-09-13 07:29:34 +02:00
rustc_ty_utils Auto merge of #115817 - fee1-dead-contrib:fix-codegen, r=oli-obk 2023-09-14 13:42:30 +00:00
rustc_type_ir Explain why TypeFoldable is a sub-trait of TypeVisitable. 2023-09-13 16:50:35 +10:00