[PATCH 1/3] rust: pin-init: internal: pin_init: emit `slot` using mixed site hygiene
From: Gary Guo
Date: Wed Sep 16 2026 - 08:32:04 EST
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: 4883830e9784 ("rust: pin-init: rewrite the initializer macros using `syn`")
Signed-off-by: Gary Guo <gary@xxxxxxxxxxx>
---
rust/pin-init/internal/src/init.rs | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/rust/pin-init/internal/src/init.rs b/rust/pin-init/internal/src/init.rs
index dc5dfb2ca114..6ade192d27e6 100644
--- a/rust/pin-init/internal/src/init.rs
+++ b/rust/pin-init/internal/src/init.rs
@@ -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.
--
2.54.0