-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1095 from alexreg/master
Added section on compatibility and subsection on raw identifiers
- Loading branch information
Showing
4 changed files
with
58 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Compatibility | ||
|
||
The Rust language is fastly evolving, and because of this certain compatibility | ||
issues can arise, despite efforts to ensure forwards-compatibility wherever | ||
possible. | ||
|
||
* [Raw identifiers](compatibility/raw_identifiers.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Raw identifiers | ||
|
||
Rust, like many programming languages, has the concept of "keywords". | ||
These identifiers mean something to the language, and so you cannot use them in | ||
places like variable names, function names, and other places. | ||
Raw identifiers let you use keywords where they would not normally be allowed. | ||
This is particularly useful when Rust introduces new keywords, and a library | ||
using an older edition of Rust has a variable or function with the same name | ||
as a keyword introduced in a newer edition. | ||
|
||
For example, consider a crate `foo` compiled with the 2015 edition of Rust that | ||
exports a function named `try`. This keyword is reserved for a new feature in | ||
the 2018 edition, so without raw identifiers, we would have no way to name the | ||
function. | ||
|
||
```rust,ignore | ||
extern crate foo; | ||
fn main() { | ||
foo::try(); | ||
} | ||
``` | ||
|
||
You'll get this error: | ||
|
||
```text | ||
error: expected identifier, found keyword `try` | ||
--> src/main.rs:4:4 | ||
| | ||
4 | foo::try(); | ||
| ^^^ expected identifier, found keyword | ||
``` | ||
|
||
You can write this with a raw identifier: | ||
|
||
```rust,ignore | ||
extern crate foo; | ||
fn main() { | ||
foo::r#try(); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters