Skip to content

Commit

Permalink
Update comments for derive macros
Browse files Browse the repository at this point in the history
  • Loading branch information
gio256 committed Jun 25, 2024
1 parent 16c0051 commit c7bc00b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion derive/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ macro_rules! span_err {
}
pub(crate) use span_err;

/// Checks the condition and returns early with the given error message if
/// Checks the condition and returns early with a prefixed error message if
/// false.
macro_rules! ensure {
($cond:expr, $ast:expr, $msg:literal $(,)?) => {
Expand Down
8 changes: 4 additions & 4 deletions derive/src/impls/columns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ pub(crate) fn try_derive(ast: DeriveInput) -> Result<proc_macro2::TokenStream> {
let is_struct = matches!(ast.data, Data::Struct(_));
ensure!(is_struct, &ast, "expected `struct`");

// Check that the struct is `#[repr(C)]`
// Check that the struct is `#[repr(C)]`.
let repr_c = is_repr_c(&ast.attrs);
ensure!(repr_c, &ast, "column struct must be `#[repr(C)]`");

// The name of the struct.
let name = &ast.ident;

// Safety: `u8` is guaranteed to have a `size_of` of 1.
// SAFETY: `u8` is guaranteed to have a `size_of` of 1.
// https://doc.rust-lang.org/reference/type-layout.html#primitive-data-layout
let num_columns = quote!(::core::mem::size_of::<#name<u8>>());

// Safety:
// A repr(C) struct generic over T has the same layout as an array [T; N] if:
// SAFETY: A struct generic over T has the same layout as an array [T; N] if:
// - The struct is `#[repr(C)]`.
// - Every field of the struct is either T or a type with the same alignment as
// T and a size of `size_of::<T>() * M` where M <= N. i.e. every field is one
// of T, [T; M], or a type with the same layout as [T; M].
Expand Down
8 changes: 4 additions & 4 deletions derive/src/impls/deref_columns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ pub(crate) fn try_derive(ast: DeriveInput) -> Result<proc_macro2::TokenStream> {
let is_struct = matches!(ast.data, Data::Struct(_));
ensure!(is_struct, &ast, "expected `struct`");

// Check that the struct is `#[repr(C)]`
// Check that the struct is `#[repr(C)]`.
let repr_c = is_repr_c(&ast.attrs);
ensure!(repr_c, &ast, "column struct must be `#[repr(C)]`");

// The name of the struct.
let name = &ast.ident;

// Safety: `u8` is guaranteed to have a `size_of` of 1.
// SAFETY: `u8` is guaranteed to have a `size_of` of 1.
// https://doc.rust-lang.org/reference/type-layout.html#primitive-data-layout
let num_columns = quote!(::core::mem::size_of::<#name<u8>>());

// Safety:
// A repr(C) struct generic over T has the same layout as an array [T; N] if:
// SAFETY: A struct generic over T has the same layout as an array [T; N] if:
// - The struct is `#[repr(C)]`.
// - Every field of the struct is either T or a type with the same alignment as
// T and a size of `size_of::<T>() * M` where M <= N. i.e. every field is one
// of T, [T; M], or a type with the same layout as [T; M].
Expand Down

0 comments on commit c7bc00b

Please sign in to comment.