diff options
| author | Jeremy Smart <jeremy3141592@gmail.com> | 2025-06-04 18:15:12 -0400 |
|---|---|---|
| committer | Jeremy Smart <jeremy3141592@gmail.com> | 2025-06-04 18:15:12 -0400 |
| commit | 188c40126dbda835e80238ea70eaef7d09e3e167 (patch) | |
| tree | 82d59cc60db8e3f7559d9223f349f62aaa97b170 /library/alloctests | |
| parent | 59aa1e873028948faaf8b97e5e02d4db340ad7b1 (diff) | |
| download | rust-188c40126dbda835e80238ea70eaef7d09e3e167.tar.gz rust-188c40126dbda835e80238ea70eaef7d09e3e167.zip | |
add Vec::peek_mut
Diffstat (limited to 'library/alloctests')
| -rw-r--r-- | library/alloctests/lib.rs | 1 | ||||
| -rw-r--r-- | library/alloctests/tests/vec.rs | 11 |
2 files changed, 12 insertions, 0 deletions
diff --git a/library/alloctests/lib.rs b/library/alloctests/lib.rs index 56e60ed4c84..232cf06fff9 100644 --- a/library/alloctests/lib.rs +++ b/library/alloctests/lib.rs @@ -42,6 +42,7 @@ #![feature(trusted_random_access)] #![feature(try_reserve_kind)] #![feature(try_trait_v2)] +#![feature(vec_peek_mut)] // tidy-alphabetical-end // // Language features: diff --git a/library/alloctests/tests/vec.rs b/library/alloctests/tests/vec.rs index f430d979fa8..0de9da37561 100644 --- a/library/alloctests/tests/vec.rs +++ b/library/alloctests/tests/vec.rs @@ -2698,6 +2698,17 @@ fn test_pop_if_mutates() { assert_eq!(v, [2]); } +#[test] +fn test_peek_mut() { + let mut vec = Vec::new(); + assert!(vec.peek_mut().is_none()); + vec.push(1); + vec.push(2); + assert_eq!(vec.peek_mut(), Some(2)); + *vec.peek_mut() = 0; + assert_eq!(vec.peek_mut(), Some(0)); +} + /// This assortment of tests, in combination with miri, verifies we handle UB on fishy arguments /// in the stdlib. Draining and extending the allocation are fairly well-tested earlier, but /// `vec.insert(usize::MAX, val)` once slipped by! |
