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

Make or (|) patterns work with match default binding modes #44912

Open
tbg opened this issue Sep 29, 2017 · 2 comments
Open

Make or (|) patterns work with match default binding modes #44912

tbg opened this issue Sep 29, 2017 · 2 comments
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@tbg
Copy link
Contributor

tbg commented Sep 29, 2017

Consider the following example which (at the time of writing, i.e. #44614) fails:

pub fn main() {
    let x = &Some((3, 3));
    let _: &i32 = match x {
        // Here, each of the patterns are treated independently
        //
        // FIXME(tschottdorf): make this compile without the actual `|`.
        // @nikomatsakis suggested perhaps just removing the code which
        // complains but wasn't sure whether it's still required for anything.
        // Opinions?
        //
        //          Some((x, 3)) | &Some((ref x, 5)) => x,
        //                - first binding     ^ bound in different ways
        /*Some((x, 3)) |*/ &Some((ref x, 5)) => x,
        _ => &5i32,
    };
}

It's not clear whether the rule that prevents this from compiling is still worthwhile.

@nikomatsakis had this to say:

I suspect we can just remove it but it may be used by some code somewhere
i.e., I'm pretty sure the old trans code (obviated by MIR now) used to rely on that (that each binding had a single "mode") but...
well, maybe MIR builder does too, who knows
honestly maybe not worth supporting
(well, I guess that if we keep the check, we would want to check the inferred mode -- probably better if we ditch it and figure out if we have to change anything else as a result)

@TimNN TimNN added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Oct 1, 2017
@nikomatsakis nikomatsakis added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-compiler-middle labels Oct 3, 2017
@Centril
Copy link
Contributor

Centril commented Sep 3, 2019

It seems this issue is not about default binding modes but rather about the check in resolve that makes sure an or-pattern has consistent binding modes.

@jackh726
Copy link
Member

Removing wg label without retagging; not a good wg- label for this right now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants