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

Nested slice pattern incorrectly considered irrefutable #26158

Closed
eefriedman opened this issue Jun 9, 2015 · 9 comments
Closed

Nested slice pattern incorrectly considered irrefutable #26158

eefriedman opened this issue Jun 9, 2015 · 9 comments
Labels
A-type-system Area: Type system T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@eefriedman
Copy link
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.

@oli-obk
Copy link
Contributor

oli-obk commented Jun 10, 2015

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
Copy link
Contributor

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

@bluss
Copy link
Member

bluss commented Jun 10, 2015

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

@TheNeikos
Copy link
Contributor

@bluss Alright

@steveklabnik steveklabnik added the A-type-system Area: Type system label Jun 15, 2015
@emberian emberian added I-wrong T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Jul 3, 2015
@eefriedman
Copy link
Contributor Author

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

@eefriedman
Copy link
Contributor Author

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 reopened this Jul 27, 2016
@eefriedman
Copy link
Contributor Author

eefriedman commented Jul 27, 2016

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; }

@arielb1
Copy link
Contributor

arielb1 commented Jul 31, 2016

I want to figure out our nested slice pattern story.

@nikomatsakis
Copy link
Contributor

@arielb1 can you clarify what are the thorny cases and where things get confusing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-system Area: Type system 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

8 participants