Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update patterns.md for const pattern RFC #1456

Merged
merged 3 commits into from
May 27, 2024

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Jan 26, 2024

Updates the reference for rust-lang/rfcs#3535.
Tracking issue: rust-lang/rust#120362.

This is not 100% implemented yet:

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 3, 2024
make matching on NaN a hard error, and remove the rest of illegal_floating_point_literal_pattern

These arms would never be hit anyway, so the pattern makes little sense. We have had a future-compat lint against float matches in general for a *long* time, so I hope we can get away with immediately making this a hard error.

This is part of implementing rust-lang/rfcs#3535.

Closes rust-lang#41620 by removing the lint.

rust-lang/reference#1456 updates the reference to match.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 3, 2024
make matching on NaN a hard error, and remove the rest of illegal_floating_point_literal_pattern

These arms would never be hit anyway, so the pattern makes little sense. We have had a future-compat lint against float matches in general for a *long* time, so I hope we can get away with immediately making this a hard error.

This is part of implementing rust-lang/rfcs#3535.

Closes rust-lang#41620 by removing the lint.

rust-lang/reference#1456 updates the reference to match.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 5, 2024
make matching on NaN a hard error, and remove the rest of illegal_floating_point_literal_pattern

These arms would never be hit anyway, so the pattern makes little sense. We have had a future-compat lint against float matches in general for a *long* time, so I hope we can get away with immediately making this a hard error.

This is part of implementing rust-lang/rfcs#3535.

Closes rust-lang#41620 by removing the lint.

rust-lang/reference#1456 updates the reference to match.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 5, 2024
make matching on NaN a hard error, and remove the rest of illegal_floating_point_literal_pattern

These arms would never be hit anyway, so the pattern makes little sense. We have had a future-compat lint against float matches in general for a *long* time, so I hope we can get away with immediately making this a hard error.

This is part of implementing rust-lang/rfcs#3535.

Closes rust-lang#41620 by removing the lint.

rust-lang/reference#1456 updates the reference to match.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 5, 2024
make matching on NaN a hard error, and remove the rest of illegal_floating_point_literal_pattern

These arms would never be hit anyway, so the pattern makes little sense. We have had a future-compat lint against float matches in general for a *long* time, so I hope we can get away with immediately making this a hard error.

This is part of implementing rust-lang/rfcs#3535.

Closes rust-lang#41620 by removing the lint.

rust-lang/reference#1456 updates the reference to match.
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Feb 5, 2024
Rollup merge of rust-lang#116284 - RalfJung:no-nan-match, r=cjgillot

make matching on NaN a hard error, and remove the rest of illegal_floating_point_literal_pattern

These arms would never be hit anyway, so the pattern makes little sense. We have had a future-compat lint against float matches in general for a *long* time, so I hope we can get away with immediately making this a hard error.

This is part of implementing rust-lang/rfcs#3535.

Closes rust-lang#41620 by removing the lint.

rust-lang/reference#1456 updates the reference to match.
@ehuss
Copy link
Contributor

ehuss commented Feb 5, 2024

@RalfJung Is this ready to merge? Were there any changes since this was written?

@RalfJung
Copy link
Member Author

RalfJung commented Feb 5, 2024

We are slowly staging the deployment of this in rustc. Not sure how closely the reference wants to match that.

If you are okay with the reference stating things as required that are just future-compat lints in rustc (rather than hard errors), then this is ready to go, yes.

flip1995 pushed a commit to flip1995/rust-clippy that referenced this pull request Feb 8, 2024
make matching on NaN a hard error, and remove the rest of illegal_floating_point_literal_pattern

These arms would never be hit anyway, so the pattern makes little sense. We have had a future-compat lint against float matches in general for a *long* time, so I hope we can get away with immediately making this a hard error.

This is part of implementing rust-lang/rfcs#3535.

Closes rust-lang/rust#41620 by removing the lint.

rust-lang/reference#1456 updates the reference to match.
@RalfJung
Copy link
Member Author

RalfJung commented May 3, 2024

FYI, when rust-lang/rust#124661 lands rustc will fully behave as documented here. I hope to land that in this release cycle.

src/patterns.md Outdated
Comment on lines 789 to 790
In particular, the value of `C` must be known at pattern-building time (which is pre-monomorphization).
This means that associated consts cannot be used as patterns.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand this part. Path patterns can be associated consts. Can you clarify what it is referring to?

Copy link
Member Author

@RalfJung RalfJung May 6, 2024

Choose a reason for hiding this comment

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

This is intended to explain why this code does not compile:

trait Trait {
    const C: i32;
}

fn f<T: Trait>(x: i32) -> bool {
    matches!(x, T::C) //~ERROR: associated consts cannot be referenced in patterns
}

src/patterns.md Outdated
When a constant `C` of type `T` is used as a pattern, we first check that `T: PartialEq`.
Furthermore we require that the value of `C` *has (recursive) structural equality*, which is defined recursively as follows:

- Integers as well as `bool` and `char` values always have structural equality.
Copy link
Contributor

Choose a reason for hiding this comment

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

And strings?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah right, they should also be added here, good catch.

Copy link
Contributor

@ehuss ehuss left a comment

Choose a reason for hiding this comment

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

Thanks!

@ehuss ehuss added this pull request to the merge queue May 27, 2024
Merged via the queue into rust-lang:master with commit 0e07fc5 May 27, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-stabilization Waiting for a stabilization PR to be merged in the main Rust repository
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants