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

ICE on pattern match against const &`static [u8] #46920

Closed
chridou opened this issue Dec 21, 2017 · 6 comments
Closed

ICE on pattern match against const &`static [u8] #46920

chridou opened this issue Dec 21, 2017 · 6 comments
Assignees
Labels
P-high High priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@chridou
Copy link

chridou commented Dec 21, 2017

I matched against a &'static [u8] and got the error below. The code compiles on stable and beta. Interestingly I do these kinds of pattern matches elsewhere in the code, too, and there it works.

I found errors with similiar error messages but could not relate them to this code. So sorry if this is a duplicate.

I tried this code:

Can be reproduced on rust playground:

const CURSOR_PARTITION_LABEL: &'static [u8] = b"partition";
const CURSOR_EVENT_TYPE_LABEL: &'static [u8] = b"event_type";
    
fn main() {
    let sample = b"abce";
    
    match &sample[..] {
        CURSOR_PARTITION_LABEL => println!("a"),
        CURSOR_EVENT_TYPE_LABEL => println!("b"),
        _ => (),
    }
}

I expected to see this happen:

A successful build.

Instead, this happened:

error: internal compiler error: broken MIR in NodeId(2445) (""): errors selecting obligation: [FulfillmentError(Obligation(predicate=Binder(TraitPredicate(<[u8] as std::marker::Unsize<[u8]>>)),depth=1),Unimplemented)]

Meta

rustc --version --verbose:

rustc 1.24.0-nightly (7eb64b86c 2017-12-20)
binary: rustc
commit-hash: 7eb64b86ce44cc1828dd176a8b981e37ea08fc38
commit-date: 2017-12-20
host: x86_64-unknown-linux-gnu
release: 1.24.0-nightly
LLVM version: 4.0
@chridou
Copy link
Author

chridou commented Dec 21, 2017

I have some additional information on this:

  • It worked on nightly a week or so ago
  • It also seems to crash the RLS since visual studio code tells me that RLS crashed 5 times and will not be restarted.

@Deewiant
Copy link
Contributor

Bisecting points to 0c26d8f, introduced in #46582.

@MageSlayer
Copy link

@alexcrichton
Please mark it as regression.

@alexcrichton
Copy link
Member

cc @nikomatsakis and @rust-lang/compiler, I think this is a new beta regression!

@alexcrichton alexcrichton added I-nominated T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. regression-from-stable-to-beta Performance or correctness regression from stable to beta. labels Jan 16, 2018
@nikomatsakis
Copy link
Contributor

Will investigate.

@nikomatsakis nikomatsakis self-assigned this Jan 16, 2018
@nikomatsakis
Copy link
Contributor

triage: P-high

@rust-highfive rust-highfive added P-high High priority and removed I-nominated labels Jan 16, 2018
arielb1 added a commit to arielb1/rust that referenced this issue Jan 16, 2018
The match lowering code, when lowering matches against bytestrings,
works by coercing both the scrutinee and the pattern to `&[u8]` and
then comparing them using `<[u8] as Eq>::eq`.

If the scrutinee is already of type `&[u8]`, then unsizing it is both
unneccessary and a trait error caught by the new and updated MIR typeck,
so this PR changes lowering to avoid doing that (match lowering tried to
avoid that before, but that attempt was quite broken).

Fixes rust-lang#46920.
bors added a commit that referenced this issue Jan 19, 2018
avoid double-unsizing arrays in bytestring match lowering

The match lowering code, when lowering matches against bytestrings,
works by coercing both the scrutinee and the pattern to `&[u8]` and
then comparing them using `<[u8] as Eq>::eq`.

If the scrutinee is already of type `&[u8]`, then unsizing it is both
unneccessary and a trait error caught by the new and updated MIR typeck,
so this PR changes lowering to avoid doing that (match lowering tried to
avoid that before, but that attempt was quite broken).

Fixes #46920.

r? @eddyb
MaloJaffre pushed a commit to MaloJaffre/rust that referenced this issue Jan 23, 2018
The match lowering code, when lowering matches against bytestrings,
works by coercing both the scrutinee and the pattern to `&[u8]` and
then comparing them using `<[u8] as Eq>::eq`.

If the scrutinee is already of type `&[u8]`, then unsizing it is both
unneccessary and a trait error caught by the new and updated MIR typeck,
so this PR changes lowering to avoid doing that (match lowering tried to
avoid that before, but that attempt was quite broken).

Fixes rust-lang#46920.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P-high High priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. 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

6 participants