]> git.lizzy.rs Git - rust.git/blob - src/test/ui/unsafe/issue-85435-unsafe-op-in-let-under-unsafe-under-closure.rs
Rollup merge of #105955 - Nilstrieb:no-trivial-opt-wrappers-we-have-field-accesses...
[rust.git] / src / test / ui / unsafe / issue-85435-unsafe-op-in-let-under-unsafe-under-closure.rs
1 // check-pass
2 // revisions: mir thir
3 // [thir]compile-flags: -Z thir-unsafeck
4
5 // This is issue #85435. But the real story is reflected in issue #85561, where
6 // a bug in the implementation of feature(capture_disjoint_fields) () was
7 // exposed to non-feature-gated code by a diagnostic changing PR that removed
8 // the gating in one case.
9
10 // This test is double-checking that the case of interest continues to work as
11 // expected in the *absence* of that feature gate. At the time of this writing,
12 // enabling the feature gate will cause this test to fail. We obviously cannot
13 // stabilize that feature until it can correctly handle this test.
14
15 fn main() {
16     let val: u8 = 5;
17     let u8_ptr: *const u8 = &val;
18     let _closure = || {
19         unsafe {
20             let tmp = *u8_ptr;
21             tmp
22
23             // Just dereferencing and returning directly compiles fine:
24             // *u8_ptr
25         }
26     };
27 }