mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
rust: pin-init: internal: init: emit slot using mixed site hygiene
Syn/quote's default is the call site hygiene. If user provides a field
named `slot`, it will conflict with pin-init generated `slot` identifier.
Change it to use mixed site hygiene instead.
Fixes: 4883830e97 ("rust: pin-init: rewrite the initializer macros using `syn`")
Link: https://patch.msgid.link/20260916-dev-hygiene-v1-1-dfb6ae2588ba@garyguo.net
Signed-off-by: Gary Guo <gary@garyguo.net>
This commit is contained in:
parent
3b3ff9034a
commit
e30decc3f9
|
|
@ -1,7 +1,7 @@
|
|||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
use proc_macro2::{Span, TokenStream};
|
||||
use quote::{format_ident, quote, ToTokens, TokenStreamExt};
|
||||
use quote::{format_ident, quote, quote_spanned, ToTokens, TokenStreamExt};
|
||||
use syn::{
|
||||
braced, parenthesized,
|
||||
parse::{End, Parse},
|
||||
|
|
@ -269,7 +269,7 @@ fn expand(
|
|||
},
|
||||
|(_, err)| Box::new(err),
|
||||
);
|
||||
let slot = format_ident!("slot");
|
||||
let slot = Ident::new("slot", Span::mixed_site());
|
||||
let (has_data_trait, get_data, init_from_closure) = if pinned {
|
||||
(
|
||||
format_ident!("HasPinData"),
|
||||
|
|
@ -302,7 +302,7 @@ fn assert_zeroable<T: ?::core::marker::Sized>(_: *mut T)
|
|||
};
|
||||
let this = match this {
|
||||
None => quote!(),
|
||||
Some(This { ident, .. }) => quote! {
|
||||
Some(This { ident, .. }) => quote_spanned! { Span::mixed_site() =>
|
||||
// Create the `this` so it can be referenced by the user inside of the
|
||||
// expressions creating the individual fields.
|
||||
let #ident = unsafe { ::core::ptr::NonNull::new_unchecked(slot) };
|
||||
|
|
@ -312,7 +312,7 @@ fn assert_zeroable<T: ?::core::marker::Sized>(_: *mut T)
|
|||
let data = Ident::new("__data", Span::mixed_site());
|
||||
let init_fields = init_fields(&fields, pinned, &data, &slot);
|
||||
let field_check = make_field_check(&fields, init_kind, &path);
|
||||
Ok(quote! {{
|
||||
Ok(quote_spanned! { Span::mixed_site() => {
|
||||
// Get the data about fields from the supplied type.
|
||||
// SAFETY: TODO
|
||||
let #data = unsafe {
|
||||
|
|
@ -512,7 +512,7 @@ fn make_field_check(
|
|||
..::core::mem::zeroed()
|
||||
}),
|
||||
};
|
||||
quote! {
|
||||
quote_spanned! { Span::mixed_site() =>
|
||||
#[allow(unreachable_code)]
|
||||
// We use unreachable code to perform field checks. They're still checked by the compiler.
|
||||
// SAFETY: this code is never executed.
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user