File tree Expand file tree Collapse file tree 4 files changed +25
-5
lines changed
Expand file tree Collapse file tree 4 files changed +25
-5
lines changed Original file line number Diff line number Diff line change @@ -133,7 +133,11 @@ pub fn account(
133133 #[ automatically_derived]
134134 impl #impl_gen anchor_lang:: Owner for #account_name #type_gen #where_clause {
135135 fn owner( ) -> Pubkey {
136- crate :: ID
136+ // In a doctest the ID will be in the current scope, not the crate root
137+ #[ cfg( not( doctest) ) ]
138+ { crate :: ID }
139+ #[ cfg( doctest) ]
140+ { ID }
137141 }
138142 }
139143 }
Original file line number Diff line number Diff line change @@ -174,7 +174,11 @@ pub fn emit_cpi(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
174174 . collect( ) ;
175175
176176 let ix = anchor_lang:: solana_program:: instruction:: Instruction :: new_with_bytes(
177- crate :: ID ,
177+ // In a doctest the ID will be in the current scope, not the crate root
178+ #[ cfg( not( doctest) ) ]
179+ { crate :: ID } ,
180+ #[ cfg( doctest) ]
181+ { ID } ,
178182 & ix_data,
179183 vec![
180184 anchor_lang:: solana_program:: instruction:: AccountMeta :: new_readonly(
Original file line number Diff line number Diff line change @@ -21,8 +21,16 @@ pub fn generate(accs: &AccountsStruct) -> proc_macro2::TokenStream {
2121 let impl_exit = exit:: generate ( accs) ;
2222 let bumps_struct = bumps:: generate ( accs) ;
2323
24- let __client_accounts_mod = __client_accounts:: generate ( accs, quote ! ( crate :: ID ) ) ;
25- let __cpi_client_accounts_mod = __cpi_client_accounts:: generate ( accs, quote ! ( crate :: ID ) ) ;
24+ let program_id = quote ! {
25+ // In a doctest the ID will be in the current scope, not the crate root
26+ #[ cfg( not( doctest) ) ]
27+ { crate :: ID }
28+ #[ cfg( doctest) ]
29+ { ID }
30+ } ;
31+
32+ let __client_accounts_mod = __client_accounts:: generate ( accs, program_id. clone ( ) ) ;
33+ let __cpi_client_accounts_mod = __cpi_client_accounts:: generate ( accs, program_id) ;
2634
2735 let ret = quote ! {
2836 #impl_try_accounts
Original file line number Diff line number Diff line change @@ -29,7 +29,11 @@ pub fn idl_accounts_and_functions() -> proc_macro2::TokenStream {
2929 // works. Namespaces are the root of most of the problem.
3030 impl anchor_lang:: Owner for IdlAccount {
3131 fn owner( ) -> Pubkey {
32- crate :: ID
32+ // In a doctest the ID will be in the current scope, not the crate root
33+ #[ cfg( not( doctest) ) ]
34+ { crate :: ID }
35+ #[ cfg( doctest) ]
36+ { ID }
3337 }
3438 }
3539
You can’t perform that action at this time.
0 commit comments