rust-lang / rust-analyzer

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

keeping panic when initialize struct with automatic type inference on associated type in alias declaration #17651

Closed Fancyflame closed 3 weeks ago

Fancyflame commented 1 month ago

rust-analyzer version: 0.4.2043-standalone (8d489e21e 2024-07-20)

rustc version: rustc 1.79.0 (129f3b996 2024-06-10)

editor or extension: VSCode and official rust-analyzer extension

relevant settings: everything is default

repository link (if public, optional): none

description: When I open the following code in VSCode, any action causes Rust Analyzer to panic and restart, and syntax highlighting is severely affected, making it completely unusable.

code snippet to reproduce:

type Alias<T> = T;

trait Trait<T> {
    type Assoc;
}

struct Foo;
struct Bar {
    x: i32,
}

impl Trait<()> for Foo {
    type Assoc = Bar;
}

fn main() {
    Alias::<<Foo as Trait<_>>::Assoc> { x: 10 };
}

ra output:

[Error - 11:00:02] Request textDocument/inlayHint failed.
  Message: request handler panicked: index out of bounds: the len is 1 but the index is 1
  Code: -32603 
Panic context:
> 
version: 0.4.2043-standalone (8d489e21e 2024-07-20)
request: textDocument/inlayHint InlayHintParams {
    work_done_progress_params: WorkDoneProgressParams {
        work_done_token: None,
    },
    text_document: TextDocumentIdentifier {
        uri: Url {
            scheme: "file",
            cannot_be_a_base: false,
            username: "",
            password: None,
            host: None,
            port: None,
            path: "/d%3A/FancyFlame/irisia-gui-new/examples/t.rs",
            query: None,
            fragment: None,
        },
    },
    range: Range {
        start: Position {
            line: 0,
            character: 0,
        },
        end: Position {
            line: 18,
            character: 0,
        },
    },
}

thread 'Worker' panicked at C:\Users\runneradmin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\ena-0.14.3\src\snapshot_vec.rs:199:10:
index out of bounds: the len is 1 but the index is 1
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library\std\src\panicking.rs:652
   1: core::panicking::panic_fmt
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library\core\src\panicking.rs:72
   2: core::panicking::panic_bounds_check
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library\core\src\panicking.rs:275
   3: chalk_solve::infer::InferenceTable<I>::probe_var
   4: <chalk_ir::visit::visitors::FindFreeVarsVisitor<I> as chalk_ir::visit::TypeVisitor<I>>::visit_free_var
   5: chalk_ir::fold::TypeSuperFoldable::super_fold_with
   6: <smallvec::SmallVec<A> as core::iter::traits::collect::Extend<<A as smallvec::Array>::Item>>::extend
   7: chalk_ir::fold::boring_impls::<impl chalk_ir::fold::TypeFoldable<I> for chalk_ir::Substitution<I>>::try_fold_with
   8: chalk_ir::_::<impl chalk_ir::fold::TypeFoldable<I> for chalk_ir::WhereClause<I>>::try_fold_with
   9: chalk_ir::_::<impl chalk_ir::fold::TypeFoldable<I> for chalk_ir::DomainGoal<I>>::try_fold_with
  10: chalk_ir::fold::TypeSuperFoldable::super_fold_with
  11: chalk_solve::infer::canonicalize::<impl chalk_solve::infer::InferenceTable<I>>::canonicalize
  12: hir_ty::infer::unify::InferenceTable::canonicalize_with_free_vars
  13: hir_ty::infer::unify::InferenceTable::register_obligation_in_env
  14: hir_ty::infer::unify::InferenceTable::normalize_projection_ty
  15: hir_ty::traits::normalize_projection_query
  16: <DB as hir_ty::db::HirDatabase>::normalize_projection
  17: hir_ty::infer::InferenceContext::make_lifetime
  18: hir_ty::infer::InferenceContext::make_lifetime
  19: hir_ty::infer::coerce::auto_deref_adjust_steps
  20: hir_ty::infer::coerce::auto_deref_adjust_steps
  21: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_assignee_expr
  22: hir_ty::infer::coerce::auto_deref_adjust_steps
  23: hir_ty::infer::coerce::auto_deref_adjust_steps
  24: hir_ty::infer::infer_query
  25: salsa::Cycle::catch
  26: salsa::derived::slot::Slot<Q>::read
  27: salsa::derived::slot::Slot<Q>::read
  28: <salsa::derived::DerivedStorage<Q> as salsa::plumbing::QueryStorageOps<Q>>::fetch
  29: <DB as hir_ty::db::HirDatabase>::infer
  30: hir::semantics::SemanticsImpl::analyze_impl
  31: ide_db::active_parameter::generic_def_for_node
  32: ide::inlay_hints::generic_param::hints
  33: ide::inlay_hints::hints
  34: ide::inlay_hints::inlay_hints
  35: std::panicking::try
  36: rust_analyzer::handlers::request::handle_inlay_hints
  37: std::panicking::try
  38: core::ops::function::FnOnce::call_once{{vtable.shim}}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[Error - 11:00:02] Request textDocument/inlayHint failed.
  Message: request handler panicked: index out of bounds: the len is 1 but the index is 1
  Code: -32603
marcvanheerden commented 1 month ago

can I try pick up this issue?

Fancyflame commented 1 month ago

@marcvanheerden Sure, just try. :)

lnicola commented 3 weeks ago

I think #17882 fixed the panic here, but we still don't resolve x.