Skip to content

fix: parse field expr keyword field to field-expr node#22398

Closed
A4-Tacks wants to merge 2 commits into
rust-lang:masterfrom
A4-Tacks:field-expr-keyword-err
Closed

fix: parse field expr keyword field to field-expr node#22398
A4-Tacks wants to merge 2 commits into
rust-lang:masterfrom
A4-Tacks:field-expr-keyword-err

Conversation

@A4-Tacks
Copy link
Copy Markdown
Member

@A4-Tacks A4-Tacks commented May 18, 2026

This makes the completion more coherent and helpful for climbing trees

Example

const _=x.ref

Before this PR

CONST
  CONST_KW "const"
  WHITESPACE " "
  UNDERSCORE "_"
  EQ "="
  FIELD_EXPR
    PATH_EXPR
      PATH
        PATH_SEGMENT
          NAME_REF
            IDENT "x"
    DOT "."
ERROR
  REF_KW "ref"
ERROR
  SEMICOLON ";"

After this PR

CONST
  CONST_KW "const"
  WHITESPACE " "
  UNDERSCORE "_"
  EQ "="
  FIELD_EXPR
    PATH_EXPR
      PATH
        PATH_SEGMENT
          NAME_REF
            IDENT "x"
    DOT "."
    ERROR
      REF_KW "ref"
  SEMICOLON ";"

struct S { indent: u8 }
fn foo(_: &mut u8) {}
fn main() {
    let mut s = S { indent: 2 };
    foo(s.in$0)
}

Before this PR

ty: (), name: ?

indent

After this PR

ty: &mut u8, name: ?

&mut indent
indent

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 18, 2026
@ChayimFriedman2
Copy link
Copy Markdown
Contributor

I feel this is a wrong step to take. The reason completion fails is a bug in completion (specifically in the expansion phase, which speculative execution will fix). We shouldn't touch parsing to fix that.

This makes the completion more coherent and helpful for climbing trees

Example
---
```rust
const _=x.ref
```

**Before this PR**

```
CONST
  CONST_KW "const"
  WHITESPACE " "
  UNDERSCORE "_"
  EQ "="
  FIELD_EXPR
    PATH_EXPR
      PATH
        PATH_SEGMENT
          NAME_REF
            IDENT "x"
    DOT "."
ERROR
  REF_KW "ref"
ERROR
  SEMICOLON ";"
```

**After this PR**

```rust
CONST
  CONST_KW "const"
  WHITESPACE " "
  UNDERSCORE "_"
  EQ "="
  FIELD_EXPR
    PATH_EXPR
      PATH
        PATH_SEGMENT
          NAME_REF
            IDENT "x"
    DOT "."
    ERROR
      REF_KW "ref"
  SEMICOLON ";"
```
@A4-Tacks A4-Tacks force-pushed the field-expr-keyword-err branch from bb7cafb to 9ba7631 Compare May 18, 2026 01:50
@A4-Tacks A4-Tacks changed the title minor: parse field expr keyword field to field-expr node fix: parse field expr keyword field to field-expr node May 18, 2026
@A4-Tacks
Copy link
Copy Markdown
Member Author

I added a bug fix example

@ChayimFriedman2
Copy link
Copy Markdown
Contributor

I'm aware of this bug and that this fixes it, that's why I said:

The reason completion fails is a bug in completion (specifically in the expansion phase, which speculative execution will fix). We shouldn't touch parsing to fix that.

@A4-Tacks
Copy link
Copy Markdown
Member Author

A4-Tacks commented May 18, 2026

But some steps are on the original tree, not speculative tree, like expected type and name

And this does make incomplete parsing more reasonable, it won't get worse

@ChayimFriedman2
Copy link
Copy Markdown
Contributor

But some steps are on the original tree, not speculative tree, like expected type and name

I don't understand what you mean by that. What I'm saying is that once we have speculative execution, this bug will be fixed without any change to the parser.

And this does make incomplete parsing more reasonable, it won't get worse

Changing parsing to accept more code has many implications, and I'm opposed to that without a very good reason, especially not to aid a specific IDE feature such as completion.

@A4-Tacks
Copy link
Copy Markdown
Member Author

Okay, I've come up with a worse case:

const _={
    x.
    let y = 2;
}

@A4-Tacks A4-Tacks closed this May 18, 2026
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 18, 2026
@A4-Tacks A4-Tacks deleted the field-expr-keyword-err branch May 18, 2026 02:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants