Skip to content

Commit dd060bd

Browse files
committed
Slice methods are not lifetmiebound
Since slice holds references, returning those references does not mean they are bound to the lifetime of the slice itself.
1 parent 7b70cdc commit dd060bd

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

subspace/containers/slice.h

+14-19
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class [[sus_trivial_abi]] Slice {
6060
constexpr Slice() : Slice(nullptr, 0_usize) {}
6161

6262
static constexpr inline Slice from_raw_parts(::sus::marker::UnsafeFnMarker,
63-
T* data,
63+
T* data sus_lifetimebound,
6464
::sus::usize len) noexcept {
6565
::sus::check(size_t{len} <= size_t{isize::MAX_PRIMITIVE});
6666
return Slice(data, len);
@@ -84,13 +84,12 @@ class [[sus_trivial_abi]] Slice {
8484
/// # Panics
8585
/// If the index `i` is beyond the end of the slice, the function will panic.
8686
/// #[doc.overloads=slice.index.usize]
87-
constexpr inline const T& operator[](usize i) const& noexcept
88-
sus_lifetimebound {
87+
constexpr inline const T& operator[](usize i) const& noexcept {
8988
check(i < len_);
9089
return data_[i.primitive_value];
9190
}
9291

93-
constexpr T& operator[](usize i) & noexcept sus_lifetimebound
92+
constexpr T& operator[](usize i) & noexcept
9493
requires(!std::is_const_v<T>)
9594
{
9695
check(i < len_);
@@ -99,7 +98,7 @@ class [[sus_trivial_abi]] Slice {
9998

10099
/// Returns a const reference to the element at index `i`, or `None` if
101100
/// `i` is beyond the end of the Slice.
102-
constexpr Option<const T&> get(usize i) const& noexcept sus_lifetimebound {
101+
constexpr Option<const T&> get(usize i) const& noexcept {
103102
if (i < len_) [[likely]]
104103
return Option<const T&>::some(data_[i.primitive_value]);
105104
else
@@ -108,7 +107,7 @@ class [[sus_trivial_abi]] Slice {
108107

109108
/// Returns a mutable reference to the element at index `i`, or `None` if
110109
/// `i` is beyond the end of the Slice.
111-
constexpr Option<T&> get_mut(usize i) & noexcept sus_lifetimebound
110+
constexpr Option<T&> get_mut(usize i) & noexcept
112111
requires(!std::is_const_v<T>)
113112
{
114113
if (i < len_) [[likely]]
@@ -124,8 +123,7 @@ class [[sus_trivial_abi]] Slice {
124123
/// Behaviour results. The size of the slice must therefore also have a length
125124
/// of at least 1.
126125
constexpr inline const T& get_unchecked(::sus::marker::UnsafeFnMarker,
127-
usize i) const& noexcept
128-
sus_lifetimebound {
126+
usize i) const& noexcept {
129127
return data_[i.primitive_value];
130128
}
131129

@@ -136,7 +134,7 @@ class [[sus_trivial_abi]] Slice {
136134
/// Behaviour results. The size of the slice must therefore also have a length
137135
/// of at least 1.
138136
constexpr inline T& get_unchecked_mut(::sus::marker::UnsafeFnMarker,
139-
usize i) & noexcept sus_lifetimebound
137+
usize i) & noexcept
140138
requires(!std::is_const_v<T>)
141139
{
142140
return data_[i.primitive_value];
@@ -155,8 +153,7 @@ class [[sus_trivial_abi]] Slice {
155153
/// function will panic.
156154
/// #[doc.overloads=slice.index.range]
157155
constexpr inline Slice<T> operator[](
158-
const ::sus::ops::RangeBounds<usize> auto range) const noexcept
159-
sus_lifetimebound {
156+
const ::sus::ops::RangeBounds<usize> auto range) const noexcept {
160157
const usize start = range.start_bound().unwrap_or(0u);
161158
const usize end = range.end_bound().unwrap_or(len_);
162159
const usize len = end >= start ? end - start : 0u;
@@ -177,8 +174,7 @@ class [[sus_trivial_abi]] Slice {
177174
/// Returns None if the Range would otherwise contain an element that is out
178175
/// of bounds.
179176
constexpr Option<Slice<T>> get_range(
180-
const ::sus::ops::RangeBounds<usize> auto range) const noexcept
181-
sus_lifetimebound {
177+
const ::sus::ops::RangeBounds<usize> auto range) const noexcept {
182178
const usize start = range.start_bound().unwrap_or(0u);
183179
const usize end = range.end_bound().unwrap_or(len_);
184180
const usize len = end >= start ? end - start : 0u;
@@ -201,8 +197,7 @@ class [[sus_trivial_abi]] Slice {
201197
/// of bounds of the Slice, which can result in Undefined Behaviour.
202198
constexpr Slice<T> get_range_unchecked(
203199
::sus::marker::UnsafeFnMarker,
204-
const ::sus::ops::RangeBounds<usize> auto range) const noexcept
205-
sus_lifetimebound {
200+
const ::sus::ops::RangeBounds<usize> auto range) const noexcept {
206201
const usize start = range.start_bound().unwrap_or(0u);
207202
const usize end = range.end_bound().unwrap_or(len_);
208203
const usize len = end >= start ? end - start : 0u;
@@ -287,13 +282,13 @@ class [[sus_trivial_abi]] Slice {
287282
}
288283

289284
/// Returns a const pointer to the first element in the slice.
290-
inline const T* as_ptr() const& noexcept sus_lifetimebound {
285+
inline const T* as_ptr() const& noexcept {
291286
check(len_ > 0_usize);
292287
return data_;
293288
}
294289

295290
/// Returns a mutable pointer to the first element in the slice.
296-
inline T* as_mut_ptr() & noexcept sus_lifetimebound
291+
inline T* as_mut_ptr() & noexcept
297292
requires(!std::is_const_v<T>)
298293
{
299294
check(len_ > 0_usize);
@@ -303,14 +298,14 @@ class [[sus_trivial_abi]] Slice {
303298
/// Returns an iterator over all the elements in the slice, visited in the
304299
/// same order they appear in the slice. The iterator gives const access to
305300
/// each element.
306-
constexpr SliceIter<const T&> iter() const& noexcept sus_lifetimebound {
301+
constexpr SliceIter<const T&> iter() const& noexcept {
307302
return SliceIter<const T&>::with(data_, len_);
308303
}
309304

310305
/// Returns an iterator over all the elements in the slice, visited in the
311306
/// same order they appear in the slice. The iterator gives mutable access to
312307
/// each element.
313-
constexpr SliceIterMut<T&> iter_mut() noexcept sus_lifetimebound
308+
constexpr SliceIterMut<T&> iter_mut() noexcept
314309
requires(!std::is_const_v<T>)
315310
{
316311
return SliceIterMut<T&>::with(data_, len_);

0 commit comments

Comments
 (0)