Skip to content

Commit 1ce5106

Browse files
committed
lang: Improve std hygiene inside macros
1 parent 82681c4 commit 1ce5106

12 files changed

Lines changed: 34 additions & 34 deletions

File tree

lang/attribute/account/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ pub fn account(
268268

269269
#[automatically_derived]
270270
impl #impl_gen anchor_lang::AccountSerialize for #account_name #type_gen #where_clause {
271-
fn try_serialize<W: std::io::Write>(&self, writer: &mut W) -> anchor_lang::Result<()> {
271+
fn try_serialize<W: ::std::io::Write>(&self, writer: &mut W) -> anchor_lang::Result<()> {
272272
if writer.write_all(#disc).is_err() {
273273
return Err(anchor_lang::error::ErrorCode::AccountDidNotSerialize.into());
274274
}

lang/attribute/program/src/declare_program/mods/accounts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub fn gen_accounts_mod(idl: &Idl) -> proc_macro2::TokenStream {
3838
match ty_def.serialization {
3939
IdlSerialization::Borsh => quote! {
4040
impl anchor_lang::AccountSerialize for #name {
41-
fn try_serialize<W: std::io::Write>(&self, writer: &mut W) -> anchor_lang::Result<()> {
41+
fn try_serialize<W: ::std::io::Write>(&self, writer: &mut W) -> anchor_lang::Result<()> {
4242
if writer.write_all(#disc).is_err() {
4343
return Err(anchor_lang::error::ErrorCode::AccountDidNotSerialize.into());
4444
}

lang/attribute/program/src/declare_program/mods/cpi.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ fn gen_cpi_instructions(idl: &Idl) -> proc_macro2::TokenStream {
5757
quote! { anchor_lang::Result<Return::<#ty>> },
5858
quote! {
5959
Ok(Return::<#ty> {
60-
phantom: std::marker::PhantomData,
60+
phantom: ::std::marker::PhantomData,
6161
program_id: ctx.program_id,
6262
return_data: anchor_lang::__private::CpiReturnData::snapshot(),
6363
})
@@ -112,7 +112,7 @@ fn gen_cpi_return_type() -> proc_macro2::TokenStream {
112112
quote! {
113113
#[derive(Debug, Clone, Copy)]
114114
pub struct Return<T> {
115-
phantom: std::marker::PhantomData<T>,
115+
phantom: ::std::marker::PhantomData<T>,
116116
program_id: anchor_lang::solana_program::pubkey::Pubkey,
117117
return_data: anchor_lang::__private::CpiReturnData,
118118
}

lang/syn/src/codegen/accounts/try_accounts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ pub fn generate(accs: &AccountsStruct) -> proc_macro2::TokenStream {
251251
__accounts: &mut &#trait_generics [anchor_lang::solana_program::account_info::AccountInfo<#trait_generics>],
252252
__ix_data: &[u8],
253253
__bumps: &mut #bumps_struct_name,
254-
__reallocs: &mut std::collections::BTreeSet<anchor_lang::solana_program::pubkey::Pubkey>,
254+
__reallocs: &mut ::std::collections::BTreeSet<anchor_lang::solana_program::pubkey::Pubkey>,
255255
) -> anchor_lang::Result<Self> {
256256
// Deserialize instruction, if declared.
257257
#ix_de
@@ -412,7 +412,7 @@ fn generate_duplicate_mutable_checks(accs: &AccountsStruct) -> proc_macro2::Toke
412412
quote! {
413413
// Duplicate mutable account validation - using HashSet
414414
{
415-
let mut __mutable_accounts = std::collections::HashSet::new();
415+
let mut __mutable_accounts = ::std::collections::HashSet::new();
416416

417417
// Check declared mutable accounts for duplicates among themselves
418418
#(

lang/syn/src/codegen/error.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub fn generate(error: Error) -> proc_macro2::TokenStream {
2121
let display_msg = match &error_code.msg {
2222
None => {
2323
quote! {
24-
<Self as std::fmt::Debug>::fmt(self, fmt)
24+
<Self as ::std::fmt::Debug>::fmt(self, fmt)
2525
}
2626
}
2727
Some(msg) => {
@@ -60,7 +60,7 @@ pub fn generate(error: Error) -> proc_macro2::TokenStream {
6060
};
6161

6262
let ret = quote! {
63-
#[derive(std::fmt::Debug, Clone, Copy)]
63+
#[derive(::std::fmt::Debug, Clone, Copy)]
6464
#[repr(u32)]
6565
#error_enum
6666

@@ -93,8 +93,8 @@ pub fn generate(error: Error) -> proc_macro2::TokenStream {
9393
}
9494
}
9595

96-
impl std::fmt::Display for #enum_name {
97-
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
96+
impl ::std::fmt::Display for #enum_name {
97+
fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::result::Result<(), ::std::fmt::Error> {
9898
match self {
9999
#(#display_variant_dispatch),*
100100
}

lang/syn/src/codegen/program/cpi.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
9393
#[cfg(feature = "cpi")]
9494
pub mod cpi {
9595
use super::*;
96-
use std::marker::PhantomData;
96+
use ::std::marker::PhantomData;
9797

9898

9999
#[derive(Debug, Clone, Copy)]
100100
pub struct Return<T> {
101-
phantom: std::marker::PhantomData<T>,
101+
phantom: ::std::marker::PhantomData<T>,
102102
program_id: anchor_lang::solana_program::pubkey::Pubkey,
103103
return_data: anchor_lang::__private::CpiReturnData,
104104
}

lang/syn/src/codegen/program/handlers.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
121121
// Bump collector.
122122
let mut __bumps = <#accounts_struct_name as anchor_lang::Bumps>::Bumps::default();
123123

124-
let mut __reallocs = std::collections::BTreeSet::new();
124+
let mut __reallocs = ::std::collections::BTreeSet::new();
125125

126126
// Deserialize accounts.
127127
let mut __remaining_accounts = __accounts;
@@ -218,55 +218,55 @@ fn generate_legacy_idl_mod() -> proc_macro2::TokenStream {
218218
match ix {
219219
anchor_lang::idl::IdlInstruction::Create { data_len } => {
220220
let mut bumps = <IdlCreateAccounts as anchor_lang::Bumps>::Bumps::default();
221-
let mut reallocs = std::collections::BTreeSet::new();
221+
let mut reallocs = ::std::collections::BTreeSet::new();
222222
let mut accounts =
223223
IdlCreateAccounts::try_accounts(program_id, &mut accounts, &[], &mut bumps, &mut reallocs)?;
224224
__idl_create_account(program_id, &mut accounts, data_len)?;
225225
accounts.exit(program_id)?;
226226
},
227227
anchor_lang::idl::IdlInstruction::Resize { data_len } => {
228228
let mut bumps = <IdlResizeAccount as anchor_lang::Bumps>::Bumps::default();
229-
let mut reallocs = std::collections::BTreeSet::new();
229+
let mut reallocs = ::std::collections::BTreeSet::new();
230230
let mut accounts =
231231
IdlResizeAccount::try_accounts(program_id, &mut accounts, &[], &mut bumps, &mut reallocs)?;
232232
__idl_resize_account(program_id, &mut accounts, data_len)?;
233233
accounts.exit(program_id)?;
234234
},
235235
anchor_lang::idl::IdlInstruction::Close => {
236236
let mut bumps = <IdlCloseAccount as anchor_lang::Bumps>::Bumps::default();
237-
let mut reallocs = std::collections::BTreeSet::new();
237+
let mut reallocs = ::std::collections::BTreeSet::new();
238238
let mut accounts =
239239
IdlCloseAccount::try_accounts(program_id, &mut accounts, &[], &mut bumps, &mut reallocs)?;
240240
__idl_close_account(program_id, &mut accounts)?;
241241
accounts.exit(program_id)?;
242242
},
243243
anchor_lang::idl::IdlInstruction::CreateBuffer => {
244244
let mut bumps = <IdlCreateBuffer as anchor_lang::Bumps>::Bumps::default();
245-
let mut reallocs = std::collections::BTreeSet::new();
245+
let mut reallocs = ::std::collections::BTreeSet::new();
246246
let mut accounts =
247247
IdlCreateBuffer::try_accounts(program_id, &mut accounts, &[], &mut bumps, &mut reallocs)?;
248248
__idl_create_buffer(program_id, &mut accounts)?;
249249
accounts.exit(program_id)?;
250250
},
251251
anchor_lang::idl::IdlInstruction::Write { data } => {
252252
let mut bumps = <IdlAccounts as anchor_lang::Bumps>::Bumps::default();
253-
let mut reallocs = std::collections::BTreeSet::new();
253+
let mut reallocs = ::std::collections::BTreeSet::new();
254254
let mut accounts =
255255
IdlAccounts::try_accounts(program_id, &mut accounts, &[], &mut bumps, &mut reallocs)?;
256256
__idl_write(program_id, &mut accounts, data)?;
257257
accounts.exit(program_id)?;
258258
},
259259
anchor_lang::idl::IdlInstruction::SetAuthority { new_authority } => {
260260
let mut bumps = <IdlAccounts as anchor_lang::Bumps>::Bumps::default();
261-
let mut reallocs = std::collections::BTreeSet::new();
261+
let mut reallocs = ::std::collections::BTreeSet::new();
262262
let mut accounts =
263263
IdlAccounts::try_accounts(program_id, &mut accounts, &[], &mut bumps, &mut reallocs)?;
264264
__idl_set_authority(program_id, &mut accounts, new_authority)?;
265265
accounts.exit(program_id)?;
266266
},
267267
anchor_lang::idl::IdlInstruction::SetBuffer => {
268268
let mut bumps = <IdlSetBuffer as anchor_lang::Bumps>::Bumps::default();
269-
let mut reallocs = std::collections::BTreeSet::new();
269+
let mut reallocs = ::std::collections::BTreeSet::new();
270270
let mut accounts =
271271
IdlSetBuffer::try_accounts(program_id, &mut accounts, &[], &mut bumps, &mut reallocs)?;
272272
__idl_set_buffer(program_id, &mut accounts)?;

lang/syn/src/codegen/program/idl.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub fn idl_accounts_and_functions() -> proc_macro2::TokenStream {
107107
}
108108

109109

110-
use std::cell::{Ref, RefMut};
110+
use ::std::cell::{Ref, RefMut};
111111

112112
pub trait IdlTrailingData<'info> {
113113
fn trailing_data(self) -> Ref<'info, [u8]>;
@@ -147,7 +147,7 @@ pub fn idl_accounts_and_functions() -> proc_macro2::TokenStream {
147147
let owner = accounts.program.key;
148148
let to = Pubkey::create_with_seed(&base, seed, owner).unwrap();
149149
// Space: account discriminator || authority pubkey || vec len || vec data
150-
let space = std::cmp::min(
150+
let space = ::std::cmp::min(
151151
IdlAccount::DISCRIMINATOR.len() + 32 + 4 + data_len as usize,
152152
10_000
153153
);
@@ -189,7 +189,7 @@ pub fn idl_accounts_and_functions() -> proc_macro2::TokenStream {
189189
// Store the new account data.
190190
let mut data = accounts.to.try_borrow_mut_data()?;
191191
let dst: &mut [u8] = &mut data;
192-
let mut cursor = std::io::Cursor::new(dst);
192+
let mut cursor = ::std::io::Cursor::new(dst);
193193
idl_account.try_serialize(&mut cursor)?;
194194

195195
Ok(())
@@ -213,7 +213,7 @@ pub fn idl_accounts_and_functions() -> proc_macro2::TokenStream {
213213
}
214214

215215
let idl_ref = AsRef::<AccountInfo>::as_ref(&accounts.idl);
216-
let new_account_space = idl_ref.data_len().checked_add(std::cmp::min(
216+
let new_account_space = idl_ref.data_len().checked_add(::std::cmp::min(
217217
data_len
218218
.checked_sub(idl_ref.data_len())
219219
.expect("data_len should always be >= the current account space"),

lang/syn/src/idl/accounts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ pub fn gen_idl_build_impl_accounts_struct(accounts: &AccountsStruct) -> TokenStr
144144
quote! {
145145
impl #impl_generics #ident #ty_generics #where_clause {
146146
pub fn __anchor_private_gen_idl_accounts(
147-
accounts: &mut std::collections::BTreeMap<String, #idl::IdlAccount>,
148-
types: &mut std::collections::BTreeMap<String, #idl::IdlTypeDef>,
147+
accounts: &mut ::std::collections::BTreeMap<String, #idl::IdlAccount>,
148+
types: &mut ::std::collections::BTreeMap<String, #idl::IdlTypeDef>,
149149
) -> Vec<#idl::IdlInstructionAccountItem> {
150150
#(
151151
if let Some(ty) = <#defined>::create_type() {

lang/syn/src/idl/defined.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ fn impl_idl_build(
5959
}
6060

6161
fn insert_types(
62-
types: &mut std::collections::BTreeMap<String, #idl::IdlTypeDef>
62+
types: &mut ::std::collections::BTreeMap<String, #idl::IdlTypeDef>
6363
) {
6464
#insert_defined
6565
}

0 commit comments

Comments
 (0)