Skip to content

Nested slice pattern incorrectly considered irrefutable #26158

@eefriedman

Description

@eefriedman
Contributor

Testcase:

#![feature(slice_patterns)]
fn main() { let x: &[String] = &[]; let [[ref _a, _b..]..] = x; }

This clearly shouldn't type-check, but currently compiles without any error.

Activity

oli-obk

oli-obk commented on Jun 10, 2015

@oli-obk
Contributor

This is very bad:

#![feature(slice_patterns)]
fn main() {
    let x: &[u32] = &[];
    let [[a, b..]..] = x;
    println!("{:08x}", a);
    for x in b.iter().take(30) {
        println!("{:08x}", x);
    }
}
0000000a
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000020
00000003
00000008
00000000
00000003
00000000
00000000
00000000
00000000
00000000
00000008
00000000
74697261
74656d68
6f206369
61726570
6e6f6974
65766f20
6f6c6672
00646577
6d6f682f
75722f65
75627473
TheNeikos

TheNeikos commented on Jun 10, 2015

@TheNeikos
Contributor

If I understand correctly this reads unitialized memory? Or rather, not owned memory?

bluss

bluss commented on Jun 10, 2015

@bluss
Member

@TheNeikos yes. Fortunately it depends on a feature marked unstable.

TheNeikos

TheNeikos commented on Jun 10, 2015

@TheNeikos
Contributor

@bluss Alright

eefriedman

eefriedman commented on Jul 27, 2016

@eefriedman
ContributorAuthor

This is outdated since the slice pattern rewrite. Filed #35077 as a followup.

eefriedman

eefriedman commented on Jul 27, 2016

@eefriedman
ContributorAuthor

Wait, nevermind, this is still a problem; revised testcase:

#![feature(slice_patterns)]
fn main() {
    let x: &[u32] = &[];
    let (a, b) = match x { &[[a, ref b..]..] => (a, b) };
    println!("{:08x}", a);
    for x in b.iter().take(30) {
        println!("{:08x}", x);
    }
}
eefriedman

eefriedman commented on Jul 27, 2016

@eefriedman
ContributorAuthor

Related miscompile:

#![feature(slice_patterns)]
fn main() {
    let x: &[String] = &[];
    match x {
        &[[ref b..]..] => { println!("Fun{}{}", b.len()); }
    }
}

MIR ICE:

#![feature(slice_patterns)]
fn main() { let x: &[i32] = &[]; let &[[_a, ref _b..]..] = x; }

7 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-type-systemArea: Type systemT-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @steveklabnik@nikomatsakis@oli-obk@emberian@TheNeikos

        Issue actions

          Nested slice pattern incorrectly considered irrefutable · Issue #26158 · rust-lang/rust