Skip to content

Commit 9bbef9d

Browse files
author
Alexander Regueiro
committed
Added section on compatibility and subsection on raw identifiers.
1 parent e3719fc commit 9bbef9d

File tree

4 files changed

+58
-4
lines changed

4 files changed

+58
-4
lines changed

src/SUMMARY.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,10 @@
196196
- [Integration testing](testing/integration_testing.md)
197197
- [Dev-dependencies](testing/dev_dependencies.md)
198198

199+
- [Unsafe Operations](unsafe.md)
200+
201+
- [Compatibility](compatibility.md)
202+
- [Raw identifiers](compatibility/raw_identifiers.md)
203+
199204
- [Meta](meta.md)
200205
- [Documentation](meta/doc.md)
201-
202-
- [Unsafe Operations](unsafe.md)

src/compatibility.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Compatibility
2+
3+
The Rust language is fastly evolving, and because of this certain compatibility
4+
issues can arise, despite efforts to ensure forwards-compatibility wherever
5+
possible.
6+
7+
* [Raw identifiers](compatibility/raw_identifiers.md)

src/compatibility/raw_identifiers.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Raw identifiers
2+
3+
Rust, like many programming languages, has the concept of "keywords".
4+
These identifiers mean something to the language, and so you cannot use them in
5+
places like variable names, function names, and other places.
6+
Raw identifiers let you use keywords where they would not normally be allowed.
7+
This is particularly useful when Rust introduces new keywords, and a library
8+
using an older edition of Rust has a variable or function with the same name
9+
as a keyword introduced in a newer edition.
10+
11+
For example, consider a crate `foo` compiled with the 2015 edition of Rust that
12+
exports a function named `try`. This keyword is reserved for a new feature in
13+
the 2018 edition, so without raw identifiers, we would have no way to name the
14+
function.
15+
16+
```rust,ignore
17+
extern crate foo;
18+
19+
fn main() {
20+
foo::try();
21+
}
22+
```
23+
24+
You'll get this error:
25+
26+
```text
27+
error: expected identifier, found keyword `try`
28+
--> src/main.rs:4:4
29+
|
30+
4 | foo::try();
31+
| ^^^ expected identifier, found keyword
32+
```
33+
34+
You can write this with a raw identifier:
35+
36+
```rust,ignore
37+
extern crate foo;
38+
39+
fn main() {
40+
foo::r#try();
41+
}
42+
```

src/index.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ Now let's begin!
5151

5252
- [Testing](testing.html) - All sorts of testing in Rust.
5353

54-
- [Meta](meta.html) - Documentation, Benchmarking.
55-
5654
- [Unsafe Operations](unsafe.html)
5755

56+
- [Compatibility](compatibility.html)
57+
58+
- [Meta](meta.html) - Documentation, Benchmarking.
59+
5860

5961
[rust]: https://www.rust-lang.org/
6062
[install]: https://www.rust-lang.org/install.html

0 commit comments

Comments
 (0)