Skip to content

chars() iterator no longer compiling #28110

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

Closed
CodingAnarchy opened this issue Aug 30, 2015 · 2 comments
Closed

chars() iterator no longer compiling #28110

CodingAnarchy opened this issue Aug 30, 2015 · 2 comments

Comments

@CodingAnarchy
Copy link

Back a couple weeks ago, I had a program with this code here:

for ch in msg.chars() {
        if !ch.is_alphabetic() { continue; }
        let s = caesar_shift(ch, key);
        e.push(s);
    }

This code compiled just fine, where msg is an &str parameter to the function in question.

Now, having duplicated the same code with the same variable as:

for ch in msg.chars() {
            if !ch.is_alphabetic() { continue; }
            let p = ch.to_digit(36).unwrap() - 10;  // Need to shift down by 10 for range of 0-25
            let c = alpha.chars().nth(p as usize).unwrap();
            e.push(c);
        }

the compiler presents this error:

src/lib/classical.rs:163:9: 168:10 error: mismatched types:
 expected `collections::string::String`,
    found `()`
(expected struct `collections::string::String`,
    found ()) [E0308]
src/lib/classical.rs:163         for ch in msg.chars() {
src/lib/classical.rs:164             if !ch.is_alphabetic() { continue; }
src/lib/classical.rs:165             let p = ch.to_digit(36).unwrap() - 10;  // Need to shift down by 10 for range of 0-25
src/lib/classical.rs:166             let c = alpha.chars().nth(p as usize).unwrap();
src/lib/classical.rs:167             e.push(c);
src/lib/classical.rs:168         }
note: in expansion of for loop expansion
src/lib/classical.rs:163:9: 168:10 note: expansion site
src/lib/classical.rs:163:9: 168:10 help: run `rustc --explain E0308` to see a detailed explanation

This was using the nightly build in both cases:

Now: rustc 1.4.0-nightly (f3f23bf9c 2015-08-30)
Then: rustc 1.4.0-nightly (ab450ef22 2015-08-14)

Strangely, the old code does not cause the compiler to error out, but I see literally no difference in the new code to speak of that would cause it to not understand what type msg is.

@eefriedman
Copy link
Contributor

Please provide a complete example when asking questions or filing bug reports; see http://stackoverflow.com/help/mcve etc.

Please don't ask support questions on the issue tracker; you can ask on StackOverflow (http://stackoverflow.com) or the Rust discussion forum at https://users.rust-lang.org/ .

The terrible error message is tracked by #25228 .

@CodingAnarchy
Copy link
Author

Ok, it was in fact that there was no return value in a path far removed from the code in question.

But to be fair, this wasn't a support question - it's clearly an issue if the compiler looks at working code and flags it as the issue.

As the issue is already be tracked, I'll close this as a duplication of #25228.

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

2 participants