diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 38f40c3d36..1da9145383 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -1556,8 +1556,14 @@ pub type Files = Vec<(PathBuf, String)>; /// /// # Example /// -/// ```ignore -/// crate_files(vec![("programs/my_program/src/lib.rs".into(), "// Content".into())])?; +/// ```rust,no_run +/// # use anchor_cli::create_files; +/// # use std::path::PathBuf; +/// # fn main() -> anyhow::Result<()> { +/// let files = vec![(PathBuf::from("programs/my_program/src/lib.rs"), "// Content".to_string())]; +/// create_files(&files)?; +/// # Ok(()) +/// # } /// ``` pub fn create_files(files: &Files) -> Result<()> { for (path, content) in files { @@ -1586,8 +1592,14 @@ pub fn create_files(files: &Files) -> Result<()> { /// /// # Example /// -/// ```ignore -/// override_or_create_files(vec![("programs/my_program/src/lib.rs".into(), "// Content".into())])?; +/// ```rust,no_run +/// # use anchor_cli::override_or_create_files; +/// # use std::path::PathBuf; +/// # fn main() -> anyhow::Result<()> { +/// let files = vec![(PathBuf::from("test.rs"), "// Content".to_string())]; +/// override_or_create_files(&files)?; +/// # Ok(()) +/// # } /// ``` pub fn override_or_create_files(files: &Files) -> Result<()> { for (path, content) in files { diff --git a/idl/src/build.rs b/idl/src/build.rs index 97175ff711..bc4d3bdc02 100644 --- a/idl/src/build.rs +++ b/idl/src/build.rs @@ -47,8 +47,14 @@ pub trait IdlBuild { /// /// # Example /// -/// ```ignore +/// ```rust,no_run +/// # use std::path::PathBuf; +/// # use anchor_lang_idl::build::IdlBuilder; +/// # fn main() -> Result<(), Box> { +/// let path = PathBuf::from("programs/my_program"); /// let idl = IdlBuilder::new().program_path(path).skip_lint(true).build()?; +/// # Ok(()) +/// # } /// ``` #[derive(Default)] pub struct IdlBuilder { diff --git a/lang/attribute/access-control/src/lib.rs b/lang/attribute/access-control/src/lib.rs index 6d31da0cc9..2807e470ca 100644 --- a/lang/attribute/access-control/src/lib.rs +++ b/lang/attribute/access-control/src/lib.rs @@ -20,20 +20,29 @@ use syn::parse_macro_input; /// pub fn create(ctx: Context, bump_seed: u8) -> Result<()> { /// let my_account = &mut ctx.accounts.my_account; /// my_account.bump_seed = bump_seed; +/// Ok(()) /// } /// } /// /// #[derive(Accounts)] -/// pub struct Create { -/// #[account(init)] +/// pub struct Create<'info> { +/// #[account(init, payer = payer, space = 8 + 1)] /// my_account: Account<'info, MyAccount>, +/// #[account(mut)] +/// payer: Signer<'info>, +/// system_program: Program<'info, System>, /// } /// -/// impl Create { +/// #[account] +/// pub struct MyAccount { +/// bump_seed: u8, +/// } +/// +/// impl Create<'_> { /// pub fn accounts(ctx: &Context, bump_seed: u8) -> Result<()> { /// let seeds = &[ctx.accounts.my_account.to_account_info().key.as_ref(), &[bump_seed]]; /// Pubkey::create_program_address(seeds, ctx.program_id) -/// .map_err(|_| ErrorCode::InvalidNonce)?; +/// .map_err(|_| error!(ErrorCode::InvalidNonce))?; /// Ok(()) /// } /// } diff --git a/lang/attribute/account/src/lib.rs b/lang/attribute/account/src/lib.rs index bac320bf2d..9478f6fb9b 100644 --- a/lang/attribute/account/src/lib.rs +++ b/lang/attribute/account/src/lib.rs @@ -65,7 +65,7 @@ mod lazy; /// To enable zero-copy-deserialization, one can pass in the `zero_copy` /// argument to the macro as follows: /// -/// ```ignore +/// ```rust,ignore /// #[account(zero_copy)] /// ``` /// @@ -406,7 +406,7 @@ pub fn derive_zero_copy_accessor(item: proc_macro::TokenStream) -> proc_macro::T /// /// `#[zero_copy]` is just a convenient alias for /// -/// ```ignore +/// ```rust,ignore /// #[derive(Copy, Clone)] /// #[derive(bytemuck::Zeroable)] /// #[derive(bytemuck::Pod)] diff --git a/lang/attribute/error/src/lib.rs b/lang/attribute/error/src/lib.rs index 3f403de2ef..ad4cd167bb 100644 --- a/lang/attribute/error/src/lib.rs +++ b/lang/attribute/error/src/lib.rs @@ -66,7 +66,9 @@ pub fn error_code( /// Generates an [`Error::AnchorError`](../../anchor_lang/error/enum.Error.html) that includes file and line information. /// /// # Example -/// ```rust,ignore +/// ```ignore +/// use anchor_lang::prelude::*; +/// /// #[program] /// mod errors { /// use super::*; @@ -75,6 +77,9 @@ pub fn error_code( /// } /// } /// +/// #[derive(Accounts)] +/// pub struct Example {} +/// /// #[error_code] /// pub enum MyError { /// #[msg("This is an error message clients will automatically display")] diff --git a/lang/attribute/event/src/lib.rs b/lang/attribute/event/src/lib.rs index ba5085998f..3ecda48d5e 100644 --- a/lang/attribute/event/src/lib.rs +++ b/lang/attribute/event/src/lib.rs @@ -200,6 +200,8 @@ pub fn emit_cpi(input: proc_macro::TokenStream) -> proc_macro::TokenStream { /// # Example /// /// ```ignore +/// use anchor_lang::prelude::*; +/// /// #[event_cpi] /// #[derive(Accounts)] /// pub struct MyInstruction<'info> { @@ -210,6 +212,8 @@ pub fn emit_cpi(input: proc_macro::TokenStream) -> proc_macro::TokenStream { /// The code above will be expanded to: /// /// ```ignore +/// use anchor_lang::prelude::*; +/// /// #[derive(Accounts)] /// pub struct MyInstruction<'info> { /// pub signer: Signer<'info>, diff --git a/lang/derive/space/src/lib.rs b/lang/derive/space/src/lib.rs index f0832e1f0e..fc6c5323dc 100644 --- a/lang/derive/space/src/lib.rs +++ b/lang/derive/space/src/lib.rs @@ -16,6 +16,8 @@ use syn::{ /// /// # Example /// ```ignore +/// use anchor_lang::prelude::*; +/// /// #[account] /// #[derive(InitSpace)] /// pub struct ExampleAccount { diff --git a/lang/src/accounts/boxed.rs b/lang/src/accounts/boxed.rs index 5fea704ad1..2c0fdaa86d 100644 --- a/lang/src/accounts/boxed.rs +++ b/lang/src/accounts/boxed.rs @@ -8,7 +8,7 @@ //! # Example //! ```ignore //! #[derive(Accounts)] -//! pub struct Example { +//! pub struct Example<'info> { //! pub my_acc: Box> //! } //! ``` diff --git a/lang/src/accounts/option.rs b/lang/src/accounts/option.rs index cf6428dd9d..f9f491fbc1 100644 --- a/lang/src/accounts/option.rs +++ b/lang/src/accounts/option.rs @@ -3,7 +3,7 @@ //! # Example //! ```ignore //! #[derive(Accounts)] -//! pub struct Example { +//! pub struct Example<'info> { //! pub my_acc: Option> //! } //! ``` diff --git a/lang/src/accounts/signer.rs b/lang/src/accounts/signer.rs index 39a216305a..0b96015e80 100644 --- a/lang/src/accounts/signer.rs +++ b/lang/src/accounts/signer.rs @@ -25,7 +25,7 @@ use std::ops::Deref; /// /// #[derive(Accounts)] /// pub struct Example<'info> { -/// #[account(init, payer = payer)] +/// #[account(init, payer = payer, space = 8 + 8)] /// pub my_acc: Account<'info, MyData>, /// #[account(mut)] /// pub payer: Signer<'info>, diff --git a/lang/src/lib.rs b/lang/src/lib.rs index c5599f60ed..a070ca553f 100644 --- a/lang/src/lib.rs +++ b/lang/src/lib.rs @@ -832,6 +832,9 @@ macro_rules! require_gte { /// pub enum MyError { /// SomeError /// } +/// +/// #[derive(Accounts)] +/// pub struct Example {} /// ``` #[macro_export] macro_rules! err {