Skip to content

Commit d61e158

Browse files
authored
Merge pull request #121 from dtolnay/assert
Move element size check into private_new
2 parents f349938 + 824eb3a commit d61e158

File tree

4 files changed

+6
-8
lines changed

4 files changed

+6
-8
lines changed

impl/src/declaration.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,6 @@ pub fn expand(input: TokenStream) -> TokenStream {
229229
)))]
230230
#unsupported_platform
231231

232-
#linkme_path::__private::assert!(
233-
#linkme_path::__private::mem::size_of::<<#ty as #linkme_path::__private::Slice>::Element>() > 0,
234-
);
235-
236232
unsafe {
237233
#linkme_path::DistributedSlice::private_new(
238234
#name,

src/distributed_slice.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,16 @@ impl<T> Clone for StaticPtr<T> {
155155

156156
impl<T> DistributedSlice<[T]> {
157157
#[doc(hidden)]
158+
#[track_caller]
158159
pub const unsafe fn private_new(
159160
name: &'static str,
160161
section_start: *const [T; 0],
161162
section_stop: *const [T; 0],
162163
dupcheck_start: *const (),
163164
dupcheck_stop: *const (),
164165
) -> Self {
166+
assert!(mem::size_of::<T>() > 0);
167+
165168
DistributedSlice {
166169
name,
167170
section_start: StaticPtr {

src/private.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#[doc(hidden)]
2-
pub use core::assert;
3-
#[doc(hidden)]
42
pub use core::mem;
53
#[doc(hidden)]
64
pub use core::primitive::isize;

tests/ui/zerosized.stderr

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
error[E0080]: evaluation panicked: assertion failed: ::linkme::__private::mem::size_of::<<[Unit] as
2-
::linkme::__private::Slice>::Element>() > 0
1+
error[E0080]: evaluation panicked: assertion failed: mem::size_of::<T>() > 0
32
--> tests/ui/zerosized.rs:7:1
43
|
54
7 | #[distributed_slice]
65
| ^^^^^^^^^^^^^^^^^^^^ evaluation of `ZEROSIZED` failed here
6+
|
7+
= note: this error originates in the attribute macro `distributed_slice` (in Nightly builds, run with -Z macro-backtrace for more info)

0 commit comments

Comments
 (0)