Skip to content

Add 2018 edition keywords. #442

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 1 commit into from
Oct 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/keywords.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ be used as the names of:
> KW_WHERE : `where`\
> KW_WHILE : `while`

The following keywords were added beginning in the 2018 edition.

> **<sup>Lexer 2018+</sup>**\
> KW_DYN : `dyn`

## Reserved keywords

These keywords aren't used yet, but they are reserved for future use. They have
Expand All @@ -78,6 +83,13 @@ them to use these keywords.
> KW_VIRTUAL : `virtual`\
> KW_YIELD : `yield`

The following keywords are reserved beginning in the 2018 edition.

> **<sup>Lexer 2018+</sup>**\
> KW_ASYNC : `async`\
> KW_AWAIT : `await`\
> KW_TRY : `try`

## Weak keywords

These keywords have special meaning only in certain contexts. For example, it
Expand All @@ -92,12 +104,16 @@ is possible to declare a variable or method with the name `union`.
// error[E0262]: invalid lifetime parameter name: `'static`
fn invalid_lifetime_parameter<'static>(s: &'static str) -> &'static str { s }
```
* `dyn` denotes a [trait object] and is a keyword when used in a type position
* In the 2015 edition, [`dyn`] is a keyword when used in a type position
followed by a path that does not start with `::`.

Beginning in the 2018 edition, `dyn` has been promoted to a strict keyword.

> **<sup>Lexer</sup>**\
> KW_UNION : `union`\
> KW_STATICLIFETIME : `'static`\
> KW_STATICLIFETIME : `'static`
>
> **<sup>Lexer 2015</sup>**\
> KW_DYN : `dyn`

[items]: items.html
Expand All @@ -110,4 +126,4 @@ is possible to declare a variable or method with the name `union`.
[Crates]: crates-and-source-files.html
[union]: items/unions.html
[variants]: items/enumerations.html
[trait object]: types.html#trait-objects
[`dyn`]: types.html#trait-objects
13 changes: 8 additions & 5 deletions src/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -676,11 +676,14 @@ For example, given a trait `Trait`, the following are all trait objects:
* `dyn 'static + Trait`.
* `dyn (Trait)`

If the first bound of the trait object is a path that starts with `::`, then the
`dyn` will be treated as a part of the path. The first path can be put in
parenthesis to get around this. As such, if you want a trait object with the
trait `::your_module::Trait`, you should write it as
`dyn (::your_module::Trait)`.
> **Edition Differences**: In the 2015 edition, if the first bound of the
> trait object is a path that starts with `::`, then the `dyn` will be treated
> as a part of the path. The first path can be put in parenthesis to get
> around this. As such, if you want a trait object with the trait
> `::your_module::Trait`, you should write it as `dyn (::your_module::Trait)`.
>
> Beginning in the 2018 edition, `dyn` is a true keyword and is not allowed in
> paths, so the parentheses are not necessary.

> Note: For clarity, it is recommended to always use the `dyn` keyword on your
> trait objects unless your codebase supports compiling with Rust 1.26 or lower.
Expand Down