Skip to content

advanced_slice_patterns has unreachable expression #37598

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
adjivas opened this issue Nov 4, 2016 · 5 comments
Closed

advanced_slice_patterns has unreachable expression #37598

adjivas opened this issue Nov 4, 2016 · 5 comments
Labels
regression-from-stable-to-nightly Performance or correctness regression from stable to nightly.

Comments

@adjivas
Copy link

adjivas commented Nov 4, 2016

Hello,

According to this chapiter, I have writted this example:

#![feature(advanced_slice_patterns, slice_patterns)]


fn check(list: &[u8]) {
    match list {
        &[] => {},
        &[u1 @ b'\xF0' ... b'\xF4', u2 @ b'\x8F' ... b'\x90',
          u3 @ b'\x80' ... b'\xBF', u4 @ b'\x80' ... b'\xBF', ref next..] => {
            println!("{} {} {} {}", u1, u2, u3, u4);
            check(next)
        },
        &[u1, ref next..] => {
            println!("{}", u1);
            check(next)
        },
    }
}

fn main() {
    let buf = &[b'0', b'1', b'4'];
    
    check(&buf[..]);
}

But after the rustc 1.14.0-nightly version from 2016-10-25 -aef18be1b-,
I expected to see this happen:

error[E0001]: unreachable pattern
  --> <anon>:12:9
   |
12 |         &[u1 @ b'\xF0' ... b'\xF4',
   |         ^ this is an unreachable pattern

error: aborting due to previous error
@djzin
Copy link
Contributor

djzin commented Nov 5, 2016

Minimal example

#![feature(slice_patterns)]

fn check(list: &[u8]) {
    match list {
        &[] => {},
        &[u1, u2, ref next..] => {},
        &[u1] => {},
    }
}

Fails with

rustc 1.14.0-nightly (7c69b0d5a 2016-11-01)
error[E0001]: unreachable pattern
 --> <anon>:6:9
  |
6 |         &[u1, u2, ref next..] => {},
  |         ^^^^^^^^^^^^^^^^^^^^^ this is an unreachable pattern

error: aborting due to previous error

@arielb1 arielb1 added the regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. label Nov 5, 2016
@arielb1
Copy link
Contributor

arielb1 commented Nov 5, 2016

regression introduced in #36695.

@TimNN
Copy link
Contributor

TimNN commented Nov 5, 2016

@arielb1: How can this be a stable-nightly regression when this affects a gated feature?

@arielb1
Copy link
Contributor

arielb1 commented Nov 5, 2016

Not sure what's the policy about it. It's a regression.

@TimNN
Copy link
Contributor

TimNN commented Nov 5, 2016

Yeah, I totally agree that this is a regression, although the label is inaccurate. I have wanted a regression-from-nightly-to-nightly label in the past (for eg. #36954), and think that once upon a time there even was such a label.

arielb1 added a commit to arielb1/rust that referenced this issue Nov 5, 2016
The logic used to be wildly wrong, but before the HAIR patch its
wrongness was hidden by another bug.

Fixes rust-lang#37598.
bors added a commit that referenced this issue Nov 9, 2016
_match: correct max_slice_length logic

The logic used to be wildly wrong, but before the HAIR patch its wrongness was in most cases hidden by another bug.

Fixes #37598.

r? @nikomatsakis
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
regression-from-stable-to-nightly Performance or correctness regression from stable to nightly.
Projects
None yet
Development

No branches or pull requests

4 participants