diff options
| author | bors <bors@rust-lang.org> | 2025-06-27 00:44:20 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-06-27 00:44:20 +0000 |
| commit | e61dd437f33b5a640e67dc3628397689c664c17f (patch) | |
| tree | fe823cac3a7f456538d748b1892313bb91e59ca8 /library/coretests | |
| parent | 513999b936c37902120380f4171963d1f1d80347 (diff) | |
| parent | cb0b62121c401909fc946569825c5c99229e9f44 (diff) | |
| download | rust-e61dd437f33b5a640e67dc3628397689c664c17f.tar.gz rust-e61dd437f33b5a640e67dc3628397689c664c17f.zip | |
Auto merge of #143074 - compiler-errors:rollup-cv64hdh, r=compiler-errors
Rollup of 18 pull requests Successful merges: - rust-lang/rust#137843 (make RefCell unstably const) - rust-lang/rust#140942 (const-eval: allow constants to refer to mutable/external memory, but reject such constants as patterns) - rust-lang/rust#142549 (small iter.intersperse.fold() optimization) - rust-lang/rust#142637 (Remove some glob imports from the type system) - rust-lang/rust#142647 ([perf] Compute hard errors without diagnostics in impl_intersection_has_impossible_obligation) - rust-lang/rust#142700 (Remove incorrect comments in `Weak`) - rust-lang/rust#142927 (Add note to `find_const_ty_from_env`) - rust-lang/rust#142967 (Fix RwLock::try_write documentation for WouldBlock condition) - rust-lang/rust#142986 (Port `#[export_name]` to the new attribute parsing infrastructure) - rust-lang/rust#143001 (Rename run always ) - rust-lang/rust#143010 (Update `browser-ui-test` version to `0.20.7`) - rust-lang/rust#143015 (Add `sym::macro_pin` diagnostic item for `core::pin::pin!()`) - rust-lang/rust#143033 (Expand const-stabilized API links in relnotes) - rust-lang/rust#143041 (Remove cache for citool) - rust-lang/rust#143056 (Move an ACE test out of the GCI directory) - rust-lang/rust#143059 (Fix 1.88 relnotes) - rust-lang/rust#143067 (Tracking issue number for `iter_macro`) - rust-lang/rust#143073 (Fix some fixmes that were waiting for let chains) Failed merges: - rust-lang/rust#143020 (codegen_fn_attrs: make comment more precise) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'library/coretests')
| -rw-r--r-- | library/coretests/tests/cell.rs | 72 | ||||
| -rw-r--r-- | library/coretests/tests/lib.rs | 3 |
2 files changed, 75 insertions, 0 deletions
diff --git a/library/coretests/tests/cell.rs b/library/coretests/tests/cell.rs index 781a46c3744..c0ac66e5d2b 100644 --- a/library/coretests/tests/cell.rs +++ b/library/coretests/tests/cell.rs @@ -1,4 +1,5 @@ use core::cell::*; +use core::mem::forget; #[test] fn smoketest_unsafe_cell() { @@ -477,3 +478,74 @@ fn const_cells() { const _: i32 = CELL.into_inner(); */ } + +#[test] +fn refcell_borrow() { + // Check that `borrow` is usable at compile-time + const { + let a = RefCell::new(0); + assert!(a.try_borrow().is_ok()); + assert!(a.try_borrow_mut().is_ok()); + let a_ref = a.borrow(); + assert!(*a_ref == 0); + assert!(a.try_borrow().is_ok()); + assert!(a.try_borrow_mut().is_err()); + } +} + +#[test] +fn refcell_borrow_mut() { + // Check that `borrow_mut` is usable at compile-time + const { + let mut a = RefCell::new(0); + { + assert!(a.try_borrow().is_ok()); + assert!(a.try_borrow_mut().is_ok()); + let mut a_ref = a.borrow_mut(); + assert!(*a_ref == 0); + *a_ref = 10; + assert!(*a_ref == 10); + assert!(a.try_borrow().is_err()); + assert!(a.try_borrow_mut().is_err()); + } + assert!(*a.get_mut() == 10); + }; +} +struct NeverDrop; +impl Drop for NeverDrop { + fn drop(&mut self) { + panic!("should never be called"); + } +} + +#[test] +fn refcell_replace() { + // Check that `replace` is usable at compile-time + const { + let a = RefCell::new(0); + assert!(a.replace(10) == 0); + let a = a.into_inner(); + assert!(a == 10); + + let b = RefCell::new(NeverDrop); + forget(b.replace(NeverDrop)); + forget(b) + }; +} + +#[test] +fn refcell_swap() { + // Check that `swap` is usable at compile-time + const { + let (a, b) = (RefCell::new(31), RefCell::new(41)); + a.swap(&b); + let (a, b) = (a.into_inner(), b.into_inner()); + assert!(a == 41); + assert!(b == 31); + + let c = RefCell::new(NeverDrop); + let d = RefCell::new(NeverDrop); + c.swap(&d); + forget((c, d)); + }; +} diff --git a/library/coretests/tests/lib.rs b/library/coretests/tests/lib.rs index b8a5ff620a4..0c54609260f 100644 --- a/library/coretests/tests/lib.rs +++ b/library/coretests/tests/lib.rs @@ -15,8 +15,11 @@ #![feature(cfg_target_has_reliable_f16_f128)] #![feature(char_max_len)] #![feature(clone_to_uninit)] +#![feature(const_deref)] +#![feature(const_destruct)] #![feature(const_eval_select)] #![feature(const_float_round_methods)] +#![feature(const_ref_cell)] #![feature(const_trait_impl)] #![feature(core_float_math)] #![feature(core_intrinsics)] |
