Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1555,9 +1555,12 @@ pub type Files = Vec<(PathBuf, String)>;
/// Create files from the given (path, content) tuple array.
///
/// # Example
///
/// ```ignore
/// crate_files(vec![("programs/my_program/src/lib.rs".into(), "// Content".into())])?;
/// # fn main() -> anyhow::Result<()> {
/// # use std::path::PathBuf;
/// # let files = vec![(PathBuf::from("programs/my_program/src/lib.rs"), "// Content".to_string())];
/// # crate::create_files(&files)?;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be commented out, the doctest will be empty

/// # Ok(())
/// # }
/// ```
pub fn create_files(files: &Files) -> Result<()> {
for (path, content) in files {
Expand Down Expand Up @@ -1586,8 +1589,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
/// # fn main() -> anyhow::Result<()> {
/// # let temp_dir = tempfile::tempdir()?;
/// # let file_path = temp_dir.path().join("lib.rs");
/// # let files = vec![(file_path, "// Content".to_string())];
/// // override_or_create_files(&files)?;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please restore the original line here - no-run can be used to ensure that it compiles without requiring it to run

/// # Ok(())
/// # }
/// ```
pub fn override_or_create_files(files: &Files) -> Result<()> {
for (path, content) in files {
Expand Down
3 changes: 3 additions & 0 deletions client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ impl<C: Deref<Target = impl Signer> + Clone, S: AsSigner> RequestBuilder<'_, C,
/// # Example
///
/// ```ignore
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove all changes like these to tests which are still marked ignore

/// program
/// .request()
/// // Regular accounts
Expand All @@ -585,6 +586,8 @@ impl<C: Deref<Target = impl Signer> + Clone, S: AsSigner> RequestBuilder<'_, C,
/// }])
/// .args(instruction::Initialize { field: 42 })
/// .send()?;
/// # Ok(())
/// # }
/// ```
#[must_use]
pub fn accounts(mut self, accounts: impl ToAccountMetas) -> Self {
Expand Down
8 changes: 7 additions & 1 deletion idl/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn std::error::Error>> {
/// # let path = PathBuf::from("programs/my_program");
/// let idl = IdlBuilder::new().program_path(path).skip_lint(true).build()?;
/// # Ok(())
/// # }
/// ```
#[derive(Default)]
pub struct IdlBuilder {
Expand Down
7 changes: 5 additions & 2 deletions lang/attribute/access-control/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,26 @@ use syn::parse_macro_input;
/// pub fn create(ctx: Context<Create>, bump_seed: u8) -> Result<()> {
/// let my_account = &mut ctx.accounts.my_account;
/// my_account.bump_seed = bump_seed;
// / Ok(()) // This was missing.
/// }
/// }
///
/// #[derive(Accounts)]
/// pub struct Create {
/// pub struct Create <'info> { // <'info> added
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// pub struct Create <'info> { // <'info> added
/// pub struct Create <'info> {

/// #[account(init)]
/// my_account: Account<'info, MyAccount>,
/// }
///
/// impl Create {
/// impl Create <'_> {
/// pub fn accounts(ctx: &Context<Create>, 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)?;
/// Ok(())
/// }
/// }
///
/// # fn main() {}
/// ```
///
/// This example demonstrates a useful pattern. Not only can you use
Expand Down
4 changes: 2 additions & 2 deletions lang/attribute/account/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
/// ```
///
Expand Down Expand Up @@ -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)]
Expand Down
2 changes: 2 additions & 0 deletions lang/attribute/error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ use syn::{parse_macro_input, Expr};
/// #[msg("This is an error message clients will automatically display")]
/// Hello,
/// }
///
/// # fn main() {}
/// ```
///
/// Note that we generate a new `Error` type so that we can return either the
Expand Down
8 changes: 8 additions & 0 deletions lang/attribute/event/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ pub fn event(
/// pub data: u64,
/// pub label: [u8; 5],
/// }
///
/// # fn main() {}
/// ```
#[proc_macro]
pub fn emit(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
Expand Down Expand Up @@ -147,6 +149,8 @@ pub fn emit(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
/// pub struct MyEvent {
/// pub data: u64,
/// }
///
/// # fn main() {}
/// ```
///
/// **NOTE:** This macro requires `ctx` to be in scope.
Expand Down Expand Up @@ -205,6 +209,8 @@ pub fn emit_cpi(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
/// pub struct MyInstruction<'info> {
/// pub signer: Signer<'info>,
/// }
///
/// # fn main() {}
/// ```
///
/// The code above will be expanded to:
Expand All @@ -219,6 +225,8 @@ pub fn emit_cpi(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
/// /// CHECK: Self-CPI will fail if the program is not the current program
/// pub program: AccountInfo<'info>,
/// }
///
/// # fn main() {}
/// ```
///
/// See [`emit_cpi!`](emit_cpi!) for a full example.
Expand Down
4 changes: 4 additions & 0 deletions lang/attribute/program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ pub fn program(
///
/// ```ignore
/// use anchor_client::anchor_lang;
///
/// # fn main() {}
/// ```
///
/// # Example
Expand Down Expand Up @@ -118,6 +120,8 @@ pub fn declare_program(input: proc_macro::TokenStream) -> proc_macro::TokenStrea
/// pub struct MyIx<'info> {
/// pub signer: Signer<'info>,
/// }
///
/// # fn main() {}
/// ```
#[proc_macro_attribute]
pub fn instruction(
Expand Down
2 changes: 2 additions & 0 deletions lang/derive/accounts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ use syn::parse_macro_input;
/// pub struct Initialize<'info> {
/// ...
/// }
///
/// # fn main() {}
/// ```
///
/// # Constraints
Expand Down
2 changes: 2 additions & 0 deletions lang/derive/space/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ use syn::{
/// #[account(init, payer = payer, space = 8 + ExampleAccount::INIT_SPACE)]
/// pub data: Account<'info, ExampleAccount>,
/// }
///
/// # fn main() {}
Copy link
Copy Markdown
Collaborator

@jamie-osec jamie-osec Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no reason to add this if the test is not compiled. Same for many other instances of this pattern

/// ```
#[proc_macro_derive(InitSpace, attributes(max_len))]
pub fn derive_init_space(item: TokenStream) -> TokenStream {
Expand Down
10 changes: 10 additions & 0 deletions lang/src/accounts/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ use std::ops::{Deref, DerefMut};
/// pub authorized: bool
/// }
/// ...
///
/// # fn main() {}
/// ```
///
/// # Using Account with non-anchor programs
Expand Down Expand Up @@ -132,6 +134,8 @@ use std::ops::{Deref, DerefMut};
/// &self.0
/// }
/// }
///
/// # fn main() {}
/// ```
///
/// ## Out of the box wrapper types
Expand Down Expand Up @@ -193,6 +197,8 @@ use std::ops::{Deref, DerefMut};
/// pub program_data: Account<'info, ProgramData>,
/// pub system_program: Program<'info, System>,
/// }
///
/// # fn main() {}
/// ```
///
/// This example solves a problem you may face if your program has admin settings: How do you set the
Expand All @@ -212,6 +218,8 @@ use std::ops::{Deref, DerefMut};
/// pub struct Example {
/// pub my_acc: Account<'info, TokenAccount>
/// }
///
/// # fn main() {}
/// ```
/// to access token accounts and
/// ```ignore
Expand All @@ -221,6 +229,8 @@ use std::ops::{Deref, DerefMut};
/// pub struct Example {
/// pub my_acc: Account<'info, Mint>
/// }
///
/// # fn main() {}
/// ```
/// to access mint accounts.
#[derive(Clone)]
Expand Down
2 changes: 2 additions & 0 deletions lang/src/accounts/account_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ use std::ops::DerefMut;
/// pub bar: AccountLoader<'info, Bar>,
/// pub authority: Signer<'info>,
/// }
///
/// # fn main() {}
/// ```
#[derive(Clone)]
pub struct AccountLoader<'info, T: ZeroCopy + Owner> {
Expand Down
2 changes: 2 additions & 0 deletions lang/src/accounts/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
//! pub struct Example {
//! pub my_acc: Box<Account<'info, MyData>>
//! }
//!
//! # fn main() {}
//! ```

use crate::solana_program::account_info::AccountInfo;
Expand Down
2 changes: 2 additions & 0 deletions lang/src/accounts/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ use std::ops::Deref;
/// pub program_data: Account<'info, ProgramData>,
/// pub authority: Signer<'info>,
/// }
///
/// # fn main() {}
/// ```
/// The given program has a function with which the upgrade authority can set admin settings.
///
Expand Down
6 changes: 6 additions & 0 deletions lang/src/accounts/interface_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ use std::ops::{Deref, DerefMut};
/// pub authorized: bool
/// }
/// ...
///
/// fn main() {}
/// ```
///
/// # Using InterfaceAccount with non-anchor programs
Expand Down Expand Up @@ -146,6 +148,8 @@ use std::ops::{Deref, DerefMut};
/// pub struct Example {
/// pub my_acc: InterfaceAccount<'info, TokenAccount>
/// }
///
/// # fn main() {}
/// ```
/// to access token accounts and
/// ```ignore
Expand All @@ -155,6 +159,8 @@ use std::ops::{Deref, DerefMut};
/// pub struct Example {
/// pub my_acc: InterfaceAccount<'info, Mint>
/// }
///
/// # fn main() {}
/// ```
/// to access mint accounts.
#[derive(Clone)]
Expand Down
2 changes: 2 additions & 0 deletions lang/src/accounts/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ pub enum MigrationInner<From, To> {
/// pub my_account: Migration<'info, AccountV1, AccountV2>,
/// pub system_program: Program<'info, System>,
/// }
///
/// # fn main() {}
/// ```
#[derive(Debug)]
pub struct Migration<'info, From, To>
Expand Down
2 changes: 2 additions & 0 deletions lang/src/accounts/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
//! pub struct Example {
//! pub my_acc: Option<Account<'info, MyData>>
//! }
//!
//! # fn main() {}
//! ```

use std::collections::BTreeSet;
Expand Down
2 changes: 2 additions & 0 deletions lang/src/accounts/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ use std::ops::Deref;
/// pub program_data: Account<'info, ProgramData>,
/// pub authority: Signer<'info>,
/// }
///
/// # fn main() {}
/// ```
/// The given program has a function with which the upgrade authority can set admin settings.
///
Expand Down
1 change: 1 addition & 0 deletions lang/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ where
/// pub callee_authority: UncheckedAccount<'info>,
/// pub callee: Program<'info, Callee>,
/// }
/// # fn main() {}
/// ```
pub struct CpiContext<'a, 'b, 'c, 'info, T>
where
Expand Down
2 changes: 2 additions & 0 deletions lang/src/lazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use crate::{AnchorDeserialize, Pubkey};
/// pub struct MyStruct {
/// field: u8,
/// }
///
/// # fn main() {}
/// ```
pub trait Lazy: AnchorDeserialize {
/// Whether the type is a fixed-size type.
Expand Down
2 changes: 2 additions & 0 deletions lang/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,8 @@ macro_rules! require_gte {
/// pub enum MyError {
/// SomeError
/// }
///
/// # fn main() {}
/// ```
#[macro_export]
macro_rules! err {
Expand Down
Loading