Rust analyzer missinterprets `cfg_attr`?

I am reconfiguring my neovim setup, and noticed strange behaviour of RA.

I have code like this:

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn instantiate(
    deps: DepsMut,
    _env: Env,
    _info: MessageInfo,
    msg: InstantiateMsg,
) -> StdResult<Response> {
    set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
    let cfg = AdminList {
        admins: map_validate(deps.api, &msg.admins)?,
        mutable: msg.mutable,
    };
    ADMIN_LIST.save(deps.storage, &cfg)?;
    Ok(Response::default())
}

Full code: cw-plus/contract.rs at main · CosmWasm/cw-plus · GitHub

The implementation doesn't matter here, the important is:

#[cfg_attr(not(feature = "library"), entry_point)]

The entry_point macro generates a bridge for wasm which at the end calls this instantiate function.

I configured RA to build with allFeatures = true on safe to have more diags. The problem is, that because of that, code is built with the library feature, which causes the attr not to be attached. It is correct behaviour. However, the instantiate function is in the final binary.

However! When I introduce any problem (like change _env to env, or even msg to sg to introduce an error) directly in this function, diagnostics are not shown! They are working for any non-entry point function. Removing allFeatures solves the problem. But why RA things this function is not compiled in?

I am leading to create an issue in RA git, but first I want to ensure I don't miss something obvious.

I also double-checked - introducing error (msg -> sg) causes build to fail:

$ cargo build --features library
   Compiling cw1-whitelist v0.13.2 (/home/hashed/confio/git/cosmwasm-plus/contracts/cw1-whitelist)
error[E0425]: cannot find value `msg` in this scope
  --> contracts/cw1-whitelist/src/contract.rs:31:41
   |
31 |         admins: map_validate(deps.api, &msg.admins)?,
   |                                         ^^^ help: a local variable with a similar name exists: `sg`

error[E0425]: cannot find value `msg` in this scope
  --> contracts/cw1-whitelist/src/contract.rs:32:18
   |
32 |         mutable: msg.mutable,
   |                  ^^^ help: a local variable with a similar name exists: `sg`

For more information about this error, try `rustc --explain E0425`.
error: could not compile `cw1-whitelist` due to 2 previous errors

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.