Skip to content

Commit bdc0724

Browse files
committed
TEST: To show the improvement of maybe_uninit, fix the comments in sort-axis.rs
See comments. There is no real panic critical section, just the small section that hands over ownership.
1 parent 1229eea commit bdc0724

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

examples/sort-axis.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ where
104104

105105
let mut result = Array::maybe_uninit(self.dim());
106106

107-
// panic-critical begin: we must not panic
108107
unsafe {
109108
// logically move ownership of all elements from self into result
110109
// the result realizes this ownership at .assume_init() further down
@@ -118,15 +117,16 @@ where
118117
moved_elements += 1;
119118
});
120119
}
120+
debug_assert_eq!(result.len(), moved_elements);
121+
// panic-critical begin: we must not panic
121122
// forget moved array elements but not its vec
122123
// old_storage drops empty
123124
let mut old_storage = self.into_raw_vec();
124125
old_storage.set_len(0);
125126

126-
debug_assert_eq!(result.len(), moved_elements);
127127
result.assume_init()
128+
// panic-critical end
128129
}
129-
// panic-critical end
130130
}
131131
}
132132

0 commit comments

Comments
 (0)