Skip to content

Conversation

A4-Tacks
Copy link
Contributor

@A4-Tacks A4-Tacks commented Oct 11, 2025

Close #20830

Example

struct Foo { bar: bool, n: i32 }

fn baz() {
    let bar = true;
    let foo: Foo = Fo$0;
}

Before this PR:

struct Foo { bar: bool, n: i32 }

fn baz() {
    let bar = true;
    let foo: Foo = Foo { bar: ${1:()}, n: ${2:()} }$0;
}

After this PR:

struct Foo { bar: bool, n: i32 }

fn baz() {
    let bar = true;
    let foo: Foo = Foo { bar$1, n: ${2:()} }$0;
}

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 11, 2025
@A4-Tacks A4-Tacks force-pushed the record-expr-shorthand branch from 9469076 to 6c29055 Compare October 11, 2025 06:01
Copy link
Contributor

@ChayimFriedman2 ChayimFriedman2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was always annoyed by this, thanks! Just one nit.

let field_name = field.name(ctx.db);

if let Some(local) = ctx.locals.get(&field_name)
&& local.ty(ctx.db) == field.ty(ctx.db).to_type(ctx.db)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit better to use could_unify_deeply(), I believe, although I won't hold strong on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be Type::could_unify_with_deeply, right

Example
---
```rust
struct Foo { bar: bool, n: i32 }

fn baz() {
    let bar = true;
    let foo: Foo = Fo$0;
}
```

**Before this PR**:

```rust
struct Foo { bar: bool, n: i32 }

fn baz() {
    let bar = true;
    let foo: Foo = Foo { bar: ${1:()}, n: ${2:()} }$0;
}
```

**After this PR**:

```rust
struct Foo { bar: bool, n: i32 }

fn baz() {
    let bar = true;
    let foo: Foo = Foo { bar$1, n: ${2:()} }$0;
}
```
Copy link
Contributor

@ChayimFriedman2 ChayimFriedman2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ChayimFriedman2 ChayimFriedman2 added this pull request to the merge queue Oct 22, 2025
Merged via the queue into rust-lang:master with commit d2c42fc Oct 22, 2025
15 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 22, 2025
@A4-Tacks A4-Tacks deleted the record-expr-shorthand branch October 22, 2025 04:04
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.

Support struct expression shorthand field

3 participants