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

Returning a for loop gives confusing error message if you aren't aware that can be done #18606

Closed
mdinger opened this issue Nov 4, 2014 · 1 comment

Comments

@mdinger
Copy link
Contributor

mdinger commented Nov 4, 2014

Here the compiler complains about the for loop but the problem is that no value is being returned to the function call. This error is confusing.

fn read() -> Vec<String> {
    let data: Vec<String> = Vec::new();
    for _ in range(0i, 7i) {}
    //data
}

fn main() {
    read();
}

Returns:

<anon>:3:5: 5:2 error: mismatched types: expected `collections::vec::Vec<collections::string::String>`, found `()` (expected struct collections::vec::Vec, found ())
<anon>:3     for _ in range(0i, 7i) {}
<anon>:4     //data
<anon>:5 }
error: aborting due to previous error
playpen: application terminated with error code 101
@mdinger
Copy link
Contributor Author

mdinger commented Nov 4, 2014

Hmm...I was not aware that for _ in range(0i,7i) {} returns types (). The error makes sense once that is known so I'll close this. The only easy action against this seems to be expanded documentation about expressions.

@mdinger mdinger closed this as completed Nov 4, 2014
@mdinger mdinger changed the title Unhelpful compiler error message Returning a for loop gives confusing error message if you aren't aware that can be done Nov 4, 2014
lnicola added a commit to lnicola/rust that referenced this issue Dec 11, 2024
…ness-just-a-bit

minor: Improve soundness a bit by making `TaggedArcPtr::try_as_arc_owned()` unsafe
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

No branches or pull requests

1 participant