rust/tests
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
..
assembly Auto merge of #112922 - g0djan:godjan/wasi-threads, r=wesleywiser 2023-08-02 01:01:48 +00:00
auxiliary
codegen Rollup merge of #115591 - djkoloski:issue_115385, r=cuviper 2023-09-11 21:16:21 +02:00
codegen-units
coverage-map Fix up run-coverage and coverage-map/status-quo tests 2023-09-08 12:46:23 +01:00
debuginfo Auto merge of #115128 - davidtwco:re-enable-debuginfo-test, r=wesleywiser 2023-09-12 19:39:27 +00:00
incremental Forbid old-style simd_shuffleN intrinsics 2023-08-03 09:29:00 +00:00
mir-opt fix clippy (and MIR printing) handling of ConstValue::Indirect slices 2023-09-14 11:56:55 +02:00
pretty Rework no_coverage to coverage(off) 2023-09-08 12:46:06 +01:00
run-coverage Fix up run-coverage and coverage-map/status-quo tests 2023-09-08 12:46:23 +01:00
run-coverage-rustdoc Tidy up some awkwardly-placed comments in tests 2023-08-26 14:35:34 +10:00
run-make rustdoc: merge theme css into rustdoc.css 2023-09-15 07:40:17 -07:00
run-make-fulldeps Remove EarlyErrorHandler argument from after_analysis callback 2023-09-10 09:44:03 +00:00
run-pass-valgrind
rustdoc Add test for the presence of "Aliased type" title in the sidebar 2023-09-11 14:17:39 +02:00
rustdoc-gui rusdoc: add gui test for custom CSS themes 2023-09-14 13:24:23 -07:00
rustdoc-js Correctly handle paths from foreign items 2023-09-02 23:04:37 +02:00
rustdoc-js-std Add tests for type-based search 2023-09-01 15:16:11 +02:00
rustdoc-json Fix rustdoc-json tests 2023-08-23 11:52:49 -07:00
rustdoc-ui rustdoc: use unicode-aware checks for redundant explicit link fastpath 2023-08-21 14:25:26 -07:00
ui Auto merge of #115315 - RalfJung:field-capture-packed-alignment, r=oli-obk 2023-09-16 05:29:23 +00:00
ui-fulldeps Auto merge of #115677 - matthewjasper:let-expr-recovery, r=b-naber 2023-09-14 19:56:55 +00:00
COMPILER_TESTS.md