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

Ports and channels tutorial example code #2097

Closed
jesse99 opened this issue Apr 1, 2012 · 6 comments
Closed

Ports and channels tutorial example code #2097

jesse99 opened this issue Apr 1, 2012 · 6 comments

Comments

@jesse99
Copy link
Contributor

jesse99 commented Apr 1, 2012

Has code like comm::port::<int>() which looks odd and seems erroneous.

@marijnh
Copy link
Contributor

marijnh commented Apr 1, 2012

This is perfectly correct code, though.

@marijnh marijnh closed this as completed Apr 1, 2012
@jesse99
Copy link
Contributor Author

jesse99 commented Apr 1, 2012

It hasn't worked anywhere I have tried it. It fails with this code for example:

import comm;

fn main(args: [str])
{
let port1: comm::port = comm::port();
port1;

// get hello.rs:9:21: 5:23 error: expecting ';' but found '::'
let port2: comm::port::<int> = comm::port();
port2;

args;

}

compiled with rustc -o hello hello.rs. This is with commit:0904f255075d3c20f16d4ca2d1db14cac3fbb2de (which is a few days past 0.2).

@jesse99
Copy link
Contributor Author

jesse99 commented Apr 1, 2012

Here's the example again (github thought some of the code was markup):

import comm;

fn main(args: [str]) 
{
    let port1: comm::port<int> = comm::port();
    port1;

    // get hello.rs:9:21: 5:23 error: expecting ';' but found '::'
    let port2: comm::port::<int> = comm::port();
    port2;

    args;
}```

@marijnh
Copy link
Contributor

marijnh commented Apr 1, 2012

That's not code from the tutorial, is it?

In value expressions (comm::port::<int>()), type parameters have to be prefixed with :: to prevent ambiguity with the < operator. In type expressions (such as : comm::port<int>), they shouldn't be.

We are aware of the fact that this is confusing (I think there's a bug open on it, though I can't find it just now), but we haven't been able to find a satisfactory alternative.

@jesse99
Copy link
Contributor Author

jesse99 commented Apr 2, 2012

No, that code wasn't from the tutorial. And, yes the difference is confusing, especially because the tutorial doesn't point out the distinction. Not sure if the reference manual does. I spent a few minutes looking and didn't find anything.

@marijnh
Copy link
Contributor

marijnh commented Apr 2, 2012

For what it's worth, section 8.3 of the tutorial does point out this distinction.

bors added a commit to rust-lang-ci/rust that referenced this issue Sep 22, 2022
Format tests and benches with rustfmt (1-50 of 300)

Extracted from rust-lang#2097.

I filtered this PR to contain exclusively "easy" cases to start off with, i.e. where there is no compiletest_rs (or other) comment in the vicinity that might need to get manually repositioned.
bors added a commit to rust-lang-ci/rust that referenced this issue Sep 22, 2022
Format tests with rustfmt (101-150 of 300)

Extracted from rust-lang#2097.

Like rust-lang/miri#2244, these are "easy" cases that do not involve moving around comments.
bors added a commit to rust-lang-ci/rust that referenced this issue Sep 22, 2022
Format tests with rustfmt (51-100 of 300)

Extracted from rust-lang#2097.

Like rust-lang#2244, this is intended to be "easy" cases which don't involve comments in the vicinity.
bors added a commit to rust-lang-ci/rust that referenced this issue Sep 22, 2022
Format tests with rustfmt (151-200 of 300)

Extracted from rust-lang#2097.

This PR is still only doing the easy cases with no comments involved.

In the next PRs after this, I'll start grouping by common comment patterns, e.g. all the cases resembling rust-lang/miri#2097 (comment) together in one PR.
bors added a commit to rust-lang-ci/rust that referenced this issue Sep 22, 2022
Format tests with rustfmt (201-224 of 300)

Extracted from rust-lang#2097. Last of the easy cases which do not involve moving around a comment.
bors added a commit to rust-lang-ci/rust that referenced this issue Sep 22, 2022
Format tests with rustfmt (276-287 of 299)

Extracted from rust-lang#2097.

This is one half of the last 24 files (left for last because they require more unique attention than the first 275 "easy" files).

I'll comment below to call attention to cases where I exercised my own judgement in how to format the test.

rust-lang/rustfmt#3255 is especially annoying: rustfmt does not like `…( //` and `…{ //`.
bors added a commit to rust-lang-ci/rust that referenced this issue Sep 22, 2022
Format tests with rustfmt (225-275 of 300)

Extracted from rust-lang#2097.

These cases all involve a line comment at the end of a block that rustfmt has chosen to wrap.

```diff
- unsafe { (*ptr).set(20); } //~ ERROR does not exist in the borrow stack
+ unsafe {
+     (*ptr).set(20);
+ } //~ ERROR does not exist in the borrow stack
```

I have moved all of those comments back onto the same line as the content of the block instead, as was indicated being `@RalfJung's` preference in rust-lang/miri#2097 (comment).

```diff
+ unsafe {
+     (*ptr).set(20); //~ ERROR does not exist in the borrow stack
+ }
```
bors added a commit to rust-lang-ci/rust that referenced this issue Sep 22, 2022
Format tests with rustfmt (288-299 of 299)

Extracted from rust-lang#2097.

I'll make a separate PR to enable checking the `tests` directory's formatting in CI. I'll need to rebase that after both this and rust-lang#2254 have landed, and if any new non-rustfmt-formatted files appear in the meantime, we can include formatting those in the same PR that enables the CI.
celinval pushed a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
Co-authored-by: Zyad Hassan <88045115+zhassan-aws@users.noreply.github.com>
Kobzol pushed a commit to Kobzol/rust that referenced this issue Dec 30, 2024
bors pushed a commit to rust-lang-ci/rust that referenced this issue Jan 2, 2025
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