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

Fake capture closures if typeck results are empty #100452

Closed
wants to merge 2 commits into from

Conversation

ouz-a
Copy link
Contributor

@ouz-a ouz-a commented Aug 12, 2022

This ICE happens because closure_min_captures is empty, the reason it's empty is with the 2021 edition enable_precise_capture is set to true, which makes it so that we can't fake capture any information because that result of the unwrap is none hence the ICE.

Other solution is editing maybe_read_scrutinee to this since empty slice contains no sub patterns.

Fixes #93242

PatKind::Slice(_, ref slice, _) => {
    if slice.is_none(){
    need_to_be_read = true;
    }
}
// instead of
PatKind::Or(_)
| PatKind::Box(_)
| PatKind::Slice(..)
| PatKind::Ref(..)
| PatKind::Wild => {}

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Aug 12, 2022
@rust-highfive
Copy link
Collaborator

r? @nagisa

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 12, 2022
@nagisa
Copy link
Member

nagisa commented Aug 15, 2022

r? rust-lang/compiler

@rust-highfive rust-highfive assigned wesleywiser and unassigned nagisa Aug 15, 2022
@ouz-a
Copy link
Contributor Author

ouz-a commented Aug 30, 2022

r? rust-lang/compiler

@ouz-a
Copy link
Contributor Author

ouz-a commented Sep 7, 2022

r? rust-lang/compiler

@rust-highfive rust-highfive assigned fee1-dead and unassigned jackh726 Sep 7, 2022
@jackh726
Copy link
Member

jackh726 commented Sep 7, 2022

Should ping @nikomatsakis about this. He probably has the most background on this.

@@ -231,7 +231,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

// We now fake capture information for all variables that are mentioned within the closure
Copy link
Member

Choose a reason for hiding this comment

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

Can you update this comment to include an explanation for the added logic? And also add a reference to the issue number?

@jackh726
Copy link
Member

jackh726 commented Sep 7, 2022

r=me with updated comment

@fee1-dead fee1-dead assigned jackh726 and unassigned fee1-dead Sep 8, 2022
@jackh726 jackh726 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 Sep 12, 2022
@ouz-a
Copy link
Contributor Author

ouz-a commented Sep 23, 2022

r? @jackh726

@ouz-a
Copy link
Contributor Author

ouz-a commented Sep 23, 2022

cc @nikomatsakis I feel like there is a bigger issue I am missing here and this fix feels a bit like hack, is there anything you would like to add?

@bors
Copy link
Contributor

bors commented Sep 27, 2022

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

@bors
Copy link
Contributor

bors commented Oct 21, 2022

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

@jackh726
Copy link
Member

@bors delegate+

r=me after rebase

@bors
Copy link
Contributor

bors commented Oct 21, 2022

✌️ @ouz-a can now approve this pull request

@ouz-a
Copy link
Contributor Author

ouz-a commented Oct 23, 2022

@bors r=jackh726

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Oct 24, 2022
Fake capture closures if typeck results are empty

This ICE happens because `closure_min_captures` is empty, the reason it's empty is with the 2021 edition `enable_precise_capture` is set to true, which makes it so that we can't fake capture any information because that result of the `unwrap` is none hence the ICE.

