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

Bindings does not simplify programming #45427

Closed
3442853561 opened this issue Oct 21, 2017 · 3 comments
Closed

Bindings does not simplify programming #45427

3442853561 opened this issue Oct 21, 2017 · 3 comments
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@3442853561
Copy link
Contributor

3442853561 commented Oct 21, 2017

fn main() {
    let foo = "1 + (2 + 3)";
    for ch in foo.chars() {
        match ch {
            e @ '(' | e @ '[' | e @ '{' => match e {
                '(' => {}
                '[' => {}
                '{' => {}
                // As we all know, there is missing a _
                // However I think the compiler should be smarter
                // Because there is a binding
            },
            _ => {}
        }
    }
}

As we all know, there is missing a _
However I think the compiler should be smarter
Because there is a binding here
There may be code that will never be executed

@kennytm kennytm added C-enhancement Category: An issue proposing an enhancement or a PR with one. T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Oct 21, 2017
@lambda
Copy link
Contributor

lambda commented Oct 24, 2017

There may be code that will never be executed

The right way to express this is _ => unreachable!().

It would be nice if the compiler would be smarter in this case, but there will always be some cases in which the compiler is not smart enough to figure something out, so you can use unreachable!() to explicitly denote impossible cases.

@crlf0710
Copy link
Member

It would be nice if the compiler would be smarter in this case, but there will always be some cases in which the compiler is not smart enough to figure something out, so you can use unreachable!() to explicitly denote impossible cases.

However, sometimes it's hard if not impossible for people to estimate how smart the compiler is, or would be in the future. See #45414 for an example. It would be great if there's a solid and compatible "check condition", so people would know whether an "unreachable!()" is necessary and won't raise such warnings.

@Mark-Simulacrum
Copy link
Member

I'm going to go ahead and close this as it's not entirely clear that this would be something we'd want to implement; I think extending the compiler lints to be able to detect this would be an interesting avenue to explore but are quite hard and not entirely clear -- as well as almost impossible to close out entirely.

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-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants