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

Bad for loop #6972

Merged
merged 2 commits into from
Jun 6, 2013
Merged

Bad for loop #6972

merged 2 commits into from
Jun 6, 2013

Conversation

artagnon
Copy link
Contributor

@artagnon artagnon commented Jun 6, 2013

I noticed this while reading the tutorial.

[1/2] adds tests to guard against regressions.
[2/2] corrects the tutorial.

Please let me know if you have a standard place to put tests: they seem to be all over the place currently.

There are two distinct kinds of bad-for-loops to check for with two
distinct error messages.  The current bad-for-loop.rs does not make this
clear, so rewrite it into bad-for-loop{,-2}.rs.  The two failing
prototypes are:

  fn quux(_: &fn(&int) -> int) -> bool { true }
  fn quux(_: &fn(&int) -> bool) -> () { }

Note that the second one runs fine in rust-0.6 (the latest release), and
only fails with a rust built from `incoming`.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
Although in the example function `each` works as expected with
rust-0.6 (the latest release), it fails to even compile with `incoming`
rust (see test/compile-fail/bad-for-loop-2.rs). Change the function to
return a `bool` instead of `()`: this works fine with both versions of
rust, and does not misguide potential contributors.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
bors added a commit that referenced this pull request Jun 6, 2013
I noticed this while reading the tutorial.

[1/2] adds tests to guard against regressions.
[2/2] corrects the tutorial.

Please let me know if you have a standard place to put tests: they seem to be all over the place currently.
@bors bors closed this Jun 6, 2013
@bors bors merged commit dd923e3 into rust-lang:incoming Jun 6, 2013
@artagnon artagnon deleted the bad-for-loop branch June 6, 2013 15:39
flip1995 pushed a commit to flip1995/rust that referenced this pull request Apr 8, 2021
`len_without_is_empty` improvements

fixes: rust-lang#6958
fixes: rust-lang#6972

changelog: Check the return type of `len`. Only integral types, or an `Option` or `Result` wrapping one.
changelog: Ensure the return type of `is_empty` matches. e.g. `Option<usize>` -> `Option<bool>`
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.

2 participants