Other solution is editing [maybe_read_scrutinee](https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_typeck/expr_use_visitor.rs.html#453-463) to this since empty slice contains no sub patterns.

Fixes rust-lang#93242

```rust
PatKind::Slice(_, ref slice, _) => {
    if slice.is_none(){
    need_to_be_read = true;
    }
}
// instead of
PatKind::Or(_)
| PatKind::Box(_)
| PatKind::Slice(..)
| PatKind::Ref(..)
| PatKind::Wild => {}
```
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Oct 25, 2022
Fake capture closures if typeck results are empty

This ICE happens because `closure_min_captures` is empty, the reason it's empty is with the 2021 edition `enable_precise_capture` is set to true, which makes it so that we can't fake capture any information because that result of the `unwrap` is none hence the ICE.

Other solution is editing [maybe_read_scrutinee](https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_typeck/expr_use_visitor.rs.html#453-463) to this since empty slice contains no sub patterns.

Fixes rust-lang#93242

```rust
PatKind::Slice(_, ref slice, _) => {
    if slice.is_none(){
    need_to_be_read = true;
    }
}
// instead of
PatKind::Or(_)
| PatKind::Box(_)
| PatKind::Slice(..)
| PatKind::Ref(..)
| PatKind::Wild => {}
```
compiler-errors added a commit to compiler-errors/rust that referenced this pull request Oct 26, 2022
Fake capture closures if typeck results are empty

This ICE happens because `closure_min_captures` is empty, the reason it's empty is with the 2021 edition `enable_precise_capture` is set to true, which makes it so that we can't fake capture any information because that result of the `unwrap` is none hence the ICE.

Other solution is editing [maybe_read_scrutinee](https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_typeck/expr_use_visitor.rs.html#453-463) to this since empty slice contains no sub patterns.

Fixes rust-lang#93242

```rust
PatKind::Slice(_, ref slice, _) => {
    if slice.is_none(){
    need_to_be_read = true;
    }
}
// instead of
PatKind::Or(_)
| PatKind::Box(_)
| PatKind::Slice(..)
| PatKind::Ref(..)
| PatKind::Wild => {}
```
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Oct 28, 2022
Fake capture closures if typeck results are empty

This ICE happens because `closure_min_captures` is empty, the reason it's empty is with the 2021 edition `enable_precise_capture` is set to true, which makes it so that we can't fake capture any information because that result of the `unwrap` is none hence the ICE.

Other solution is editing [maybe_read_scrutinee](https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_typeck/expr_use_visitor.rs.html#453-463) to this since empty slice contains no sub patterns.

Fixes rust-lang#93242

```rust
PatKind::Slice(_, ref slice, _) => {
    if slice.is_none(){
    need_to_be_read = true;
    }
}
// instead of
PatKind::Or(_)
| PatKind::Box(_)
| PatKind::Slice(..)
| PatKind::Ref(..)
| PatKind::Wild => {}
```
@Dylan-DPC
Copy link
Member

failed in rollup

@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 Oct 28, 2022
@rustbot
Copy link
Collaborator

rustbot commented Oct 31, 2022

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@ouz-a
Copy link
Contributor Author

ouz-a commented Oct 31, 2022

I am not sure about the results of these tests would love to get some approval from @rust-lang/clippy

@bors
Copy link
Contributor

bors commented Dec 29, 2022

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

@jackh726
Copy link
Member

Well, thank goodness for clippy. This PR regresses the following code with edition 2021 (it fails for previous editions):

#[derive(Clone)]
struct Alpha;

fn clone_then_move_cloned() {
    fn foo<F: Fn()>(_: &Alpha, _: F) {}
    let x = Alpha;
    // ok, data is moved while the clone is in use.
    foo(&x, move || {
        let _ = x;
    });
}

fn main() { clone_then_move_cloned() }

Can you please add the above as a test? Looks like we need to come up with a different solution.

@flip1995
Copy link
Member

Yeah this Clippy test change looks fishy. Usually when a Clippy test changes without any Clippy changes it means some assertions Clippy made about compiler internals changed.

@ouz-a
Copy link
Contributor Author

ouz-a commented Dec 30, 2022

Can you please add the above as a test? Looks like we need to come up with a different solution.

Yeah, will look into another solution.

@jackh726
Copy link
Member

@ouz-a any updates here?

@ouz-a
Copy link
Contributor Author

ouz-a commented Feb 19, 2023

@ouz-a any updates here?

Sorry completely forget about this, going to try to solve this, this week if can't solve it will post what I found.

@bors
Copy link
Contributor

bors commented Mar 1, 2023

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

@ouz-a
Copy link
Contributor Author

ouz-a commented Mar 9, 2023

I spent some time trying to uncover what's happening but I couldn't find a solution:
For the code below [] is captured as Upvar and to_upvars_resolved_place_builder can't resolve it, on the other hand when we remove // from [1], [] is captured as Local and everything works, however I couldn't find out why this behavior emerges so I'm closing this PR in favor of better future solution to this issue.

pub async fn something(path: &[usize]) -> usize {
    // Without this async block it doesn't ICE
    async {
        match path {
            [] => 1,
            //[1] => 2,
            _ => 1,
        }
    }
    .await
}

@ouz-a ouz-a closed this Mar 9, 2023
@ouz-a ouz-a deleted the issue-93242 branch July 26, 2023 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

ICE for async block containing match on empty slice and wildcard
10 participants