Skip to content
22 changes: 11 additions & 11 deletions src/attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ apply to the item that follows the attribute.

An example of attributes:

```{.rust}
```rust
// General metadata applied to the enclosing module or crate.
#![crate_type = "lib"]

Expand Down Expand Up @@ -164,8 +164,8 @@ macro scope.

## Miscellaneous attributes

- `deprecated` - mark the item as deprecated; the full attribute is
`#[deprecated(since = "crate version", note = "...")`, where both arguments
- `deprecated` - mark the item as deprecated; the full attribute is
`#[deprecated(since = "crate version", note = "...")`, where both arguments
are optional.
- `export_name` - on statics and functions, this determines the name of the
exported symbol.
Expand Down Expand Up @@ -218,7 +218,7 @@ Configuration options are either provided by the compiler or passed in on the
command line using `--cfg` (e.g. `rustc main.rs --cfg foo --cfg 'bar="baz"'`).
Rust code then checks for their presence using the `#[cfg(...)]` attribute:

```
```rust
// The function is only included in the build when compiling for macOS
#[cfg(target_os = "macos")]
fn macos_only() {
Expand Down Expand Up @@ -320,7 +320,7 @@ along with their default settings. [Compiler
plugins](../unstable-book/plugin.html#lint-plugins) can provide additional
lint checks.

```{.ignore}
```rust,ignore
pub mod m1 {
// Missing documentation is ignored here
#[allow(missing_docs)]
Expand All @@ -339,7 +339,7 @@ pub mod m1 {
This example shows how one can use `allow` and `warn` to toggle a particular
check on and off:

```{.ignore}
```rust
#[warn(missing_docs)]
pub mod m2{
#[allow(missing_docs)]
Expand All @@ -361,7 +361,7 @@ pub mod m2{
This example shows how one can use `forbid` to disallow uses of `allow` for
that lint check:

```{.ignore}
```rust,ignore
#[forbid(missing_docs)]
pub mod m3 {
// Attempting to toggle warning signals an error here
Expand All @@ -379,7 +379,7 @@ operations have to be easy for the compiler to find. The `lang` attribute
makes it possible to declare these operations. For example, the `str` module
in the Rust standard library defines the string equality function:

```{.ignore}
```rust,ignore
#[lang = "str_eq"]
pub fn eq_slice(a: &str, b: &str) -> bool {
// details elided
Expand Down Expand Up @@ -419,7 +419,7 @@ for data structures. For example, the following will create an `impl` for the
`PartialEq` and `Clone` traits for `Foo`, the type parameter `T` will be given
the `PartialEq` or `Clone` constraints for the appropriate `impl`:

```
```rust
#[derive(PartialEq, Clone)]
struct Foo<T> {
a: i32,
Expand All @@ -429,7 +429,7 @@ struct Foo<T> {

The generated `impl` for `PartialEq` is equivalent to

```
```rust
# struct Foo<T> { a: i32, b: T }
impl<T: PartialEq> PartialEq for Foo<T> {
fn eq(&self, other: &Foo<T>) -> bool {
Expand All @@ -454,7 +454,7 @@ considered a full-fledged language feature.

For this reason, Rust recognizes a special crate-level attribute of the form:

```{.ignore}
```rust,ignore
#![feature(feature1, feature2, feature3)]
```

Expand Down
62 changes: 31 additions & 31 deletions src/expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ A _literal expression_ consists of one of the [literal](tokens.html#literals) fo
described earlier. It directly describes a number, character, string, boolean
value, or the unit value.

```text
```rust
(); // unit type
"hello"; // string type
'5'; // character type
Expand All @@ -108,15 +108,15 @@ Tuples are written by enclosing zero or more comma-separated expressions in
parentheses. They are used to create [tuple-typed](types.html#tuple-types)
values.

```{.tuple}
```rust
(0.0, 4.5);
("a", 4usize, true);
```

You can disambiguate a single-element tuple from a value in parentheses with a
comma:

```
```rust
(0,); // single-element tuple
(0); // zero in parentheses
```
Expand All @@ -141,7 +141,7 @@ A _unit-like struct expression_ consists only of the [path](paths.html) of a

The following are examples of struct expressions:

```
```rust
# struct Point { x: f64, y: f64 }
# struct NothingInMe { }
# struct TuplePoint(f64, f64);
Expand All @@ -166,7 +166,7 @@ the same type as the base expression) with the given values for the fields that
were explicitly specified and the values in the base expression for all other
fields.

```
```rust
# struct Point3d { x: i32, y: i32, z: i32 }
let base = Point3d {x: 1, y: 2, z: 3};
Point3d {y: 0, z: 10, .. base};
Expand All @@ -180,7 +180,7 @@ This allows a compact syntax with less duplication.

Example:

```
```rust
# struct Point3d { x: i32, y: i32, z: i32 }
# let x = 0;
# let y_value = 0;
Expand All @@ -199,13 +199,13 @@ the block itself.
A block will execute each statement sequentially, and then execute the
expression (if given). If the block ends in a statement, its value is `()`:

```
```rust
let x: () = { println!("Hello."); };
```

If it ends in an expression, its value and type are that of the expression:

```
```rust
let x: i32 = { println!("Hello."); 5 };

assert_eq!(5, x);
Expand All @@ -227,7 +227,7 @@ identifier, when not immediately followed by a parenthesized expression-list
(the latter is a [method call expression](#method-call-expressions)). A field
expression denotes a field of a [struct](types.html#struct-types).

```{.ignore .field}
```rust,ignore
mystruct.myfield;
foo().x;
(Struct {a: 10, b: 20}).a;
Expand All @@ -252,7 +252,7 @@ In the `[expr ';' expr]` form, the expression after the `';'` must be a
constant expression that can be evaluated at compile time, such as a
[literal](tokens.html#literals) or a [static item](items.html#static-items).

```
```rust
[1, 2, 3, 4];
["a", "b", "c", "d"];
[0; 128]; // array with 128 zeros
Expand All @@ -271,7 +271,7 @@ bounds-checked at compile-time for constant arrays being accessed with a
constant index value. Otherwise a check will be performed at run-time that
will put the thread in a _panicked state_ if it fails.

```{should-fail}
```rust,should_panic
([1, 2, 3, 4])[0];

let x = (["a", "b"])[10]; // compiler error: const index-expr is out of bounds
Expand All @@ -292,7 +292,7 @@ autoderefs to more.

The `..` operator will construct an object of one of the `std::ops::Range` variants.

```
```rust
1..2; // std::ops::Range
3..; // std::ops::RangeFrom
..4; // std::ops::RangeTo
Expand All @@ -301,7 +301,7 @@ The `..` operator will construct an object of one of the `std::ops::Range` varia

The following expressions are equivalent.

```
```rust
let x = std::ops::Range {start: 0, end: 10};
let y = 0..10;

Expand All @@ -311,15 +311,15 @@ assert_eq!(x, y);
Similarly, the `...` operator will construct an object of one of the
`std::ops::RangeInclusive` variants.

```
```rust
# #![feature(inclusive_range_syntax)]
1...2; // std::ops::RangeInclusive
...4; // std::ops::RangeToInclusive
```

The following expressions are equivalent.

```
```rust
# #![feature(inclusive_range_syntax, inclusive_range)]
let x = std::ops::RangeInclusive::NonEmpty {start: 0, end: 10};
let y = 0...10;
Expand Down Expand Up @@ -464,7 +464,7 @@ on the right-hand side.

An example of an `as` expression:

```
```rust
# fn sum(values: &[f64]) -> f64 { 0.0 }
# fn len(values: &[f64]) -> i32 { 0 }

Expand Down Expand Up @@ -493,7 +493,7 @@ Evaluating an assignment expression [either copies or
moves](#moved-and-copied-types) its right-hand operand to its left-hand
operand.

```
```rust
# let mut x = 0;
# let y = 0;
x = y;
Expand All @@ -512,7 +512,7 @@ Any such expression always has the [`unit`](types.html#tuple-types) type.
The precedence of Rust binary operators is ordered as follows, going from
strong to weak:

```{.text .precedence}
```text
as :
* / %
+ -
Expand Down Expand Up @@ -540,7 +540,7 @@ within an expression.

An example of a parenthesized expression:

```
```rust
let x: i32 = (2 + 3) * 4;
```

Expand All @@ -553,7 +553,7 @@ eventually returns, then the expression completes.

Some examples of call expressions:

```
```rust
# fn add(x: i32, y: i32) -> i32 { 0 }

let x: i32 = add(1i32, 2i32);
Expand Down Expand Up @@ -592,7 +592,7 @@ In this example, we define a function `ten_times` that takes a higher-order
function argument, and we then call it with a lambda expression as an argument,
followed by a lambda expression that moves values from its environment.

```
```rust
fn ten_times<F>(f: F) where F: Fn(i32) {
for index in 0..10 {
f(index);
Expand Down Expand Up @@ -646,7 +646,7 @@ conditional expression evaluates to `false`, the `while` expression completes.

An example:

```
```rust
let mut i = 0;

while i < 10 {
Expand All @@ -667,7 +667,7 @@ by an implementation of `std::iter::IntoIterator`.

An example of a `for` loop over the contents of an array:

```
```rust
# type Foo = i32;
# fn bar(f: &Foo) { }
# let a = 0;
Expand All @@ -683,7 +683,7 @@ for e in v {

An example of a for loop over a series of integers:

```
```rust
# fn bar(b:usize) { }
for i in 0..256 {
bar(i);
Expand Down Expand Up @@ -738,7 +738,7 @@ the inside of the match.

An example of a `match` expression:

```
```rust
let x = 1;

match x {
Expand All @@ -759,7 +759,7 @@ bind to a reference by using the `ref` keyword, or to a mutable reference using
Subpatterns can also be bound to variables by the use of the syntax `variable @
subpattern`. For example:

```
```rust
let x = 1;

match x {
Expand All @@ -772,7 +772,7 @@ Patterns can also dereference pointers by using the `&`, `&mut` and `box`
symbols, as appropriate. For example, these two matches on `x: &i32` are
equivalent:

```
```rust
# let x = &3;
let y = match *x { 0 => "zero", _ => "some" };
let z = match x { &0 => "zero", _ => "some" };
Expand All @@ -783,7 +783,7 @@ assert_eq!(y, z);
Multiple match patterns may be joined with the `|` operator. A range of values
may be specified with `...`. For example:

```
```rust
# let x = 2;

let message = match x {
Expand All @@ -802,7 +802,7 @@ criteria for matching a case. Pattern guards appear after the pattern and
consist of a bool-typed expression following the `if` keyword. A pattern guard
may refer to the variables bound within the pattern they follow.

```
```rust
# let maybe_digit = Some(0);
# fn process_digit(i: i32) { }
# fn process_other(i: i32) { }
Expand All @@ -822,7 +822,7 @@ pattern. If the value of the expression on the right hand side of the `let`
statement matches the pattern, the corresponding block will execute, otherwise
flow proceeds to the first `else` block that follows.

```
```rust
let dish = ("Ham", "Eggs");

// this body will be skipped because the pattern is refuted
Expand Down Expand Up @@ -853,7 +853,7 @@ transfers control to the caller frame.

An example of a `return` expression:

```
```rust
fn max(a: i32, b: i32) -> i32 {
if a > b {
return a;
Expand Down
2 changes: 1 addition & 1 deletion src/paths.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ crates; an item's canonical path merely identifies it within the crate.

Two examples of simple paths consisting of only identifier components:

```{.ignore}
```rust,ignore
x;
x::y::z;
```
Expand Down
2 changes: 1 addition & 1 deletion src/subtyping.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ would be due to type equality.
Consider the following example: string literals always have `'static`
lifetime. Nevertheless, we can assign `s` to `t`:

```
```rust
fn bar<'a>() {
let s: &'static str = "hi";
let t: &'a str = s;
Expand Down
Loading