Skip to content

Introduces a "Syntax Index" chapter to TRPL. #28926

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

Merged
merged 3 commits into from
Oct 9, 2015

Conversation

DanielKeep
Copy link
Contributor

The intent with this chapter is to have a central place where users can
go to find out what a random bit of syntax means, be it a keyword,
symbol, or some unusual bit of composite syntax (like for <...>). This
should be useful both for new users (who may not know what to call this
weird 'blah thing), and for experienced users (who may just wish to
link someone to the appropriate section on Trait + Trait bounds).

Where possible, entries have been linked to an appropriate section of
the book which explains the syntax. This was not possible in all cases.
If an entry is missing links, that's because I was unable to find
anything appropriate to link to.

This commit should include all stable keywords, operators and symbols,
as well as a selection of potentially confusing or unusual syntax.

The intent with this chapter is to have a central place where users can
go to find out what a random bit of syntax means, be it a keyword,
symbol, or some unusual bit of composite syntax (like `for <...>`).  This
should be useful both for new users (who may not know what to call this
weird `'blah` thing), and for experienced users (who may just wish to
link someone to the appropriate section on `Trait + Trait` bounds).

Where possible, entries have been linked to an appropriate section of
the book which explains the syntax.  This was not possible in all cases.
If an entry is missing links, that's because I was unable to *find*
anything appropriate to link to.

This commit should include all stable keywords, operators and symbols,
as well as a selection of potentially confusing or unusual syntax.
@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @pcwalton (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@killercup
Copy link
Member

This is great! When I was beginning to learn Rust I wished there was a list like this. (The reference is a bit long to easily search for stuff.)

<!-- Generics -->

* `path<…>`: specifies parameters to generic type *in a type*. See [Generics].
* `path::<…>`: specifies parameters to generic type or function *in an expression*.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe expand the example a bit to show this can be used for functions, e.g. "42".parse::<u32>().

* Now mentions method generics.
* Has separate entries for generic `fn`, `struct`, `enum`, and `impl`
  items.

(Thanks killercup).
@steveklabnik
Copy link
Member

I like it. Thanks!

@steveklabnik
Copy link
Member

@bors: r+ rollup

@bors
Copy link
Collaborator

bors commented Oct 9, 2015

📌 Commit b78614f has been approved by steveklabnik

@bors
Copy link
Collaborator

bors commented Oct 9, 2015

⌛ Testing commit b78614f with merge 54f8381...

* `match`: pattern matching. See [Match].
* `mod`: module declaration. See [Crates and Modules (Defining Modules)].
* `move`: part of closure syntax. See [Closures (`move` closures)].
* `mut`: denotes mutability in pointer types, pattern bindings, and `struct` fields. See [Mutability].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/, and struct fields//

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stares Well, that's embarrassing.

@petrochenkov
Copy link
Contributor

When I was beginning to learn Rust I wished there was a list like this.

+1, this is very useful

* removed reference to struct fields from `mut` description.
* changed `..` pattern example to not be syntactically bogus.
* changed `@` pattern example for similar reasons.

(Thanks petrochenkov)
@DanielKeep
Copy link
Contributor Author

@steveklabnik I made some changes prompted by @petrochenkov's comments; hope that doesn't stuff anything up. Good bors pats

@steveklabnik
Copy link
Member

@bors: r+ rollup

@bors
Copy link
Collaborator

bors commented Oct 9, 2015

📌 Commit 2b59834 has been approved by steveklabnik

@aochagavia
Copy link
Contributor

Would it be worth it to add keywords that are reserved but not used (like virtual)?

@DanielKeep
Copy link
Contributor Author

@aochagavia I decided against it on the basis that doing so can only confuse things. Such keywords can't show up in existing code and can't be used in new code. It'd be a bit like having keywords from unrelated languages with the note "not used in Rust at all in any way".

That said, it just occurred to me that you could make an argument for obsolete syntax. We do have a bit of an issue with old code examples, so maybe it'd be worth listing old syntax at the end. But not in this PR. I don't want to create even more work for poor old Bors. throws Bors a cookie

@TyOverby
Copy link
Contributor

TyOverby commented Oct 9, 2015

! (expr!(…), expr!{…}, expr![…]): denotes macro expansion. See Macros.'

Shouldn't those be "ident" not "expr"?

@Gankra
Copy link
Contributor

Gankra commented Oct 9, 2015

@DanielKeep I'd be interested in noting reserved (and deprecated) things, as code doesn't clearly indicate what version it works with. If you see <- and the docs you check don't mention it, you're just left going ????. But if you see it's reserved, that's an indication you need newer docs.

@bors
Copy link
Collaborator

bors commented Oct 9, 2015

⌛ Testing commit 2b59834 with merge d0813b9...

@Diggsey
Copy link
Contributor

Diggsey commented Oct 9, 2015

for seems to link to "method syntax", which has no explanation of higher ranked lifetime syntax (or any other kind of "for")

@DanielKeep
Copy link
Contributor Author

@gankro My concern was that, for example, it's possible that in is going to change to <-, which would make old docs just as useless as not having anything for that. I'd contend that if you see syntax that's not in the index, then of course you need newer docs.

Maybe there's a use for stuff in nightly that hasn't made it to stable yet, though.

@DanielKeep
Copy link
Contributor Author

@Diggsey That's because I couldn't find any documentation on higher ranked lifetime syntax in the book.

@bors
Copy link
Collaborator

bors commented Oct 9, 2015

💔 Test failed - auto-mac-32-opt

@steveklabnik
Copy link
Member

Yes, there's a bug open for adding HRTB

@alexcrichton
Copy link
Member

@bors: retry

On Fri, Oct 9, 2015 at 10:47 AM, Steve Klabnik [email protected]
wrote:

Yes, there's a bug open for adding HRTB


Reply to this email directly or view it on GitHub
#28926 (comment).

@supr
Copy link
Contributor

supr commented Oct 9, 2015

@DanielKeep nice work 👍. Love it, would end up helping a lot when searching for syntax information quickly.

@Gankra
Copy link
Contributor

Gankra commented Oct 9, 2015

@Diggsey it just seems like all that needs to be done for that is to note when syntax is unstable, no?

Edit: there's a degenerate case, I suppose, where syntax is used unstably and then repurposed.

@Diggsey
Copy link
Contributor

Diggsey commented Oct 9, 2015

@gankro The for<'a> syntax isn't unstable though? (At least it works on stable rust!)

bors added a commit that referenced this pull request Oct 9, 2015
The intent with this chapter is to have a central place where users can
go to find out what a random bit of syntax means, be it a keyword,
symbol, or some unusual bit of composite syntax (like `for <...>`).  This
should be useful both for new users (who may not know what to call this
weird `'blah` thing), and for experienced users (who may just wish to
link someone to the appropriate section on `Trait + Trait` bounds).

Where possible, entries have been linked to an appropriate section of
the book which explains the syntax.  This was not possible in all cases.
If an entry is missing links, that's because I was unable to *find*
anything appropriate to link to.

This commit should include all stable keywords, operators and symbols,
as well as a selection of potentially confusing or unusual syntax.
@bors
Copy link
Collaborator

bors commented Oct 9, 2015

⌛ Testing commit 2b59834 with merge 7dcc4d7...

@Gankra
Copy link
Contributor

Gankra commented Oct 9, 2015

@Diggsey sorry I meant to ping @DanielKeep

(dang tab completion!)

@bors bors merged commit 2b59834 into rust-lang:master Oct 9, 2015
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

Successfully merging this pull request may close these issues.