Skip to content

Conversation

helldawg
Copy link
Contributor

@helldawg helldawg commented Sep 19, 2025

Fixes #146476

This is kinda rough, 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
Contributor 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
Contributor 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
Contributor 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
Contributor 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.

@workingjubilee
Copy link
Member

Thanks!

I feel like this could have a future improvement but I think this is also better than what we currently have so I think I will r+ it. Maybe someone will open a new issue and we'll revisit this someday.

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Sep 24, 2025

📌 Commit 39c67cf has been approved by workingjubilee

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 24, 2025
@workingjubilee
Copy link
Member

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Sep 24, 2025
@workingjubilee
Copy link
Member

my brain.

@helldawg Remembered one last thing: squash commits?

@rustbot

This comment has been minimized.

@rustbot rustbot added the has-merge-commits PR has merge commits, merge with caution. label Sep 25, 2025
@rustbot
Copy link
Collaborator

rustbot commented Sep 25, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rustbot rustbot removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. has-merge-commits PR has merge commits, merge with caution. labels Sep 25, 2025
@helldawg
Copy link
Contributor Author

@helldawg Remembered one last thing: squash commits?

Welp, that took a good 7 open tabs and 20 minutes. Good news is that the commits are squashed, and 700 other commits aren't tacked on for good measure.

@workingjubilee
Copy link
Member

sorry. ^^;

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Sep 27, 2025

📌 Commit 7e58c91 has been approved by workingjubilee

It is now in the queue for this repository.

@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Sep 27, 2025
Zalathar added a commit to Zalathar/rust that referenced this pull request Sep 28, 2025
Clarified error note for usize range matching

Fixes rust-lang#146476

This is kinda rough, but it gets the point across a little better and stays short.
bors added a commit that referenced this pull request Sep 28, 2025
Rollup of 16 pull requests

Successful merges:

 - #142139 (Include additional hashes in src/stage0)
 - #146745 (Clarified error note for usize range matching)
 - #146763 (cg_llvm: Replace some DIBuilder wrappers with LLVM-C API bindings (part 5))
 - #146788 (chore: removes deprecated discord.)
 - #146942 ([rustdoc] Finish getting rid of usages `write_str`)
 - #147002 (rustdoc-search: stringdex update with more packing)
 - #147061 (fix rebasing cycle heads when not reaching a fixpoint)
 - #147066 (Fix tracking issue number for feature(macro_attr))
 - #147081 (doc: fix a typo in platform-support.md)
 - #147082 (formatting_options: fix alternate docs 0b/0o mixup)
 - #147086 (compiletest: Use `PanicHookInfo::payload_as_str` now that it's stable in beta)
 - #147092 (Do not compute optimized MIR if code does not type-check.)
 - #147093 (redox: switch to colon as path separator)
 - #147095 (Library: Remove remaining private `#[repr]` workarounds)
 - #147098 (Add auto extra-checks in pre-push hook)
 - #147110 (Fix typo)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Sep 28, 2025
Rollup of 14 pull requests

Successful merges:

 - #142139 (Include additional hashes in src/stage0)
 - #146745 (Clarified error note for usize range matching)
 - #146763 (cg_llvm: Replace some DIBuilder wrappers with LLVM-C API bindings (part 5))
 - #146788 (chore: removes deprecated discord.)
 - #146942 ([rustdoc] Finish getting rid of usages `write_str`)
 - #147061 (fix rebasing cycle heads when not reaching a fixpoint)
 - #147066 (Fix tracking issue number for feature(macro_attr))
 - #147081 (doc: fix a typo in platform-support.md)
 - #147082 (formatting_options: fix alternate docs 0b/0o mixup)
 - #147086 (compiletest: Use `PanicHookInfo::payload_as_str` now that it's stable in beta)
 - #147093 (redox: switch to colon as path separator)
 - #147095 (Library: Remove remaining private `#[repr]` workarounds)
 - #147098 (Add auto extra-checks in pre-push hook)
 - #147110 (Fix typo)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 4eddf64 into rust-lang:master Sep 28, 2025
10 checks passed
@rustbot rustbot added this to the 1.92.0 milestone Sep 28, 2025
rust-timer added a commit that referenced this pull request Sep 28, 2025
Rollup merge of #146745 - helldawg:master, r=workingjubilee

Clarified error note for usize range matching

Fixes #146476

This is kinda rough, but it gets the point across a little better and stays short.
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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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
7 participants