rust/compiler/rustc_mir_transform/src
bors 8a7ca936e6 Auto merge of #105587 - tgross35:once-cell-min, r=m-ou-se
Partial stabilization of `once_cell`

This PR aims to stabilize a portion of the `once_cell` feature:

- `core::cell::OnceCell`
- `std::cell::OnceCell` (re-export of the above)
- `std::sync::OnceLock`

This will leave `LazyCell` and `LazyLock` unstabilized, which have been moved to the `lazy_cell` feature flag.

Tracking issue: https://github.com/rust-lang/rust/issues/74465 (does not fully close, but it may make sense to move to a new issue)

Future steps for separate PRs:
- ~~Add `#[inline]` to many methods~~ #105651
- Update cranelift usage of the `once_cell` crate
- Update rust-analyzer usage of the `once_cell` crate
- Update error messages discussing once_cell

## To be stabilized API summary

```rust
// core::cell (in core/cell/once.rs)

pub struct OnceCell<T> { .. }

impl<T> OnceCell<T> {
    pub const fn new() -> OnceCell<T>;
    pub fn get(&self) -> Option<&T>;
    pub fn get_mut(&mut self) -> Option<&mut T>;
    pub fn set(&self, value: T) -> Result<(), T>;
    pub fn get_or_init<F>(&self, f: F) -> &T where F: FnOnce() -> T;
    pub fn into_inner(self) -> Option<T>;
    pub fn take(&mut self) -> Option<T>;
}

impl<T: Clone> Clone for OnceCell<T>;
impl<T: Debug> Debug for OnceCell<T>
impl<T> Default for OnceCell<T>;
impl<T> From<T> for OnceCell<T>;
impl<T: PartialEq> PartialEq for OnceCell<T>;
impl<T: Eq> Eq for OnceCell<T>;
```

```rust
// std::sync (in std/sync/once_lock.rs)

impl<T> OnceLock<T> {
    pub const fn new() -> OnceLock<T>;
    pub fn get(&self) -> Option<&T>;
    pub fn get_mut(&mut self) -> Option<&mut T>;
    pub fn set(&self, value: T) -> Result<(), T>;
    pub fn get_or_init<F>(&self, f: F) -> &T where F: FnOnce() -> T;
    pub fn into_inner(self) -> Option<T>;
    pub fn take(&mut self) -> Option<T>;
}

impl<T: Clone> Clone for OnceLock<T>;
impl<T: Debug> Debug for OnceLock<T>;
impl<T> Default for OnceLock<T>;
impl<#[may_dangle] T> Drop for OnceLock<T>;
impl<T> From<T> for OnceLock<T>;
impl<T: PartialEq> PartialEq for OnceLock<T>
impl<T: Eq> Eq for OnceLock<T>;
impl<T: RefUnwindSafe + UnwindSafe> RefUnwindSafe for OnceLock<T>;
unsafe impl<T: Send> Send for OnceLock<T>;
unsafe impl<T: Sync + Send> Sync for OnceLock<T>;
impl<T: UnwindSafe> UnwindSafe for OnceLock<T>;
```

No longer planned as part of this PR, and moved to the `rust_cell_try` feature gate:

```rust
impl<T> OnceCell<T> {
    pub fn get_or_try_init<F, E>(&self, f: F) -> Result<&T, E> where F: FnOnce() -> Result<T, E>;
}

impl<T> OnceLock<T> {
    pub fn get_or_try_init<F, E>(&self, f: F) -> Result<&T, E> where F: FnOnce() -> Result<T, E>;
}
```

