Skip to content

Constants, slice patterns, and exhaustiveness interact in suboptimal ways #65413

Closed

Description

@arielb1

For example,

#![feature(slice_patterns)]

const C0: &'static [u8] = b"\x00";

fn main() {
   let x: &[u8] = &[0];
   match x { // this code compiles
       &[] => {},
       &[1..=255] => {},
       C0 => {}, //~ unreachable pattern (no it's not)
       &[_, _, ..] => {}
   }
}

cc @oli-obk

Activity

  1. varkor commented on Oct 14, 2019

    @varkor
    Contributor

    Probably related to #53708: consts are mishandled at the moment.

  2. added
    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)
    A-slice-patternsArea: Slice patterns, https://github.com/rust-lang/rust/issues/23121
    C-bugCategory: This is a bug.
    requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Oct 14, 2019
  3. Centril commented on Nov 17, 2019

    @Centril
    Contributor

    Reduced:

    #![feature(slice_patterns)]
    
    fn main() {
       let x: &[u8] = &[0];
       match x { // this code compiles
           &[] => {},
           &[1..=255] => {},
           b"\x00" => {}, //~ unreachable pattern (no it's not)
           &[_, _, ..] => {}
       }
    }
  4. Nadrieril commented on Nov 17, 2019

    @Nadrieril
    Member

    I found a fix, I'll make a PR once #66497 gets merged

  5. added a commit that references this issue on Nov 28, 2019
    f453d11
  6. added a commit that references this issue on Jan 18, 2020
  7. added a commit that references this issue on Jan 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-slice-patternsArea: Slice patterns, https://github.com/rust-lang/rust/issues/23121C-bugCategory: This is a bug.F-slice_patterns`#![feature(slice_patterns)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions