Skip to content

rust-analyzer should not emit macro-errors when macro input contains an unclosed delimiter #19782

@dhardy

Description

@dhardy

Something which frequently frustrates me with rust-analyzer:

  1. I am editing a Kas widget (to reproduce: clone Kas, pick any widget (but especially a large one; maybe try Spinner), and start typing a new fn with an unclosed brace: {)
  2. RA correctly emits

    [rust-analyzer] (syntax-error) Syntax Error: expected R_CURLY

  3. RA also emits

    [rust-analyzer] (macro-error) unexpected end of input, expected one of: enum, struct, type, union

The latter error causes the whole impl_scope to be marked as erroneous by the editor, making it harder to focus on the actual error.

Meanwhile, cargo check will only report

error: this file contains an unclosed delimiter
[details omitted]

Macros cannot be evaluated on input that won't even tokenize.

Activity

ChayimFriedman2

ChayimFriedman2 commented on May 12, 2025

@ChayimFriedman2
Contributor

rustc can stop compilation when there is an error. rust-analyzer doesn't have this luxury: we must, always, do everything, even with erroneous code. The error marking the whole macro red is bad, though - it'll be better if it would only mark the expected place red, although I'm unsure how viable this is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @dhardy@Veykril@ChayimFriedman2

        Issue actions

          rust-analyzer should not emit macro-errors when macro input contains an unclosed delimiter · Issue #19782 · rust-lang/rust-analyzer