[rust-dev] Broken tutorial code?

Josh Leverette coder543 at gmail.com
Wed Jul 10 14:37:27 PDT 2013


I'm kinda working my way through The Rust Language
Tutorial<http://static.rust-lang.org/doc/0.7/tutorial.html>,
and the sample in section 4.3 "Loops" seems broken.

The code is as follows.

let mut x = 5;loop {
    x += x - 3;
    if x % 5 == 0 { break; }
    println(int::to_str(x));
}


If I wrap my main function around this code, it won't compile because it
says that int::to_str(x) is unresolved. Specifically...

test.rs:7:12: 7:23 error: unresolved name
test.rs:7     println(int::to_str(x));
                      ^~~~~~~~~~~
test.rs:7:12: 7:23 error: use of undeclared module `int`
test.rs:7     println(int::to_str(x));
                      ^~~~~~~~~~~
test.rs:7:12: 7:23 error: unresolved name `int::to_str`.
test.rs:7     println(int::to_str(x));


If I try changing it to x.to_str(), then it gets upset because x's type is
ambiguous and it can't decide between all of the many numeric types as to
which one should receive the to_str() call.

I fixed it by declaring "x" to be an int and then just saying x.to_str()...
but why was int::to_str unresolved?

-- 
Sincerely,
    Josh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20130710/1c96024e/attachment.html>


More information about the Rust-dev mailing list