Skip to content

Conversation

Zalathar
Copy link
Contributor

I noticed that the original code has two identical fallback paths that can be combined into one by using a let-chain for the success case.


While investigating this code, I tried to check my understanding by adding an assertion that exact_size is true iff we are dealing with an array pattern (and not a slice pattern). That uncovered a non-obvious edge case that is not well represented in our test suite, so I added a mir-opt test that explicitly triggers that edge case, to catch any future changes that assume it can't happen.

@rustbot
Copy link
Collaborator

rustbot commented Jan 20, 2025

r? @wesleywiser

rustbot has assigned @wesleywiser.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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 Jan 20, 2025
@rust-log-analyzer

This comment has been minimized.

@Zalathar
Copy link
Contributor Author

Appeased tidy by renaming the test file (diff).

@Zalathar
Copy link
Contributor Author

A few more notes on “not well represented in our test suite”:

If I add an extra argument to prefix_slice_suffix to indicate array vs slice pattern, and assert that that value is equal to exact_size, I get no failures in x test mir-opt, and one failure in x test ui:

  • tests/ui/closures/2229_closure_analysis/issue-87987.rs

That test is somewhat related to this edge case (an array place that doesn't need to be captured), but in a way that wasn't very obvious to me when I first noticed that my assertion was being violated.

There are also several other tests in tests/ui/closures/2229_closure_analysis that deal with non-captured arrays, but they seem to rely on #[rustc_capture_analysis] triggering a synthetic error during type checking, so they presumably don't proceed to MIR building.

@rustbot rustbot added A-tidy Area: The tidy tool T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Jan 20, 2025
@Zalathar
Copy link
Contributor Author

I also renamed issue-87987.rs and added some notes and extra patterns.

@Zalathar
Copy link
Contributor Author

Alternate idea: What if I just make the caller directly responsible for determining what the min-length or exact-length is?

@rustbot author

@rustbot rustbot 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-review Status: Awaiting review from the assignee but also interested parties. labels Jan 20, 2025
joboet added a commit to joboet/rust that referenced this pull request Jan 24, 2025
Rename test to `unresolvable-upvar-issue-87987.rs` and add some notes

Extracted from rust-lang#135756. I had to figure out what this test was trying to test, so I might as well write it down for future reference.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 25, 2025
Rename test to `unresolvable-upvar-issue-87987.rs` and add some notes

Extracted from rust-lang#135756. I had to figure out what this test was trying to test, so I might as well write it down for future reference.
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jan 25, 2025
Rollup merge of rust-lang#135985 - Zalathar:whats-upvar, r=lqd

Rename test to `unresolvable-upvar-issue-87987.rs` and add some notes

Extracted from rust-lang#135756. I had to figure out what this test was trying to test, so I might as well write it down for future reference.
@bors
Copy link
Collaborator

bors commented Jan 25, 2025

☔ The latest upstream changes (presumably #136041) made this pull request unmergeable. Please resolve the merge conflicts.

@Zalathar
Copy link
Contributor Author

This got a bit out of hand, and I’m also not that invested in it, so I’m just going to close.

@Zalathar Zalathar closed this Jan 25, 2025
@Zalathar Zalathar deleted the sequence-patterns branch January 25, 2025 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tidy Area: The tidy tool S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) 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.

5 participants