From 006917c5124edb5a1afb2cfc7fb1f2c5260b112a Mon Sep 17 00:00:00 2001 From: Ebrahim Eldesoky Date: Mon, 8 Jun 2026 17:16:49 +0300 Subject: [PATCH 1/2] fix(lang): qualify bare error! calls in require macros in their custom-error-code arms, which implicitly required error! to be in scope via the prelude glob import. Qualify these with anchor_lang:: so they resolve without relying on any particular import at the call site. --- lang/src/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lang/src/lib.rs b/lang/src/lib.rs index f1b0123d2c..414c5c6776 100644 --- a/lang/src/lib.rs +++ b/lang/src/lib.rs @@ -771,7 +771,7 @@ macro_rules! require { macro_rules! require_eq { ($value1: expr, $value2: expr, $error_code:expr $(,)?) => { if $value1 != $value2 { - return Err(error!($error_code).with_values(($value1, $value2))); + return Err(anchor_lang::error!($error_code).with_values(($value1, $value2))); } }; ($value1: expr, $value2: expr $(,)?) => { @@ -801,7 +801,7 @@ macro_rules! require_eq { macro_rules! require_neq { ($value1: expr, $value2: expr, $error_code: expr $(,)?) => { if $value1 == $value2 { - return Err(error!($error_code).with_values(($value1, $value2))); + return Err(anchor_lang::error!($error_code).with_values(($value1, $value2))); } }; ($value1: expr, $value2: expr $(,)?) => { @@ -831,7 +831,7 @@ macro_rules! require_neq { macro_rules! require_keys_eq { ($value1: expr, $value2: expr, $error_code:expr $(,)?) => { if $value1 != $value2 { - return Err(error!($error_code).with_pubkeys(($value1, $value2))); + return Err(anchor_lang::error!($error_code).with_pubkeys(($value1, $value2))); } }; ($value1: expr, $value2: expr $(,)?) => { @@ -861,7 +861,7 @@ macro_rules! require_keys_eq { macro_rules! require_keys_neq { ($value1: expr, $value2: expr, $error_code: expr $(,)?) => { if $value1 == $value2 { - return Err(error!($error_code).with_pubkeys(($value1, $value2))); + return Err(anchor_lang::error!($error_code).with_pubkeys(($value1, $value2))); } }; ($value1: expr, $value2: expr $(,)?) => { @@ -893,7 +893,7 @@ macro_rules! require_keys_neq { macro_rules! require_gt { ($value1: expr, $value2: expr, $error_code: expr $(,)?) => { if $value1 <= $value2 { - return Err(error!($error_code).with_values(($value1, $value2))); + return Err(anchor_lang::error!($error_code).with_values(($value1, $value2))); } }; ($value1: expr, $value2: expr $(,)?) => { @@ -921,7 +921,7 @@ macro_rules! require_gt { macro_rules! require_gte { ($value1: expr, $value2: expr, $error_code: expr $(,)?) => { if $value1 < $value2 { - return Err(error!($error_code).with_values(($value1, $value2))); + return Err(anchor_lang::error!($error_code).with_values(($value1, $value2))); } }; ($value1: expr, $value2: expr $(,)?) => { From 7c86c5aa85d2c38efb5240e4237afcaafe6ee904 Mon Sep 17 00:00:00 2001 From: Ebrahim Eldesoky Date: Tue, 9 Jun 2026 13:22:41 +0300 Subject: [PATCH 2/2] docs: add changelog entry for error! macro qualification --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 507bbebd08..965265ddcb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ The minor version will be incremented upon a breaking change and the patch versi ### Fixes - lang: Shorten invariant lifetimes during `Context` creation ([#4363](https://github.com/solana-foundation/anchor/pull/4363)). +- lang: Qualify bare `error!` calls in require macros so they don't depend on global prelude imports ([#4639](https://github.com/otter-sec/anchor/pull/4639)). - ts: Guard recursive IDL layouts against stack overflows while preserving supported recursive types ([#4604](https://github.com/solana-foundation/anchor/pull/4604)). - idl: Bump version to 0.1.3 ([#4453](https://github.com/solana-foundation/anchor/pull/4453)). - lang: Migrate `anchor-syn` from syn 1.x to syn 2.0, allowing use of modern Rust syntax ([#4523](https://github.com/solana-foundation/anchor/issues/4523)).