rust-lang / rust-lang/rust-analyzer

Getting no diagnostics inside tests

Open
#12,822 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics C-bug
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

I'm having no diagnostics on a specific project. I suspect it has to do with the custom macros for the tests in this project.

If you go to this test for example: https://github.com/wireapp/core-crypto/blob/develop/crypto/src/external_commit.rs#L235
And change any line to call an invalid function: for ex calling unwrap on a Vec, there'll be no diagnostic for it.

I use neovim, but I could reproduce it with vscode as well. I've got additional errors with vscode that I didn't with neovim. It crashed once for example when it tried to auto complete. In neovim it doesn't crash but there is no auto complete in those tests.

rust-analyzer version: rust-analyzer 0.0.0 (897a7ec4b 2022-07-17)

rustc version: rustc 1.62.1 (e092d0b6b 2022-07-16)

relevant settings: the settings I use can be found here: https://github.com/augustocdias/dotfiles/blob/main/.config/nvim/lua/lsp-config.lua#L158

analysis-stats:

[ERROR project_model::workspace] cyclic deps: mls_crypto_provider(CrateId(177)) -> core_crypto_keystore(CrateId(79)), alternative path: core_crypto_keystore(CrateId(79)) -> mls_crypto_provider(CrateId(177))
[ERROR project_model::workspace] cyclic deps: mls_crypto_provider(CrateId(177)) -> mls_crypto_provider(CrateId(177)), alternative path: mls_crypto_provider(CrateId(177))
Database loaded:     1.16s (metadata 466.79ms; build 382.07ms)
  crates: 18, mods: 128, decls: 1056, fns: 833
Item Collection:     13.65s
  exprs: 21943, ??ty: 201 (0%), ?ty: 130 (0%), !ty: 8                                                                                                     
Inference:           8.24s
Total:               21.90s

Output > Rust Analyzer Language Server Trace (this is from VSCode, I'm not sure where to get the logs for NeoVim)

[ERROR project_model::workspace] cyclic deps: mls_crypto_provider(CrateId(184)) -> core_crypto_keystore(CrateId(80)), alternative path: core_crypto_keystore(CrateId(80)) -> mls_crypto_provider(CrateId(184))
[ERROR project_model::workspace] cyclic deps: mls_crypto_provider(CrateId(184)) -> mls_crypto_provider(CrateId(184)), alternative path: mls_crypto_provider(CrateId(184))
[ERROR project_model::workspace] cyclic deps: mls_crypto_provider(CrateId(184)) -> core_crypto_keystore(CrateId(80)), alternative path: core_crypto_keystore(CrateId(80)) -> mls_crypto_provider(CrateId(184))
[ERROR project_model::workspace] cyclic deps: mls_crypto_provider(CrateId(184)) -> mls_crypto_provider(CrateId(184)), alternative path: mls_crypto_provider(CrateId(184))
[ERROR project_model::workspace] cyclic deps: mls_crypto_provider(CrateId(184)) -> core_crypto_keystore(CrateId(80)), alternative path: core_crypto_keystore(CrateId(80)) -> mls_crypto_provider(CrateId(184))
[ERROR project_model::workspace] cyclic deps: mls_crypto_provider(CrateId(184)) -> mls_crypto_provider(CrateId(184)), alternative path: mls_crypto_provider(CrateId(184))
[ERROR project_model::workspace] cyclic deps: mls_crypto_provider(CrateId(184)) -> core_crypto_keystore(CrateId(80)), alternative path: core_crypto_keystore(CrateId(80)) -> mls_crypto_provider(CrateId(184))
[ERROR project_model::workspace] cyclic deps: mls_crypto_provider(CrateId(184)) -> mls_crypto_provider(CrateId(184)), alternative path: mls_crypto_provider(CrateId(184))
Panic context:
> 
version: 0.3.1131-standalone (897a7ec4b 2022-07-17)
request: textDocument/completion CompletionParams {
    text_document_position: TextDocumentPositionParams {
        text_document: TextDocumentIdentifier {
            uri: Url {
                scheme: "file",
                cannot_be_a_base: false,
                username: "",
                password: None,
                host: None,
                port: None,
                path: "/Users/augusto/projects/core-crypto/crypto/src/conversation.rs",
                query: None,
                fragment: None,
            },
        },
        position: Position {
            line: 1098,
            character: 45,
        },
    },
    work_done_progress_params: WorkDoneProgressParams {
        work_done_token: None,
    },
    partial_result_params: PartialResultParams {
        partial_result_token: None,
    },
    context: Some(
        CompletionContext {
            trigger_kind: TriggerCharacter,
            trigger_character: Some(
                ".",
            ),
        },
    ),
}

thread 'Worker' panicked at '

Failed to lookup FN@0..2827 in this Semantics.
Make sure to use only query nodes, derived from this instance of Semantics.
root node:   MACRO_ITEMS@0..3408
known nodes: MACRO_ITEMS@0..3408, MACRO_STMTS@0..232, SOURCE_FILE@0..44419, MACRO_ITEMS@0..3117, MACRO_ITEMS@0..3002, MACRO_ITEMS@0..2858

', crates/hir/src/semantics.rs:1186:13
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: hir::semantics::SemanticsImpl::find_file
   3: hir::semantics::Semantics<DB>::original_ast_node
   4: ide_db::imports::insert_use::ImportScope::find_insert_use_container
   5: ide_completion::completions::postfix::complete_postfix
   6: ide_completion::completions
   7: std::panicking::try
   8: rust_analyzer::handlers::handle_completion
   9: std::panicking::try
  10: <F as threadpool::FnBox>::call_box
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[Error - 11:51:22 AM] Request textDocument/completion failed.
  Message: request handler panicked: 

Failed to lookup FN@0..2827 in this Semantics.
Make sure to use only query nodes, derived from this instance of Semantics.
root node:   MACRO_ITEMS@0..3408
known nodes: MACRO_ITEMS@0..3408, MACRO_STMTS@0..232, SOURCE_FILE@0..44419, MACRO_ITEMS@0..3117, MACRO_ITEMS@0..3002, MACRO_ITEMS@0..2858


  Code: -32603 
[ERROR project_model::workspace] cyclic deps: mls_crypto_provider(CrateId(184)) -> core_crypto_keystore(CrateId(80)), alternative path: core_crypto_keystore(CrateId(80)) -> mls_crypto_provider(CrateId(184))
[ERROR project_model::workspace] cyclic deps: mls_crypto_provider(CrateId(184)) -> mls_crypto_provider(CrateId(184)), alternative path: mls_crypto_provider(CrateId(184))
[ERROR project_model::workspace] cyclic deps: mls_crypto_provider(CrateId(184)) -> core_crypto_keystore(CrateId(80)), alternative path: core_crypto_keystore(CrateId(80)) -> mls_crypto_provider(CrateId(184))
[ERROR project_model::workspace] cyclic deps: mls_crypto_provider(CrateId(184)) -> mls_crypto_provider(CrateId(184)), alternative path: mls_crypto_provider(CrateId(184))
Panic context:
> 
version: 0.3.1131-standalone (897a7ec4b 2022-07-17)
request: textDocument/completion CompletionParams {
    text_document_position: TextDocumentPositionParams {
        text_document: TextDocumentIdentifier {
            uri: Url {
                scheme: "file",
                cannot_be_a_base: false,
                username: "",
                password: None,
                host: None,
                port: None,
                path: "/Users/augusto/projects/core-crypto/crypto/src/conversation.rs",
                query: None,
                fragment: None,
            },
        },
        position: Position {
            line: 1098,
            character: 45,
        },
    },
    work_done_progress_params: WorkDoneProgressParams {
        work_done_token: None,
    },
    partial_result_params: PartialResultParams {
        partial_result_token: None,
    },
    context: Some(
        CompletionContext {
            trigger_kind: TriggerCharacter,
            trigger_character: Some(
                ".",
            ),
        },
    ),
}

thread 'Worker' panicked at '

Failed to lookup FN@0..2827 in this Semantics.
Make sure to use only query nodes, derived from this instance of Semantics.
root node:   MACRO_ITEMS@0..3408
known nodes: MACRO_ITEMS@0..3117, MACRO_ITEMS@0..2858, SOURCE_FILE@0..44419, MACRO_ITEMS@0..3002, MACRO_ITEMS@0..3408, MACRO_STMTS@0..232

', crates/hir/src/semantics.rs:1186:13
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: hir::semantics::SemanticsImpl::find_file
   3: hir::semantics::Semantics<DB>::original_ast_node
   4: ide_db::imports::insert_use::ImportScope::find_insert_use_container
   5: ide_completion::completions::postfix::complete_postfix
   6: ide_completion::completions
   7: std::panicking::try
   8: rust_analyzer::handlers::handle_completion
   9: std::panicking::try
  10: <F as threadpool::FnBox>::call_box
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[Error - 11:51:46 AM] Request textDocument/completion failed.
  Message: request handler panicked: 

Failed to lookup FN@0..2827 in this Semantics.
Make sure to use only query nodes, derived from this instance of Semantics.
root node:   MACRO_ITEMS@0..3408
known nodes: MACRO_ITEMS@0..3117, MACRO_ITEMS@0..2858, SOURCE_FILE@0..44419, MACRO_ITEMS@0..3002, MACRO_ITEMS@0..3408, MACRO_STMTS@0..232


  Code: -32603 

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the missing diagnostics at crypto/src/external_commit.rs#L235 in the linked core-crypto project, using the reported custom test macros and cyclic dependency setup. Start with crates/hir/src/semantics.rs:1186 and the ide_completion stack in the panic trace. Done means invalid code in those tests produces diagnostics and completion no longer panics.

Written by the indexing model from the issue text.

Assessment

Tech stack
neovim, rust, vscode
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.