rust-lang / rust-lang/rust-analyzer

r-a fails to parse `core` due to `const` closure

Open
#23,006 14 comments 0 reactions 1 assignee View on GitHub

@saberoueslati is already working on this.

Since Aug 11, 2026.

A-parser C-bug E-has-instructions E-medium good first issue
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

rust-analyzer version: (eg. output of "rust-analyzer: Show RA Version" command, accessible in VSCode via Ctrl/⌘+Shift+P)

rustc version: master (8ee66925e49c8ea918c6e0bdeb3142f602d04226) + custom edits to reveal hidden issue

editor or extension: VS Code

relevant settings: N/A

repository link (if public, optional): N/A

code snippet to reproduce: N/A

Here is my custom edit to parse_or_expand:

pub fn parse_or_expand(self, db: &dyn SourceDatabase) -> SyntaxNode {
    match self {
        HirFileId::FileId(file_id) => {
            let parse = file_id.parse(db);
            let text = db.file_text(file_id.file_id(db)).text(db);
            let source_root_id = db.file_source_root(file_id.file_id(db)).source_root_id(db);
            let root_crates = source_root_crates(db, source_root_id);
            let is_lang = root_crates.iter().any(|x| x.data(db).origin.is_lang());
            if is_lang {
                for error in parse.errors() {
                    let range = error.range();
                    let text_range = &text[range];
                    panic!(
                        "error in '{text_range}': {error}\nis_core: {is_lang}\ntext:\n{text}"
                    );
                }
            }
            parse.syntax_node()
        }
        HirFileId::MacroFile(macro_file) => {
            macro_file.parse_macro_expansion(db).value.0.syntax_node()
        }
    }
}

and it revealed that r-a is unable to parse core:

thread 'PrimeCaches#23' (30802) panicked at crates/hir-expand/src/lib.rs:1713:25:
error in '': expected fn, trait or impl

and the text that follows is this file: https://github.com/rust-lang/rust/blob/main/library/core/src/ops/try_trait.rs
I assume this is caused by the [const]and const trait syntax.

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.