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

Get with field index from pattern slice instead of directly indexing #82789

Merged
merged 2 commits into from
Mar 14, 2021

Conversation

csmoe
Copy link
Member

@csmoe csmoe commented Mar 5, 2021

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 5, 2021
@rust-log-analyzer

This comment has been minimized.

@csmoe csmoe force-pushed the issue-82772 branch 2 times, most recently from 9b10ffd to ff35210 Compare March 5, 2021 08:24
@rust-log-analyzer

This comment has been minimized.

@camelid camelid added the A-patterns Relating to patterns and pattern matching label Mar 7, 2021
@csmoe
Copy link
Member Author

csmoe commented Mar 9, 2021

@estebank ping

@estebank
Copy link
Contributor

estebank commented Mar 9, 2021

Could you add a test for the more than one field case?

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@csmoe
Copy link
Member Author

csmoe commented Mar 10, 2021

@estebank kind of strange as I fixed that with vis.is_accessible_from(), then in the test --bless shows that we already have E0451 in rustc_privacy addressed such private field case. But don't know why rustc didn't catch this earlier(before typeck of pattern).

@estebank
Copy link
Contributor

I have a theory: we already emit privacy errors pointing at the ADT on some cases of private fields, so the error for the field themselves would only be redundant. The ICE you're fixing only happens on non-existing fields, and the new error is just precluding getting to that. Could you verify whether my theory is correct? I'm swamped until next week to do this kind of light digging :)

@csmoe

This comment has been minimized.

@csmoe
Copy link
Member Author

csmoe commented Mar 11, 2021

@estebank So the real cause is we only generate single pattern for Box here
https://github.com/csmoe/rust/blob/615b03aeaa8ce9819de7828740ab3cd7def4fa76/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs#L1130-L1132
But in the replacing function, it tries to index on the 1-length pattern slice with field 1, thus out of bounds.
https://github.com/csmoe/rust/blob/615b03aeaa8ce9819de7828740ab3cd7def4fa76/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs#L1346

@csmoe csmoe changed the title Take visibility into account when checking on field pattern Get with field index from pattern slice instead of directly indexing Mar 11, 2021
@estebank
Copy link
Contributor

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Mar 13, 2021

📌 Commit 77fb6a0 has been approved by estebank

@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 Mar 13, 2021
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Mar 13, 2021
Get with field index from pattern slice instead of directly indexing

Closes rust-lang#82772
r? `@estebank`

rust-lang#82789 (comment)
> `@estebank` So the real cause is we only generate single pattern for Box here
https://github.com/csmoe/rust/blob/615b03aeaa8ce9819de7828740ab3cd7def4fa76/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs#L1130-L1132
But in the replacing function, it tries to index on the 1-length pattern slice with field 1, thus out of bounds.
https://github.com/csmoe/rust/blob/615b03aeaa8ce9819de7828740ab3cd7def4fa76/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs#L1346
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 14, 2021
Rollup of 10 pull requests

Successful merges:

 - rust-lang#81465 (Add documentation about formatting `Duration` values)
 - rust-lang#82121 (Implement Extend and FromIterator for OsString)
 - rust-lang#82617 (Document `everybody_loops`)
 - rust-lang#82789 (Get with field index from pattern slice instead of directly indexing)
 - rust-lang#82798 (Rename `rustdoc` to `rustdoc::all`)
 - rust-lang#82804 (std: Fix a bug on the wasm32-wasi target opening files)
 - rust-lang#82943 (Demonstrate best practice for feeding stdin of a child processes)
 - rust-lang#83066 (Add `reverse` search alias for Iterator::rev())
 - rust-lang#83070 (Update cargo)
 - rust-lang#83081 (Fix panic message of `assert_failed_inner`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 0d9a6ed into rust-lang:master Mar 14, 2021
@rustbot rustbot added this to the 1.52.0 milestone Mar 14, 2021
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 S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Trying to pattern-match field 1 of Box causes an ICE
8 participants