Skip to content

Conversation

helldawg
Copy link

@helldawg helldawg commented Sep 19, 2025

Fixes #146476

This is (I think) partly incorrect, but it gets the point across a little better and stays short.

r? @workingjubilee
@rustbot label A-diagnostics A-exhaustiveness-checking A-patterns

@rustbot
Copy link
Collaborator

rustbot commented Sep 19, 2025

Some changes occurred in match checking

cc @Nadrieril

@rustbot rustbot added 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. labels Sep 19, 2025
@rustbot
Copy link
Collaborator

rustbot commented Sep 19, 2025

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

@rustbot rustbot added A-diagnostics Area: Messages for errors, warnings, and lints A-exhaustiveness-checking Relating to exhaustiveness / usefulness checking of patterns A-patterns Relating to patterns and pattern matching labels Sep 19, 2025
@rustbot

This comment has been minimized.

@rustbot rustbot added has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 19, 2025
@rustbot rustbot removed has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 19, 2025
@rust-log-analyzer

This comment has been minimized.

@workingjubilee
Copy link
Member

Need to also fix the tests which may just require an ./x.py test ./tests/ui --bless

} else if ty.inner() == cx.tcx.types.isize {
err.note(format!(
"`{ty}` does not have fixed minimum and maximum values, so half-open \
"The minimum and maximum values of `{ty}` are not directly accessible, so half-open \
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"The minimum and maximum values of `{ty}` are not directly accessible, so half-open \
"the minimum and maximum values of `{ty}` are not directly accessible, so half-open \

https://rustc-dev-guide.rust-lang.org/diagnostics.html#diagnostic-output-style-guide

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@helldawg
Copy link
Author

Not really sure how to fix this failing check. It's being compared to the old one, even with the updated stderr. Seems like it's checking for stdout?

@cyrgani
Copy link
Contributor

cyrgani commented Sep 19, 2025

You also need to update the error annotations within the test files themselves such as "NOTE usize does not have a fixed maximum value". (https://rustc-dev-guide.rust-lang.org/tests/ui.html#error-annotations)

@helldawg
Copy link
Author

You also need to update the error annotations within the test files themselves such as "NOTE usize does not have a fixed maximum value". (https://rustc-dev-guide.rust-lang.org/tests/ui.html#error-annotations)

Gotcha, thank you.

if ty.inner() == cx.tcx.types.usize {
err.note(format!(
"`{ty}` does not have a fixed maximum value, so half-open ranges are \
"`{ty}::MAX` is not accessible as a fixed value, so half-open ranges are \
Copy link
Member

Choose a reason for hiding this comment

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

Hmm. I'm not sure what "accessible" is intended to mean here, as in a sense of "the path to the item", it sure is accessible.

Copy link
Author

Choose a reason for hiding this comment

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

Hmm. I'm not sure what "accessible" is intended to mean here, as in a sense of "the path to the item", it sure is accessible.

I think "accessible" means I need to access more sleep, because it looks like I was not comprehending anything I read.

Thinking of changing it to:
"usize::MAX is not treated as exhaustive, so half-open ranges are necessary to match exhaustively"
and
"isize::MIN and isize::MAX are not treated as exhaustive, so half-open ranges are necessary to match exhaustively"

Or "considered" instead of "treated as"

Copy link
Member

@workingjubilee workingjubilee Sep 20, 2025

Choose a reason for hiding this comment

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

Mm. Maybe it would be good to think about this example:

https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=07824b8c993d26743b4a371df42b106b

Notice how usize::MAX is... well, no longer "actually" usize::MAX.

usize::MAX is a library constant and remains so which also means shadowing it is fair game. It's a bit of a case of "I love it when I can implement the same things as the standard library does! ...No, wait, not like that 😭"

So usize patterns do not consider any particular constant as forming the upper bound of the type. This also handles the case, as mentioned in the issue, of

const USIZE_MAX: usize = usize::MAX;

Which arguably should be treated as the exhaustive upper bound if we treat usize::MAX also, but at what cost of compiler complexity and code correctness? Should it differ if one copies the literal there?

Copy link
Member

Choose a reason for hiding this comment

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

You don't need to present an elaborate justification about compiler implementation, mind, indeed I expect most are not interested in that, I'm just noting some things.

Copy link
Author

Choose a reason for hiding this comment

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

I considered elaborating on why this doesn't work the way it intuitively should, but decided that it wouldn't add all that much value in the end. The rationale being that knowing about the exact compiler quirk won't make it compile any better than the suggested fix (which might have some room for improvement here?) or, y'know, making work as it theoretically should on the compiler level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-exhaustiveness-checking Relating to exhaustiveness / usefulness checking of patterns A-patterns Relating to patterns and pattern matching 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Matching on usize requires half-open range
6 participants