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

if2 exercise and option1 fix #383

Merged
merged 2 commits into from May 3, 2020

Conversation

wrobstory
Copy link
Contributor

This PR implements two things:

  1. A new if2 exercise that shows the type of compiler message you get if your conditional branches don't return the same type as well as the usage of else if
  2. A small change to the option1 exercise that I think makes it very confusing (no problem dropping this one if there's disagreement here).

@@ -18,6 +18,6 @@ fn main() {
((iter * 5) + 2) / (4 * 16)
};

numbers[iter] = number_to_add;
numbers[iter as usize] = number_to_add;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Happy to discuss this; here's the compiler message you get:

21 |         numbers[iter] = number_to_add;
   |         ^^^^^^^^^^^^^ slice indices are of type `usize` or ranges of `usize`
   |
   = help: the trait `std::slice::SliceIndex<[std::option::Option<u16>]>` is not implemented for `u16`
   = note: required because of the requirements on the impl of `std::ops::Index<u16>` for `[std::option::Option<u16>]`

The message makes it sound like it could have something to do with a SliceIndex of Option, but really this is about the type of the slice index. While this is certainly a learning opportunity, it's not one that has anything to do with Option usage.

I don't feel super strongly about it, but it was the place I got stuck the longest in the exercises!

Copy link
Contributor

Choose a reason for hiding this comment

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

as the creator of the option1 exercise, you are correct and this change looks good. Looks like I forgot to add the "as usize" myself

@shadows-withal shadows-withal merged commit 3ceabe9 into rust-lang:master May 3, 2020
@wrobstory
Copy link
Contributor Author

Thanks all!

@shadows-withal
Copy link
Member

@all-contributors add @wrobstory for code

@allcontributors
Copy link
Contributor

@fmoko

I've put up a pull request to add @wrobstory! 🎉

ppp3 pushed a commit to ppp3/rustlings that referenced this pull request May 23, 2022
dmoore04 pushed a commit to dmoore04/rustlings that referenced this pull request Sep 11, 2022
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

3 participants