rust/compiler/rustc_ty_utils/src
bors 7f4b270aa4 Auto merge of #129313 - RalfJung:coroutine-niches, r=compiler-errors
Supress niches in coroutines to avoid aliasing violations

As mentioned [here](https://github.com/rust-lang/rust/issues/63818#issuecomment-2264915918), using niches in fields of coroutines that are referenced by other fields is unsound: the discriminant accesses violate the aliasing requirements of the reference pointing to the relevant field. This issue causes [Miri errors in practice](https://github.com/rust-lang/miri/issues/3780).

The "obvious" fix for this is to suppress niches in coroutines. That's what this PR does. However, we have several tests explicitly ensuring that we *do* use niches in coroutines. So I see two options:
- We guard this behavior behind a `-Z` flag (that Miri will set by default). There is no known case of these aliasing violations causing miscompilations. But absence of evidence is not evidence of absence...
- (What this PR does right now.) We temporarily adjust the coroutine layout logic and the associated tests until the proper fix lands. The "proper fix" here is to wrap fields that other fields can point to in [`UnsafePinned`](https://github.com/rust-lang/rust/issues/125735) and make `UnsafePinned` suppress niches; that would then still permit using niches of *other* fields (those that never get borrowed). However, I know that coroutine sizes are already a problem, so I am not sure if this temporary size regression is acceptable.

`@compiler-errors` any opinion? Also who else should be Cc'd here?
2024-09-08 03:11:12 +00:00
..
abi.rs Stop using a special inner body for the coroutine by-move body for async closures 2024-08-26 18:44:19 -04:00
assoc.rs address review comments 2024-06-28 15:44:20 +00:00
common_traits.rs Start implementing needs_async_drop and related 2024-05-29 12:50:44 +03:00
consts.rs Use bool in favor of Option<()> for diagnostics 2024-08-21 01:31:11 -04:00
errors.rs Add warn(unreachable_pub) to rustc_ty_utils. 2024-09-03 08:50:33 +10:00
implied_bounds.rs Stop using a special inner body for the coroutine by-move body for async closures 2024-08-26 18:44:19 -04:00
instance.rs document & impl the transmutation modeled by BikeshedIntrinsicFrom 2024-08-23 14:37:36 +00:00
layout_sanity_check.rs Use assert_matches around the compiler 2024-08-11 12:25:39 -04:00
layout.rs supress niches in coroutines 2024-08-20 17:00:13 +02:00
lib.rs Add warn(unreachable_pub) to rustc_ty_utils. 2024-09-03 08:50:33 +10:00
needs_drop.rs Fix elided_named_lifetimes in code 2024-08-24 19:21:32 +03:00
opaque_types.rs Stop using a special inner body for the coroutine by-move body for async closures 2024-08-26 18:44:19 -04:00
representability.rs Remove extern crate rustc_middle from rustc_ty_utils. 2024-05-13 08:20:18 +10:00
sig_types.rs Stop using a special inner body for the coroutine by-move body for async closures 2024-08-26 18:44:19 -04:00
structural_match.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
ty.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00