Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
853ffc7
stack overflow handler specific openbsd fix.
devnexen Jul 27, 2021
af83a96
std: Stabilize command_access
lf- Aug 28, 2021
4be574e
Add 'core::array::from_fn' and 'core::array::try_from_fn'
c410-f3r Sep 30, 2021
fdccc7d
Use reference instead of raw pointer
c410-f3r Sep 30, 2021
325025e
Improve previous commit
steffahn Sep 30, 2021
13bfcb7
Merge pull request #2 from steffahn/collect_into_array_fix_ub
c410-f3r Sep 30, 2021
355c7e9
Remove an unnecessary use of unwrap_unchecked
steffahn Sep 30, 2021
91ad91e
Skip platforms without unwinding support
c410-f3r Oct 3, 2021
5e1941c
Apply suggestions from code review
yaahc Oct 5, 2021
e159d42
Redo #81358 in unicode-table-generator
cuviper Oct 6, 2021
6b0b417
Let unicode-table-generator fail gracefully for bitsets
cuviper Oct 7, 2021
459a7e3
Regenerate tables for Unicode 14.0.0
cuviper Oct 7, 2021
6a52fb7
Add documentation to boxed conversions
timClicks Oct 8, 2021
85c4a52
Also cfg flag auxiliar function
c410-f3r Oct 8, 2021
fa5a212
Simplify wording
timClicks Oct 9, 2021
020ec0a
Remove unnecessary hyphen
timClicks Oct 9, 2021
3214253
Fix invalid HTML generation for higher bounds
GuillaumeGomez Oct 8, 2021
86bf3ce
Rollup merge of #75644 - c410-f3r:array, r=yaahc
GuillaumeGomez Oct 9, 2021
3e4f956
Rollup merge of #87528 - :stack_overflow_obsd, r=joshtriplett
GuillaumeGomez Oct 9, 2021
703cb97
Rollup merge of #88436 - lf-:stabilize-command-access, r=yaahc
GuillaumeGomez Oct 9, 2021
21a5101
Rollup merge of #89614 - cuviper:unicode-14, r=joshtriplett
GuillaumeGomez Oct 9, 2021
9f32ab8
Rollup merge of #89664 - timClicks:51430-document-boxed-conversions, …
GuillaumeGomez Oct 9, 2021
3e93472
Rollup merge of #89700 - GuillaumeGomez:fix-rustdoc-higher-bound-html…
GuillaumeGomez Oct 9, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use reference instead of raw pointer
  • Loading branch information
c410-f3r committed Sep 30, 2021
commit fdccc7dad9f9d4227ce07189585cc5214868bc28
14 changes: 7 additions & 7 deletions library/core/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,16 +559,17 @@ where
return unsafe { Some(Ok(mem::zeroed())) };
}

struct Guard<T, const N: usize> {
ptr: *mut T,
struct Guard<'a, T, const N: usize> {
array_mut: &'a mut [MaybeUninit<T>; N],
initialized: usize,
}

impl<T, const N: usize> Drop for Guard<T, N> {
impl<T, const N: usize> Drop for Guard<'_, T, N> {
fn drop(&mut self) {
debug_assert!(self.initialized <= N);

let initialized_part = crate::ptr::slice_from_raw_parts_mut(self.ptr, self.initialized);
let ptr = MaybeUninit::slice_as_mut_ptr(self.array_mut);
let initialized_part = crate::ptr::slice_from_raw_parts_mut(ptr, self.initialized);

// SAFETY: this raw slice will contain only initialized objects.
unsafe {
Expand All @@ -578,8 +579,7 @@ where
}

let mut array = MaybeUninit::uninit_array::<N>();
let mut guard: Guard<_, N> =
Guard { ptr: MaybeUninit::slice_as_mut_ptr(&mut array), initialized: 0 };
let mut guard: Guard<'_, _, N> = Guard { array_mut: &mut array, initialized: 0 };

while let Some(item_rslt) = iter.next() {
let item = match item_rslt {
Expand All @@ -593,7 +593,7 @@ where
// loop and the loop is aborted once it reaches N (which is
// `array.len()`).
unsafe {
array.get_unchecked_mut(guard.initialized).write(item);
guard.array_mut.get_unchecked_mut(guard.initialized).write(item);
}
guard.initialized += 1;

Expand Down