I am new to this process so would appreciate mentorship wherever needed.
2023-03-30 10:12:23 +00:00
..
coverage Rename IndexVec::lastlast_index 2023-03-29 00:27:24 -07:00
inline Support TLS access into dylibs on Windows 2023-03-29 08:55:21 +02:00
abort_unwinding_calls.rs Remove DropAndReplace terminator 2023-03-07 14:25:22 +01:00
add_call_guards.rs Replace Body::basic_blocks() with field access 2022-08-26 14:27:08 +02:00
add_moves_for_packed_drops.rs Remove DropAndReplace terminator 2023-03-07 14:25:22 +01:00
add_retag.rs Remove DropAndReplace terminator 2023-03-07 14:25:22 +01:00
check_const_item_mutation.rs Wrap the whole LocalInfo in ClearCrossCrate. 2023-03-14 20:52:42 +01:00
check_packed_ref.rs Properly check for builtin derives 2023-02-16 19:44:03 +00:00
check_unsafety.rs Wrap the whole LocalInfo in ClearCrossCrate. 2023-03-14 20:52:42 +01:00
cleanup_post_borrowck.rs Introduce a no-op PlaceMention statement for let _ =. 2023-03-09 17:45:13 +00:00
const_debuginfo.rs Rename debugging_opts to unstable_opts 2022-07-13 17:47:06 -05:00
const_goto.rs Disable ConstGoto opt in cleanup blocks 2023-01-26 03:50:37 -08:00
const_prop_lint.rs Don't elaborate non-obligations into obligations 2023-03-26 20:33:54 +00:00
const_prop.rs Don't elaborate non-obligations into obligations 2023-03-26 20:33:54 +00:00
copy_prop.rs Rename many interner functions. 2023-02-24 07:32:24 +11:00
ctfe_limit.rs don't into self 2023-02-16 18:30:25 +01:00
dataflow_const_prop.rs Move mir::Fieldabi::FieldIdx 2023-03-28 22:22:37 -07:00
dead_store_elimination.rs Introduce a no-op PlaceMention statement for let _ =. 2023-03-09 17:45:13 +00:00
deduce_param_attrs.rs Use local key in providers 2023-03-21 15:38:51 +00:00
deduplicate_blocks.rs Replace Body::basic_blocks() with field access 2022-08-26 14:27:08 +02:00
deref_separator.rs Wrap the whole LocalInfo in ClearCrossCrate. 2023-03-14 20:52:42 +01:00
dest_prop.rs Remove LocalKind::Var. 2023-03-14 20:52:42 +01:00
dump_mir.rs Auto merge of #105220 - oli-obk:feeding, r=cjgillot 2022-12-06 03:47:41 +00:00
early_otherwise_branch.rs Remove unneeded field from SwitchTargets 2022-12-09 04:53:10 -08:00
elaborate_box_derefs.rs Move mir::Fieldabi::FieldIdx 2023-03-28 22:22:37 -07:00
elaborate_drops.rs Move mir::Fieldabi::FieldIdx 2023-03-28 22:22:37 -07:00
ffi_unwind_calls.rs LocalCrate key 2023-03-21 15:38:52 +00:00
function_item_references.rs if $c:expr { Some($r:expr) } else { None } =>> $c.then(|| $r) 2023-02-16 15:26:00 +00:00
generator.rs Move mir::Fieldabi::FieldIdx 2023-03-28 22:22:37 -07:00
inline.rs Rollup merge of #109716 - scottmcm:field-to-fieldidx, r=oli-obk 2023-03-29 21:19:51 +02:00
instcombine.rs Move mir::Fieldabi::FieldIdx 2023-03-28 22:22:37 -07:00
large_enums.rs Remove uses of box_syntax in rustc and tools 2023-03-12 13:19:46 +00:00
lib.rs Stabilize a portion of 'once_cell' 2023-03-29 18:04:44 -04:00
lower_intrinsics.rs Move mir::Fieldabi::FieldIdx 2023-03-28 22:22:37 -07:00
lower_slice_len.rs Match unmatched backticks in comments in compiler/ 2023-03-03 08:39:00 +01:00
match_branches.rs Remove unneeded field from SwitchTargets 2022-12-09 04:53:10 -08:00
multiple_return_terminators.rs Replace Body::basic_blocks() with field access 2022-08-26 14:27:08 +02:00
normalize_array_len.rs Remove obsolete comment. 2023-01-29 22:09:51 +00:00
nrvo.rs Remove LocalKind::Var. 2023-03-14 20:52:42 +01:00
pass_manager.rs Use zero based indexing for pass_count 2022-12-02 15:55:24 +00:00
remove_noop_landing_pads.rs Introduce a no-op PlaceMention statement for let _ =. 2023-03-09 17:45:13 +00:00
remove_storage_markers.rs Make MIR basic blocks field public 2022-07-07 08:11:49 +02:00
remove_uninit_drops.rs Move mir::Fieldabi::FieldIdx 2023-03-28 22:22:37 -07:00
remove_unneeded_drops.rs Make MIR basic blocks field public 2022-07-07 08:11:49 +02:00
remove_zsts.rs Generalize operation. 2023-03-13 18:22:55 +00:00
required_consts.rs Don't ICE when encountering ConstKind::Error in RequiredConstsVisitor 2022-11-10 05:14:04 +00:00
reveal_all.rs Add option to mir::MutVisitor to not invalidate CFG. 2022-08-09 01:51:10 -07:00
separate_const_switch.rs Introduce a no-op PlaceMention statement for let _ =. 2023-03-09 17:45:13 +00:00
shim.rs Rollup merge of #109716 - scottmcm:field-to-fieldidx, r=oli-obk 2023-03-29 21:19:51 +02:00
simplify_branches.rs Remove unneeded field from SwitchTargets 2022-12-09 04:53:10 -08:00
simplify_comparison_integral.rs Remove unneeded field from SwitchTargets 2022-12-09 04:53:10 -08:00
simplify.rs Explain how we get to skip checking for cleanup blocks in the visitor 2023-03-25 13:58:49 -04:00
sroa.rs Move mir::Fieldabi::FieldIdx 2023-03-28 22:22:37 -07:00
ssa.rs Do not grow assignment_order needlessly. 2023-02-27 20:02:18 +00:00
uninhabited_enum_branching.rs move things from rustc_target::abi to rustc_abi 2022-11-24 16:26:13 +03:30
unreachable_prop.rs Change src/test to tests in source files, fix tidy and tests 2023-01-11 09:32:13 +00:00