Skip to content

Closure capture calculated incorrectly for non-binding match #14754

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

Closed
Veykril opened this issue May 7, 2023 · 3 comments · Fixed by #14851
Closed

Closure capture calculated incorrectly for non-binding match #14754

Veykril opened this issue May 7, 2023 · 3 comments · Fixed by #14851
Assignees
Labels
A-mir C-bug Category: bug

Comments

@Veykril
Copy link
Member

Veykril commented May 7, 2023

The following closures capture x by value both
playground

fn main() {
    let c: fn() = {
        let x = 1;
        || {
            let _ = x;
        }
    };
    let c: fn() = {
        let x = 1;
        || match x {
            _ => println!("Hello World!"),
        }
    };
}

yet we recognize the first as non capturing and the second as capturing by ref.

@Veykril Veykril added C-bug Category: bug A-mir labels May 7, 2023
@HKalbasi
Copy link
Member

HKalbasi commented May 7, 2023

This is really strange: if I print the size of closures, it shows 0 for both of them (playground)

@Veykril
Copy link
Member Author

Veykril commented May 7, 2023

Ah, I guess the coercion logic sees the captures "by syntax" rather by semantics? Nevertheless there is an error on our side since the second one captures for us when it shouldn't then (though i suppose that comes from our match checking logic which is slightly flawed in general I think?)

@HKalbasi
Copy link
Member

HKalbasi commented May 7, 2023

Ah, I guess the coercion logic sees the captures "by syntax" rather by semantics?

Makes sense.

though i suppose that comes from our match checking logic which is slightly flawed in general I think?

No IIRC I didn't implement the match part of the capturing logic at all :)

@HKalbasi HKalbasi self-assigned this May 12, 2023
bors added a commit that referenced this issue May 18, 2023
Add `moved-out-of-ref` diagnostic

This is marked as experimental, since spans are terrible, there are some false positives due #14754, and it doesn't play well with unknown types. But I hope we can soon lift it.
bors added a commit that referenced this issue May 19, 2023
Handle match scrutinee in closure captures

fix #14754
@bors bors closed this as completed in ce93617 May 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-mir C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants