mirror of
https://github.com/Lokathor/bytemuck.git
synced 2024-11-21 14:22:26 +00:00
Remove incorrect spanned quote usage (#279)
This commit is contained in:
parent
7b98ff1cec
commit
79a15d0a3f
@ -2,7 +2,7 @@
|
|||||||
use std::{cmp, convert::TryFrom};
|
use std::{cmp, convert::TryFrom};
|
||||||
|
|
||||||
use proc_macro2::{Ident, Span, TokenStream, TokenTree};
|
use proc_macro2::{Ident, Span, TokenStream, TokenTree};
|
||||||
use quote::{quote, quote_spanned, ToTokens};
|
use quote::{quote, ToTokens};
|
||||||
use syn::{
|
use syn::{
|
||||||
parse::{Parse, ParseStream, Parser},
|
parse::{Parse, ParseStream, Parser},
|
||||||
punctuated::Punctuated,
|
punctuated::Punctuated,
|
||||||
@ -664,7 +664,7 @@ fn generate_checked_bit_pattern_enum_without_fields(
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
let check = if count == 0 {
|
let check = if count == 0 {
|
||||||
quote_spanned!(span => false)
|
quote!(false)
|
||||||
} else if max - min == count - 1 {
|
} else if max - min == count - 1 {
|
||||||
// contiguous range
|
// contiguous range
|
||||||
let min_lit = LitInt::new(&format!("{}", min), span);
|
let min_lit = LitInt::new(&format!("{}", min), span);
|
||||||
@ -962,22 +962,20 @@ fn generate_checked_bit_pattern_enum_with_fields(
|
|||||||
/// is equal to the sum of the size of it's fields
|
/// is equal to the sum of the size of it's fields
|
||||||
fn generate_assert_no_padding(input: &DeriveInput) -> Result<TokenStream> {
|
fn generate_assert_no_padding(input: &DeriveInput) -> Result<TokenStream> {
|
||||||
let struct_type = &input.ident;
|
let struct_type = &input.ident;
|
||||||
let span = input.ident.span();
|
|
||||||
let enum_variant = None; // `no padding` check is not supported for `enum`s yet.
|
let enum_variant = None; // `no padding` check is not supported for `enum`s yet.
|
||||||
let fields = get_fields(input, enum_variant)?;
|
let fields = get_fields(input, enum_variant)?;
|
||||||
|
|
||||||
let mut field_types = get_field_types(&fields);
|
let mut field_types = get_field_types(&fields);
|
||||||
let size_sum = if let Some(first) = field_types.next() {
|
let size_sum = if let Some(first) = field_types.next() {
|
||||||
let size_first = quote_spanned!(span => ::core::mem::size_of::<#first>());
|
let size_first = quote!(::core::mem::size_of::<#first>());
|
||||||
let size_rest =
|
let size_rest = quote!(#( + ::core::mem::size_of::<#field_types>() )*);
|
||||||
quote_spanned!(span => #( + ::core::mem::size_of::<#field_types>() )*);
|
|
||||||
|
|
||||||
quote_spanned!(span => #size_first #size_rest)
|
quote!(#size_first #size_rest)
|
||||||
} else {
|
} else {
|
||||||
quote_spanned!(span => 0)
|
quote!(0)
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(quote_spanned! {span => const _: fn() = || {
|
Ok(quote! {const _: fn() = || {
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
struct TypeWithoutPadding([u8; #size_sum]);
|
struct TypeWithoutPadding([u8; #size_sum]);
|
||||||
let _ = ::core::mem::transmute::<#struct_type, TypeWithoutPadding>;
|
let _ = ::core::mem::transmute::<#struct_type, TypeWithoutPadding>;
|
||||||
@ -991,9 +989,8 @@ fn generate_fields_are_trait(
|
|||||||
let (impl_generics, _ty_generics, where_clause) =
|
let (impl_generics, _ty_generics, where_clause) =
|
||||||
input.generics.split_for_impl();
|
input.generics.split_for_impl();
|
||||||
let fields = get_fields(input, enum_variant)?;
|
let fields = get_fields(input, enum_variant)?;
|
||||||
let span = input.span();
|
|
||||||
let field_types = get_field_types(&fields);
|
let field_types = get_field_types(&fields);
|
||||||
Ok(quote_spanned! {span => #(const _: fn() = || {
|
Ok(quote! {#(const _: fn() = || {
|
||||||
#[allow(clippy::missing_const_for_fn)]
|
#[allow(clippy::missing_const_for_fn)]
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
fn check #impl_generics () #where_clause {
|
fn check #impl_generics () #where_clause {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
#![deny(clippy::allow_attributes)]
|
||||||
|
|
||||||
use bytemuck::{
|
use bytemuck::{
|
||||||
checked::CheckedCastError, AnyBitPattern, CheckedBitPattern, Contiguous,
|
checked::CheckedCastError, AnyBitPattern, CheckedBitPattern, Contiguous,
|
||||||
|
Loading…
Reference in New Issue
Block a user