rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.27k stars 1.61k forks source link

panicked: mismatched kinds in substitution #17711

Closed SiyahKara closed 2 months ago

SiyahKara commented 3 months ago

rust-analyzer version: 0.4.2048

rustc version: 1.78.0

editor or extension: VS.-Code

im recieving the following error when i try to use the anchor_lang create:

thread 'Worker' panicked at C:\Users\runneradmin.cargo\registry\src\index.crates.io-6f17d22bba15001f\chalk-ir-0.98.0\src\fold\subst.rs:59:22: mismatched kinds in substitution stack backtrace: 0: std::panicking::begin_panic 1: chalkir::fold::subst::::<impl chalk_ir::fold::FallibleTypeFolder for chalk_ir::fold::subst::Subst>::try_fold_free_var_ty 2: chalk_ir::fold::TypeSuperFoldable::super_fold_with 3: chalkir::::<impl chalk_ir::fold::TypeFoldable for chalk_ir::WhereClause>::try_fold_with 4: chalk_ir::fold::binder_impls::<impl chalk_ir::fold::TypeFoldable for chalk_ir::Binders>::try_fold_with 5: chalk_ir::Binders::substitute 6: hir_ty::infer::expr::::infer_assignee_expr 7: hir_ty::infer::expr::::infer_assignee_expr 8: hir_ty::infer::coerce::auto_deref_adjust_steps 9: hir_ty::infer::coerce::auto_deref_adjust_steps 10: hir_ty::infer::coerce::auto_deref_adjust_steps 11: hir_ty::infer::expr::::infer_assignee_expr 12: hir_ty::infer::coerce::auto_deref_adjust_steps 13: hir_ty::infer::coerce::auto_deref_adjust_steps 14: hir_ty::infer::expr::::infer_assignee_expr 15: hir_ty::infer::coerce::auto_deref_adjust_steps 16: hir_ty::infer::coerce::auto_deref_adjust_steps 17: hir_ty::infer::infer_query 18: salsa::Cycle::catch 19: salsa::derived::slot::Slot::read 20: salsa::derived::slot::Slot::read 21: <salsa::derived::DerivedStorage as salsa::plumbing::QueryStorageOps>::fetch 22: ::infer 23: hir::semantics::SemanticsImpl::analyze_impl 24: ide_db::active_parameter::generic_def_for_node 25: ide::inlay_hints::generic_param::hints 26: ide::inlay_hints::hints 27: std::panicking::try 28: rust_analyzer::handlers::request::handle_inlay_hints 29: std::panicking::try 30: core::ops::function::FnOnce::call_once{{vtable.shim}} note: Some details are omitted, run with RUST_BACKTRACE=full for a verbose backtrace. [Error - 8:41:25 PM] Request textDocument/inlayHint failed. Message: request handler panicked: mismatched kinds in substitution Code: -32603

code snippet to reproduce:

    let payer = Keypair::new();
    let client = Client::new(Cluster::Mainnet, Rc::new(payer));

    // Create program
    let program = client.program(alphazero_chain_swap::ID).unwrap();
    let instructions: Vec<Instruction> = program.request()
        .accounts(accounts)
        .args(args)
        .instructions()
        .unwrap();

The Error happens when i try after the args(args) parameter to use .instructions()

SupaGoku commented 3 months ago

Getting exactly the same issue. If I comment out the .instructions(), the error goes away.

Veykril commented 3 months ago

Note that the snippets is useless to us without the other relevant code for it

SupaGoku commented 3 months ago

Here's a minimum example:

[package]
name = "fail"
version = "0.1.0"
edition = "2021"

[dependencies]
anchor-client = { version = "0.29.0", features = ["async"] }
use std::{ str::FromStr, sync::Arc };

use anchor_client::{ solana_sdk::{ pubkey::Pubkey, signature::Keypair }, Client, Cluster };

fn main() {
  let program_pubkey = Pubkey::from_str("FooBar").unwrap();
  let http_url = "FooBar".into();
  let ws_url = "FooBar".into();
  let cluster = Cluster::Custom(http_url, ws_url);

  let payer = Keypair::new();

  let client = Client::new(cluster, Arc::new(payer));
  let program = client.program(program_pubkey).unwrap();

  let instructions = program.request().accounts(accounts).args(args).instruction();
}

accounts and args are undefined, which gives an error, but that doesn't matter. The panic still happens in rust-analyzer console/output.

image

SupaGoku commented 3 months ago

I can confirm that the issue started with version 0.3.2029.

@SiyahKara Install version 0.3.2020 for a temporary workaround.

ShoyuVanilla commented 3 months ago

Here's a minimum example:

Where can I get accounts and args in the last line? And the last method is instructions(), maybe?

SupaGoku commented 3 months ago

Here you go:

[package]
name = "fail"
version = "0.1.0"
edition = "2021"

[dependencies]
anchor-client = { version = "0.29.0", features = ["async"] }
raydium-amm-v3 = { git = "https://github.com/raydium-io/raydium-clmm.git" }
use std::{ str::FromStr, sync::Arc };

use anchor_client::{ solana_sdk::{ instruction::AccountMeta, pubkey::Pubkey, signature::Keypair }, Client, Cluster };

fn main() {
  let program_pubkey = Pubkey::from_str("FooBar").unwrap();
  let http_url = "FooBar".into();
  let ws_url = "FooBar".into();
  let cluster = Cluster::Custom(http_url, ws_url);

  let payer = Keypair::new();

  let client = Client::new(cluster, Arc::new(payer));
  let program = client.program(program_pubkey).unwrap();

  let accounts = vec![AccountMeta {
    pubkey: Pubkey::from_str("FooBar").unwrap(),
    is_signer: false,
    is_writable: false,
  }];

  let args = raydium_amm_v3::instruction::Swap {
    amount: 1,
    other_amount_threshold: 1,
    sqrt_price_limit_x64: 1,
    is_base_input: true,
  };

  let instructions = program.request().accounts(accounts).args(args).instructions();
}
ShoyuVanilla commented 3 months ago

Thanks! I'll try with your example code

ShoyuVanilla commented 2 months ago

Good news: I just made an minimal, reproducible example;

use core::ops::Deref;

struct Struct<'a, T>(&'a T)

trait Trait {}

impl<'a, T: Deref<Target = impl Trait>> Struct<'a, T> {
    fn foo(&self) {
    }

    fn bar(&self) {
        let _ = self.foo();
    }
}

extracted from https://github.com/coral-xyz/anchor/blob/2a7d9439360c209542ecad9630a40605de857706/client/src/lib.rs#L515

and I think that I can fix this soon 😄

SiyahKara commented 2 months ago

works like a charm thank you guys you are amazing