From 04985802587c693091f836e0083e4412148c0ca6 Mon Sep 17 00:00:00 2001 From: acheron <98934430+acheroncrypto@users.noreply.github.com> Date: Sun, 25 Aug 2024 23:52:29 +0200 Subject: [PATCH] idl: Fix panicking on tests (#3197) --- CHANGELOG.md | 1 + lang/syn/src/idl/defined.rs | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd078799f8..35a7631c31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -60,6 +60,7 @@ The minor version will be incremented upon a breaking change and the patch versi - lang: Fix compilation warnings due to unused deprecated program id macros ([#3170](https://github.com/coral-xyz/anchor/pull/3170)). - ts: Remove `crypto-hash` dependency ([#3171](https://github.com/coral-xyz/anchor/pull/3171)). - ts: Improve error message of unsupported `view` method ([#3177](https://github.com/coral-xyz/anchor/pull/3177)). +- idl: Fix panicking on tests ([#3197](https://github.com/coral-xyz/anchor/pull/3197)). ### Breaking diff --git a/lang/syn/src/idl/defined.rs b/lang/syn/src/idl/defined.rs index 3820d18b21..1b37740ddd 100644 --- a/lang/syn/src/idl/defined.rs +++ b/lang/syn/src/idl/defined.rs @@ -497,9 +497,7 @@ pub fn gen_idl_type( use quote::ToTokens; let source_path = proc_macro2::Span::call_site().source_file().path(); - let lib_path = find_path("lib.rs", &source_path).expect("lib.rs should exist"); - - if let Ok(ctx) = CrateContext::parse(lib_path) { + if let Ok(Ok(ctx)) = find_path("lib.rs", &source_path).map(CrateContext::parse) { let name = path.path.segments.last().unwrap().ident.to_string(); let alias = ctx.type_aliases().find(|ty| ty.ident == name); if let Some(alias) = alias {