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

extended information for slice pattern errors (E0527 through E0529) #34319

Merged
merged 3 commits into from
Aug 5, 2016

Conversation

zackmdavis
Copy link
Member

Example of erroneous code:

```compile_fail
#![feature(slice_patterns)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code throws E0308 on nightly as it seems.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it does.

@GuillaumeGomez
Copy link
Member

Have you tested your code on nightly?

@zackmdavis
Copy link
Member Author

That's strange! What specific nightly are you on? I composed these against 5c2a5d4 2016-06-11, and it looks like they still behave the same against bb4a79b 2016-06-15 (which multirust update nightly just gave me right now):

zmd@ExpectedReturn:~/Code/Misc$ rustc --version
rustc 1.11.0-nightly (bb4a79b08 2016-06-15)
zmd@ExpectedReturn:~/Code/Misc$ cat e0527.rs 
#![feature(slice_patterns)]

fn main() {
    let r = &[1, 2, 3, 4];
    match r {
        &[a, b] => { // error: pattern requires 2 elements but array
                     //        has 4
            println!("a={}, b={}", a, b);
        }
    }
}
zmd@ExpectedReturn:~/Code/Misc$ rustc e0527.rs 
e0527.rs:6:10: 6:16 error: pattern requires 2 elements but array has 4 [E0527]
e0527.rs:6         &[a, b] => { // error: pattern requires 2 elements but array
                    ^~~~~~
error: aborting due to previous error
zmd@ExpectedReturn:~/Code/Misc$ cat e0528.rs 
#![feature(slice_patterns)]

fn main() {
    let r = &[1, 2];
    match r {
        &[a, b, c, rest..] => { // error: pattern requires at least 3
                                //        elements but array has 2
            println!("a={}, b={}, c={} rest={:?}", a, b, c, rest);
        }
    }
}
zmd@ExpectedReturn:~/Code/Misc$ rustc e0528.rs 
e0528.rs:6:10: 6:27 error: pattern requires at least 3 elements but array has 2 [E0528]
e0528.rs:6         &[a, b, c, rest..] => { // error: pattern requires at least 3
                    ^~~~~~~~~~~~~~~~~
error: aborting due to previous error
zmd@ExpectedReturn:~/Code/Misc$ cat e0529.rs 
#![feature(slice_patterns)]

fn main() {
    let r: f32 = 1.0;
    match r {
        [a, b] => { // error: expected an array or slice, found `f32`
            println!("a={}, b={}", a, b);
        }
    }
}
zmd@ExpectedReturn:~/Code/Misc$ rustc e0529.rs 
e0529.rs:6:9: 6:15 error: expected an array or slice, found `f32` [E0529]
e0529.rs:6         [a, b] => { // error: expected an array or slice, found `f32`
                   ^~~~~~
error: aborting due to previous error

@zackmdavis
Copy link
Member Author

Also, Travis points out that I made a syntax error (which I suppose is only just punishment for relying on CI instead of building it locally); I'll (force-)push a fix for that later.

@GuillaumeGomez
Copy link
Member

GuillaumeGomez commented Jun 17, 2016

I tried on play.rust-lang.org. So maybe the nightly version isn't up-to-date. Don't really know. I'll retry once you'll update it.

@zackmdavis zackmdavis force-pushed the explain_slice_pattern_errors branch from 9b3f857 to f3fa2ef Compare June 22, 2016 04:58
@zackmdavis
Copy link
Member Author

@GuillaumeGomez Force-pushed to fix syntax. The playpen was very out of date, but has been fixed now (rust-lang/rust-playpen#215).

@zackmdavis zackmdavis force-pushed the explain_slice_pattern_errors branch from f3fa2ef to 9c1c399 Compare June 22, 2016 12:42
@zackmdavis
Copy link
Member Author

Force-pushed again because the corrected code samples were failing tests due to the lack of the #![feature(slice_patterns)] attribute. I've marked them as ignore because I had deliberately left the attribute out because it's already in the erroneous code samples just above and I want to conserve vertical terminal space for people running --explain.


Example of erroneous code:

```compile_fail
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add "E0527 flag", like this:

```compile_fail,E0527

@GuillaumeGomez
Copy link
Member

About the error code flags, take a look here for more information.

@zackmdavis
Copy link
Member Author

(added error code flags)

@GuillaumeGomez
Copy link
Member

GuillaumeGomez commented Jun 23, 2016

Everything looks good. Can you make a commit for each error code explanation please? (So 3 commits in total.)

@zackmdavis zackmdavis force-pushed the explain_slice_pattern_errors branch from 0b7d3ce to 06599b7 Compare June 30, 2016 05:01
@zackmdavis
Copy link
Member Author

@GuillaumeGomez Force-pushed with error code test directives squashed into the individual per-extended-error commits (and rebased on master). I regret the delay.

```compile_fail,E0527
#![feature(slice_patterns)]

fn main() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for main function.

@GuillaumeGomez
Copy link
Member

No problem. A few nits to fix and it should be good to go!

@bors
Copy link
Contributor

bors commented Jul 10, 2016

☔ The latest upstream changes (presumably #34365) made this pull request unmergeable. Please resolve the merge conflicts.

@bors
Copy link
Contributor

bors commented Aug 2, 2016

💣 Buildbot returned an error: <span>exceptions.KeyError</span>: <span>'auto-linux-64-opt-mir'</span>

@bors
Copy link
Contributor

bors commented Aug 2, 2016

⌛ Testing commit e960021 with merge 505842a...

@bors
Copy link
Contributor

bors commented Aug 2, 2016

💔 Test failed - auto-win-msvc-64-opt-no-mir

@alexcrichton
Copy link
Member

@bors: retry

On Tue, Aug 2, 2016 at 12:05 PM, bors notifications@github.com wrote:

💔 Test failed - auto-win-msvc-64-opt-no-mir
https://buildbot.rust-lang.org/builders/auto-win-msvc-64-opt-no-mir/builds/0


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#34319 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAD95OKkT2PEB1Ajs3mPnwK5fEXSFr3Cks5qb5T0gaJpZM4I4Fy2
.

sanxiyn added a commit to sanxiyn/rust that referenced this pull request Aug 3, 2016
…rors, r=GuillaumeGomez

extended information for slice pattern errors (E0527 through E0529)

r? @GuillaumeGomez
bors added a commit that referenced this pull request Aug 3, 2016
Rollup of 7 pull requests

- Successful merges: #34319, #35041, #35042, #35175, #35181, #35182, #35189
- Failed merges:
bors added a commit that referenced this pull request Aug 3, 2016
Rollup of 7 pull requests

- Successful merges: #34319, #35041, #35042, #35175, #35181, #35182, #35189
- Failed merges:
sophiajt pushed a commit to sophiajt/rust that referenced this pull request Aug 4, 2016
…rors, r=GuillaumeGomez

extended information for slice pattern errors (E0527 through E0529)

r? @GuillaumeGomez
steveklabnik added a commit to steveklabnik/rust that referenced this pull request Aug 4, 2016
…rors, r=GuillaumeGomez

extended information for slice pattern errors (E0527 through E0529)

r? @GuillaumeGomez
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Aug 5, 2016
…rors, r=GuillaumeGomez

extended information for slice pattern errors (E0527 through E0529)

r? @GuillaumeGomez
bors added a commit that referenced this pull request Aug 5, 2016
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Aug 5, 2016
…rors, r=GuillaumeGomez

extended information for slice pattern errors (E0527 through E0529)

r? @GuillaumeGomez
bors added a commit that referenced this pull request Aug 5, 2016
@bors bors merged commit e960021 into rust-lang:master Aug 5, 2016
@zackmdavis zackmdavis deleted the explain_slice_pattern_errors branch August 8, 2016 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants