rust-lang/rust-analyzer

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

Open

#23,006 opened on Aug 2, 2026

 (14 comments) (0 reactions) (1 assignee)Rust (1,726 forks)batch import
A-parserC-bugE-has-instructionsE-mediumgood first issue

Repository metrics

Stars
 (14,924 stars)
PR merge metrics
 (Avg merge 11d 5h) (96 merged PRs in 30d)

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