Skip to content

Commit dc8b8b5

Browse files
author
noam
committed
---
yaml --- r: 109367 b: refs/heads/dist-snap c: 4b224af h: refs/heads/master i: 109365: 0c43058 109363: 6e038d6 109359: 105bde6 v: v3
1 parent 98d0cc3 commit dc8b8b5

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: f64fdf524a434f0e5cd0bc91d09c144723f3c90d
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: 7dfa4b298262fde037b5fbbb8fe20468d7306cbb
9+
refs/heads/dist-snap: 4b224af72a76770694dc0998b356d9ce4d77529b
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/doc/guide-lifetimes.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,13 +559,13 @@ points at a static constant).
559559

560560
# Named lifetimes
561561

562-
Lifetimes can be named and referenced. For example, the special lifetime
562+
Lifetimes can be named and referenced. For example, the special lifetime
563563
`'static`, which does not go out of scope, can be used to create global
564564
variables and communicate between tasks (see the manual for usecases).
565565

566566
## Parameter Lifetimes
567567

568-
Named lifetimes allow for grouping of parameters by lifetime.
568+
Named lifetimes allow for grouping of parameters by lifetime.
569569
For example, consider this function:
570570

571571
~~~
@@ -674,6 +674,11 @@ Named lifetime notation can also be used to control the flow of execution:
674674
}
675675
~~~
676676

677+
> ***Note:*** Labelled breaks are not currently supported within `while` loops.
678+
679+
Named labels are hygienic and can be used safely within macros.
680+
See the macros guide section on hygiene for more details.
681+
677682
# Conclusion
678683

679684
So there you have it: a (relatively) brief tour of the lifetime

branches/dist-snap/src/doc/guide-macros.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,38 @@ position (in particular, not as an argument to yet another macro invocation),
398398
the expander will then proceed to evaluate `m2!()` (along with any other macro
399399
invocations `m1!(m2!())` produced).
400400

401+
# Hygiene
402+
403+
To prevent clashes, rust implements
404+
[hygienic macros](http://en.wikipedia.org/wiki/Hygienic_macro).
405+
406+
As an example, `loop` and `for-loop` labels (discussed in the lifetimes guide)
407+
will not clash. The following code will print "Hello!" only once:
408+
409+
~~~
410+
#[feature(macro_rules)];
411+
412+
macro_rules! loop_x (
413+
($e: expr) => (
414+
// $e will not interact with this 'x
415+
'x: loop {
416+
println!("Hello!");
417+
$e
418+
}
419+
);
420+
)
421+
422+
fn main() {
423+
'x: loop {
424+
loop_x!(break 'x);
425+
println!("I am never printed.");
426+
}
427+
}
428+
~~~
429+
430+
The two `'x` names did not clash, which would have caused the loop
431+
to print "I am never printed" and to run forever.
432+
401433
# A final note
402434

403435
Macros, as currently implemented, are not for the faint of heart. Even

0 commit comments

Comments
 (0)