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

"Hello World" example in tutorial doesn't compile #3304

Closed
toolness opened this issue Aug 30, 2012 · 9 comments
Closed

"Hello World" example in tutorial doesn't compile #3304

toolness opened this issue Aug 30, 2012 · 9 comments

Comments

@toolness
Copy link

It seems the Hello World example in the tutorial doesn't compile.

Pasting the following code into a file called hello.rs:

fn main(args: ~[~str]) {
    io::println(~"hello world from '" + args[0] + ~"'!");
}

and then running rustc hello.rs returns the following:

hello.rs:2:40: 2:46 error: mismatched types: expected `str/&<R0>` but found `~str` (str/&<R0> vs ~-ptr)
hello.rs:2     io::println(~"hello world from '" + args[0] + ~"'!");
                                                   ^~~~~~
hello.rs:2:50: 2:55 error: mismatched types: expected `str/&<R1>` but found `~str` (str/&<R1> vs ~-ptr)
hello.rs:2     io::println(~"hello world from '" + args[0] + ~"'!");
                                                             ^~~~~
hello.rs:1:0: 1:0 error: Wrong type in main function: found `extern fn(~[~str])`, expecting `extern fn(~[str]) -> ()` or `extern fn() -> ()`
hello.rs:1 fn main(args: ~[~str]) {
           ^
error: aborting due to 3 previous errors

I don't know rust, so I'm not sure what's wrong here or whether the fault is on my end. Any help is appreciated!

@nikomatsakis
Copy link
Contributor

I think you are working with an older version of rust (perhaps 0.3.1?), but using the tutorial that targets the most recent version of Rust. The syntax for strings changed in the meantime: in 0.3.1, no ~ was needed. In the current git version, a ~ is needed (if you read further on in the tutorial, it discusses the distinction between ~ values---which cannot be aliased and can be sent between tasks---and @ values, which are local to a specific task but can be aliased freely).

@pcwalton
Copy link
Contributor

Closing.

@toolness
Copy link
Author

Ah, thanks @nikomatsakis.

I wonder, then, if it may be useful to definitively mention the version of Rust that should be used in the tutorial? Right now it seems to indicate that version 0.3.x should be used, since the Installation Section uses wget to retrieve the 0.3 tarball and the "badge" at the bottom-right of the documentation window mentions Rust 0.3.1. Should I file a separate issue for that?

@AngryLawyer
Copy link

I agree with @toolness - I had a similar issue when starting as it wasn't clear that the tutorial was using the latest from the repo, as opposed to the last packaged release.

@brson
Copy link
Contributor

brson commented Aug 30, 2012

What would be a good way to indicate that the tutorial refers to an in-development version? We can bump the version to next (0.4), and possibly tag it with something like '0.4-dev'. I'm not sure how feasible it is to change the installation text based on whether the tutorial is for an in-development or released version.

Possibly in the introductory text too we can explicitly say the version number.

@nikomatsakis
Copy link
Contributor

It seems like bumping the version number so that it reflects the next version and not the last one would be helpful.

@brson
Copy link
Contributor

brson commented Aug 30, 2012

OK. I'll bump the version number today.

@toolness
Copy link
Author

Awesome, thanks @brson!

Another slightly more future-proof alternative is to just have a disclaimer at the beginning of the docs that says it's for the tip of the dev branch, so that readers know to use that when in doubt. Presumably the installation docs would wget https://github.com/mozilla/rust/tarball/master instead of a specific versioned tarball.

Anyhow, just another idea though. Thanks for bumping the version number!

@brson
Copy link
Contributor

brson commented Aug 30, 2012

OK, the version is bumped on incoming. The new docs won't show up until incoming gets promoted to master. Could be a few days. This is all I plan on doing on this matter for now, so if anybody strongly wants some of these other good ideas implemented I suggest opening new issues.

RalfJung pushed a commit to RalfJung/rust that referenced this issue Feb 25, 2024
jaisnan pushed a commit to jaisnan/rust-dev that referenced this issue Jul 29, 2024
The rust type inference for closures doesn't work in the particular use
case we are using it for ensures clauses. By creating a helper function,
we change the path the rust type inference takes and lets the type of
the closure be identified properly. This means type annotations are no
longer required within ensures clauses.

Resolves rust-lang#3304

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 and MIT licenses.
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

5 participants