Skip to content

Allow Foo { .. } patterns to match non-struct types#159295

Open
Jules-Bertholet wants to merge 1 commit into
rust-lang:mainfrom
Jules-Bertholet:rfc-3753
Open

Allow Foo { .. } patterns to match non-struct types#159295
Jules-Bertholet wants to merge 1 commit into
rust-lang:mainfrom
Jules-Bertholet:rfc-3753

Conversation

@Jules-Bertholet

@Jules-Bertholet Jules-Bertholet commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Implements rust-lang/rfcs#3753.

r? @ghost

@rustbot label T-lang A-patterns

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 14, 2026
@Jules-Bertholet Jules-Bertholet force-pushed the rfc-3753 branch 3 times, most recently from 3bf9294 to c2e2353 Compare July 14, 2026 15:44
@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added A-patterns Relating to patterns and pattern matching T-lang Relevant to the language team labels Jul 14, 2026
@rustbot

rustbot commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Error: Label needs-rfc can only be set by Rust team members

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #triagebot on Zulip.

@Jules-Bertholet Jules-Bertholet force-pushed the rfc-3753 branch 3 times, most recently from a92adc3 to fb354ce Compare July 15, 2026 02:15
@Jules-Bertholet

Copy link
Copy Markdown
Contributor Author

This should be ready for at least an initial review—though conditional on t-lang approving the RFC, of course.

r? @Nadrieril

@Jules-Bertholet Jules-Bertholet marked this pull request as ready for review July 15, 2026 02:17
@rustbot

rustbot commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Nadrieril is currently at their maximum review capacity.
They may take a while to respond.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 15, 2026
@rustbot

rustbot commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in match checking

cc @Nadrieril

@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 15, 2026
@theemathas theemathas added the needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. label Jul 15, 2026

@theemathas theemathas Jul 15, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we also add a test with patterns like Option::<i32> { .. } ?

View changes since the review

@theemathas theemathas Jul 15, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

And a test that Option::Some::<i32> { .. } or Option::<i32>::Some { .. } or Option::Some { .. } still work.

@Nadrieril Nadrieril added the needs-rfc This change is large or controversial enough that it should have an RFC accepted before doing it. label Jul 15, 2026
/// Paths in struct expressions and patterns `Path { .. }`.
Struct(Option<&'a Expr>),
/// Paths in patterns matching `Path { .. }` exactly (no fields, with rest pattern).
TypeOrEnumVariant,

@petrochenkov petrochenkov Jul 15, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think it's a good style to make resolution of a path dependent on some other code next to it.
If we are doing this, then we should resolve paths in Path { .. } and Path { fields, .. } identically and then later say that the referenced type doesn't have fields (because it's e.g. an enum).

View changes since the review

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

Labels

A-patterns Relating to patterns and pattern matching needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. needs-rfc This change is large or controversial enough that it should have an RFC accepted before doing it. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants