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

Adds a simple exercise for structures #163

Merged
merged 1 commit into from
May 25, 2019
Merged

Conversation

briankung
Copy link
Contributor

@briankung briankung commented May 25, 2019

Thanks for rustlings! Here's a small contribution in return.

Copy link
Contributor

@komaeda komaeda left a comment

Choose a reason for hiding this comment

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

thank you!

@komaeda
Copy link
Contributor

komaeda commented May 25, 2019

@bors r+

@bors
Copy link
Contributor

bors commented May 25, 2019

📌 Commit 9b92aa0 has been approved by komaeda

@bors
Copy link
Contributor

bors commented May 25, 2019

⌛ Testing commit 9b92aa0 with merge 1f07fd4...

bors added a commit that referenced this pull request May 25, 2019
Adds a simple exercise for structures

Thanks for rustlings! Here's a small contribution in return.
@bors
Copy link
Contributor

bors commented May 25, 2019

☀️ Test successful - checks-travis
Approved by: komaeda
Pushing 1f07fd4 to master...

@bors bors merged commit 9b92aa0 into rust-lang:master May 25, 2019
@briankung briankung deleted the add_structs branch May 25, 2019 14:00
@edmundmiller
Copy link

I'm having an issue with this. I'm not sure if correct answers should be discussed here or not. It may also be because of my lack of experience.

    #[test]
    fn unit_structs() {
        // TODO: Instantiate a unit struct!
        let green = ColorUnitStruct;

        if let ColorUnitStruct = green {
            assert!(true);
        } else {
            assert!(false);
        }
    }

Results in

error[E0162]: irrefutable if-let pattern
  --> exercises/structs/structs1.rs:41:16
   |
41 |         if let ColorUnitStruct = green {
   |                ^^^^^^^^^^^^^^^ irrefutable pattern

@briankung
Copy link
Contributor Author

@emiller88 would you mind sharing that entire test?

@edmundmiller
Copy link

@briankung Sorry I should have mentioned it's in the exercises/structs/structs1.rs file
https://github.com/briankung/rustlings/blob/9b92aa08aead17d7737137f1c5c382548797b83e/exercises/structs/structs1.rs

@briankung
Copy link
Contributor Author

@emiller88 I understand, sorry I must have had a brain fart (or there was an edit to your comment) but I didn't think I had the entirety of your failing test case. What version of Rust are you using?

@edmundmiller
Copy link

@briankung rustc 1.32.0-nightly (14997d56a 2018-12-05)

@briankung
Copy link
Contributor Author

Weird. Well, seeing as I'm a Rust newbie myself, I can't really say why this doesn't work on your machine. It does seem to make sense - after all once it knows the type of green, it will always match.

You can try throwing a #[allow(irrefutable_let_patterns)] at the top of the test function. Just to be clear, are you using $ rustlings run exercises/structs/struct1.rs to run this? And have you run the rustlings command on other exercises? For whatever reason, it seems to allow irrefutable let patterns by default for me (rustc 1.37.0-nightly (02564de47 2019-06-10)) as well as dead code in a bunch of exercises.

@edmundmiller
Copy link

I was using rustlings watch but it doesn't work with rustlings run exercises/structs/struct1.rs either.

#[allow(irrefutable_let_patterns)] doesn't help either.

@briankung
Copy link
Contributor Author

Odd. Unlikely to be related, but what OS are you using? I'm also confused why the allow attribute doesn't work since it works in the playground. And your test looks like the below?

    #[test]
    #[allow(irrefutable_let_patterns)]
    fn unit_structs() {
        // ...
    }

@edmundmiller
Copy link

Yes it did, the #[allow(irrefutable_let_patterns)] works in the playground however without it the test still fails so I think it's an issue.

@briankung
Copy link
Contributor Author

briankung commented Jun 11, 2019 via email

@edmundmiller
Copy link

Does this playground work for you? It's exactly what's in the exercises/structs/structs1.rs
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=b94d896c7d1c19918dc58edceae3ff77

@briankung
Copy link
Contributor Author

briankung commented Jun 11, 2019 via email

@edmundmiller
Copy link

Ah I didn't see it was a warning in the playground. When it runs with a test(At least in my version) the warning turns into an error when the test runs. If it's just unique to my version I think we're good here.

@ksceriath
Copy link

I am using
rustc 1.32.0 (9fda7c223 2019-01-16)

Facing the same issue as @emiller88 above. This doesn't appear to be machine specific. I feel we should modify the test around this, else 'rustlings watch' will not function.

@ksceriath
Copy link

This doesn't error after updating to rustc 1.35.0 (3c235d560 2019-05-20)

@briankung
Copy link
Contributor Author

briankung commented Jun 20, 2019

It seems odd that it would error in one but not the other. I think the test should change, it's just especially odd that something like an irrefutable let pattern would change from version to version of Rust.

@ksceriath does the #[allow(irrefutable_let_patterns)] allow it to compile without errors? I think you can use this snippet to override the toolchain in a particular directory:

$ rustup override set 1.32.0

From: https://doc.rust-lang.org/stable/edition-guide/rust-2018/rustup-for-managing-rust-versions.html#managing-versions)

I'm trying it myself, as well. Hopefully it does the same for rustlings.

@briankung
Copy link
Contributor Author

@emiller88 and @ksceriath I've opened #179, please take a look and see if those changes work for you. Sorry for the inconvenience!

bors added a commit that referenced this pull request Jun 20, 2019
…r=komaeda

Fixes the irrefutable let pattern warning in `structs1.rs`

PR #163 accidentally introduced an error using some versions of the Rust compiler where the compiler would (rightly!) complain about an irrefutable let pattern. I have no idea why this did not occur in all versions of the compiler, but here is a way around it.
@ksceriath
Copy link

@briankung This works with 1.32 / 1.35. Thank you!

@edmundmiller
Copy link

@briankung Works on both for me as well thanks for fixing it!

@extrawurst
Copy link

going through the tests one by one, i am wondering why this is the first that has no help to scroll down to. even the link to the docs makes this exercise suddenly much harder than the previous

cedrickchee pushed a commit to cedrickchee/rustlings-solutions that referenced this pull request Nov 15, 2019
…r=komaeda

Fixes the irrefutable let pattern warning in `structs1.rs`

PR rust-lang/rustlings#163 accidentally introduced an error using some versions of the Rust compiler where the compiler would (rightly!) complain about an irrefutable let pattern. I have no idea why this did not occur in all versions of the compiler, but here is a way around it.
pedantic79 pushed a commit to pedantic79/rustlings that referenced this pull request Apr 11, 2020
Adds a simple exercise for structures

Thanks for rustlings! Here's a small contribution in return.
panthervis added a commit to panthervis/rustlings that referenced this pull request Oct 8, 2021
…r=komaeda

Fixes the irrefutable let pattern warning in `structs1.rs`

PR rust-lang/rustlings#163 accidentally introduced an error using some versions of the Rust compiler where the compiler would (rightly!) complain about an irrefutable let pattern. I have no idea why this did not occur in all versions of the compiler, but here is a way around it.
ppp3 pushed a commit to ppp3/rustlings that referenced this pull request May 23, 2022
Adds a simple exercise for structures

Thanks for rustlings! Here's a small contribution in return.
ppp3 pushed a commit to ppp3/rustlings that referenced this pull request May 23, 2022
…tructs1, r=komaeda

Fixes the irrefutable let pattern warning in `structs1.rs`

PR rust-lang#163 accidentally introduced an error using some versions of the Rust compiler where the compiler would (rightly!) complain about an irrefutable let pattern. I have no idea why this did not occur in all versions of the compiler, but here is a way around it.
FancyGeekGuru added a commit to FancyGeekGuru/rust-lings that referenced this pull request May 24, 2022
…r=komaeda

Fixes the irrefutable let pattern warning in `structs1.rs`

PR rust-lang/rustlings#163 accidentally introduced an error using some versions of the Rust compiler where the compiler would (rightly!) complain about an irrefutable let pattern. I have no idea why this did not occur in all versions of the compiler, but here is a way around it.
dmoore04 pushed a commit to dmoore04/rustlings that referenced this pull request Sep 11, 2022
Adds a simple exercise for structures

Thanks for rustlings! Here's a small contribution in return.
dmoore04 pushed a commit to dmoore04/rustlings that referenced this pull request Sep 11, 2022
…tructs1, r=komaeda

Fixes the irrefutable let pattern warning in `structs1.rs`

PR rust-lang#163 accidentally introduced an error using some versions of the Rust compiler where the compiler would (rightly!) complain about an irrefutable let pattern. I have no idea why this did not occur in all versions of the compiler, but here is a way around it.
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.

None yet

6 participants