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

Confusing error when using do instead of for #2817

Closed
brson opened this issue Jul 5, 2012 · 5 comments
Closed

Confusing error when using do instead of for #2817

brson opened this issue Jul 5, 2012 · 5 comments
Labels
A-typesystem Area: The type system E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Milestone

Comments

@brson
Copy link
Contributor

brson commented Jul 5, 2012

Range should have been called with for

./uuid.rs:90:41: 99:9 error: mismatched types: expected `bool` but found `()` (bool vs ())
./uuid.rs:90         do uint::range(0u, 100000u) |_i| {
./uuid.rs:91             let uuid = uuid();
./uuid.rs:92             assert uuid == from_str(to_str(uuid));
./uuid.rs:93
./uuid.rs:94             let uuid = uuid_random();
./uuid.rs:95             assert uuid == from_str(to_str(uuid));
@kud1ing
Copy link

kud1ing commented Jul 6, 2012

If we'd remove the do-expression and rename for to do, what would we lose?

@brson
Copy link
Contributor Author

brson commented Jul 6, 2012

@Lenny222 for only handles functions where the operator is a stack closure returning bool. Things like map and spawn won't work with it.

We could possibly have one keyword that just does the right thing based on the closure type. do x.each { doesn't sound so bad. for spawn { isn't great.

@kud1ing
Copy link

kud1ing commented Jul 6, 2012

Having only a do "do"-ing the right thing sounds like a win.

@bblum
Copy link
Contributor

bblum commented Jul 8, 2012

Seems like the typechecker should attempt to see if "for" would have been the right thing, and said "Did you mean 'for'?". (Same for the other way around.)

@pcwalton
Copy link
Contributor

pcwalton commented Sep 6, 2012

@Lenny222 I feel like that would be too magical. Silently inserting the equivalent of return true at the end of a lambda, without a special form to indicate this is happening, doesn't sit right with me.

@ghost ghost assigned catamorphism Nov 24, 2012
catamorphism added a commit to catamorphism/rust that referenced this issue Dec 8, 2012
If a do-block body has the wrong type, or a for-loop body has a
non-() type, suggest that the user might have meant the other one.

As per rust-lang#2817
saethlin pushed a commit to saethlin/rust that referenced this issue Mar 16, 2023
rustup

Doing a sync just before I do a rustc-push
celinval added a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
Update rust toolchain to 2023-10-16 and update failing test.

The coverage test was failing because the logic was being pruned by
rustup.

Resolves rust-lang#2817
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-typesystem Area: The type system E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

No branches or pull requests

5 participants