Skip to content

Commit 367f3ab

Browse files
committed
---
yaml --- r: 105151 b: refs/heads/snap-stage3 c: 6bac560 h: refs/heads/master i: 105149: 606ed60 105147: af49ad6 105143: 2c1e172 105135: 13c0a19 105119: 59af289 105087: bec1e39 v: v3
1 parent c7bca7f commit 367f3ab

File tree

10 files changed

+178
-40
lines changed

10 files changed

+178
-40
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 62f1d68439dcfd509eaca29887afa97f22938373
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 6200e761f0ef58510ad2acc383b29de7e7a79bcd
4+
refs/heads/snap-stage3: 6bac5607c963c61d488a0d832458341589a560b3
55
refs/heads/try: db814977d07bd798feb24f6b74c00800ef458a13
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/mk/install.mk

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
# The stage we install from
1616
ISTAGE = $(PREPARE_STAGE)
1717

18+
$(eval $(call DEF_PREPARE,mkfile-install))
19+
1820
install: PREPARE_HOST=$(CFG_BUILD)
1921
install: PREPARE_TARGETS=$(CFG_TARGET)
2022
install: PREPARE_DIR_CMD=$(DEFAULT_PREPARE_DIR_CMD)
@@ -28,7 +30,7 @@ install: PREPARE_SOURCE_MAN_DIR=$(S)/man
2830
install: PREPARE_DEST_BIN_DIR=$(DESTDIR)$(CFG_PREFIX)/bin
2931
install: PREPARE_DEST_LIB_DIR=$(DESTDIR)$(CFG_LIBDIR)
3032
install: PREPARE_DEST_MAN_DIR=$(DESTDIR)$(CFG_MANDIR)/man1
31-
install: prepare-everything
33+
install: prepare-everything-mkfile-install
3234

3335

3436
# Uninstall code

branches/snap-stage3/mk/prepare.mk

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ prepare-base-$(1): PREPARE_SOURCE_MAN_DIR=$$(S)/man
156156
prepare-base-$(1): PREPARE_DEST_BIN_DIR=$$(PREPARE_DEST_DIR)/bin
157157
prepare-base-$(1): PREPARE_DEST_LIB_DIR=$$(PREPARE_DEST_DIR)/$$(CFG_LIBDIR_RELATIVE)
158158
prepare-base-$(1): PREPARE_DEST_MAN_DIR=$$(PREPARE_DEST_DIR)/share/man/man1
159-
prepare-base-$(1): prepare-host-$(1) prepare-targets-$(1)
159+
prepare-base-$(1): prepare-everything-$(1)
160+
161+
prepare-everything-$(1): prepare-host-$(1) prepare-targets-$(1)
160162

161163
prepare-host-$(1): prepare-host-tools-$(1)
162164

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

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -559,9 +559,14 @@ points at a static constant).
559559

560560
# Named lifetimes
561561

562-
Let's look at named lifetimes in more detail. Named lifetimes allow
563-
for grouping of parameters by lifetime. For example, consider this
564-
function:
562+
Lifetimes can be named and referenced. For example, the special lifetime
563+
`'static`, which does not go out of scope, can be used to create global
564+
variables and communicate between tasks (see the manual for usecases).
565+
566+
## Parameter Lifetimes
567+
568+
Named lifetimes allow for grouping of parameters by lifetime.
569+
For example, consider this function:
565570

566571
~~~
567572
# struct Point {x: f64, y: f64}; // as before
@@ -655,6 +660,25 @@ fn select<'r, T>(shape: &Shape, threshold: f64,
655660

656661
This is equivalent to the previous definition.
657662

663+
## Labeled Control Structures
664+
665+
Named lifetime notation can also be used to control the flow of execution:
666+
667+
~~~
668+
'h: for i in range(0,10) {
669+
'g: loop {
670+
if i % 2 == 0 { continue 'h; }
671+
if i == 9 { break 'h; }
672+
break 'g;
673+
}
674+
}
675+
~~~
676+
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+
658682
# Conclusion
659683

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

branches/snap-stage3/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

branches/snap-stage3/src/doc/tutorial.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2103,7 +2103,8 @@ a `&T` pointer. `MutexArc` is an example of a *sharable* type with internal muta
21032103
These are types that do not contain any data whose lifetime is bound to
21042104
a particular stack frame. These are types that do not contain any
21052105
references, or types where the only contained references
2106-
have the `'static` lifetime.
2106+
have the `'static` lifetime. (For more on named lifetimes and their uses,
2107+
see the [references and lifetimes guide][lifetimes].)
21072108
21082109
> ***Note:*** These two traits were referred to as 'kinds' in earlier
21092110
> iterations of the language, and often still are.

branches/snap-stage3/src/librustdoc/clean.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,18 @@ pub enum ItemEnum {
174174
StaticItem(Static),
175175
TraitItem(Trait),
176176
ImplItem(Impl),
177+
/// `use` and `extern crate`
177178
ViewItemItem(ViewItem),
179+
/// A method signature only. Used for required methods in traits (ie,
180+
/// non-default-methods).
178181
TyMethodItem(TyMethod),
182+
/// A method with a body.
179183
MethodItem(Method),
180184
StructFieldItem(StructField),
181185
VariantItem(Variant),
186+
/// `fn`s from an extern block
182187
ForeignFunctionItem(Function),
188+
/// `static`s from an extern block
183189
ForeignStaticItem(Static),
184190
MacroItem(Macro),
185191
}
@@ -1014,11 +1020,23 @@ pub struct Impl {
10141020
generics: Generics,
10151021
trait_: Option<Type>,
10161022
for_: Type,
1017-
methods: Vec<Item> ,
1023+
methods: Vec<Item>,
1024+
derived: bool,
10181025
}
10191026

10201027
impl Clean<Item> for doctree::Impl {
10211028
fn clean(&self) -> Item {
1029+
let mut derived = false;
1030+
for attr in self.attrs.iter() {
1031+
match attr.node.value.node {
1032+
ast::MetaWord(ref s) => {
1033+
if s.get() == "automatically_derived" {
1034+
derived = true;
1035+
}
1036+
}
1037+
_ => {}
1038+
}
1039+
}
10221040
Item {
10231041
name: None,
10241042
attrs: self.attrs.clean(),
@@ -1030,6 +1048,7 @@ impl Clean<Item> for doctree::Impl {
10301048
trait_: self.trait_.clean(),
10311049
for_: self.for_.clean(),
10321050
methods: self.methods.clean(),
1051+
derived: derived,
10331052
}),
10341053
}
10351054
}

branches/snap-stage3/src/librustdoc/html/layout.rs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,53 +29,53 @@ pub fn render<T: fmt::Show, S: fmt::Show>(
2929
-> fmt::Result
3030
{
3131
write!(dst,
32-
"<!DOCTYPE html>
33-
<html lang=\"en\">
32+
r##"<!DOCTYPE html>
33+
<html lang="en">
3434
<head>
35-
<meta charset=\"utf-8\" />
35+
<meta charset="utf-8" />
3636
<title>{title}</title>
3737
3838
<link href='http://fonts.googleapis.com/css?family=Oswald:700|Inconsolata:400,700'
3939
rel='stylesheet' type='text/css'>
40-
<link rel=\"stylesheet\" type=\"text/css\" href=\"{root_path}main.css\">
40+
<link rel="stylesheet" type="text/css" href="{root_path}main.css">
4141
42-
{favicon, select, none{} other{<link rel=\"shortcut icon\" href=\"#\" />}}
42+
{favicon, select, none{} other{<link rel="shortcut icon" href="\#" />}}
4343
</head>
4444
<body>
4545
<!--[if lte IE 8]>
46-
<div class=\"warning\">
46+
<div class="warning">
4747
This old browser is unsupported and will most likely display funky
4848
things.
4949
</div>
5050
<![endif]-->
5151
52-
<section class=\"sidebar\">
52+
<section class="sidebar">
5353
{logo, select, none{} other{
54-
<a href='{root_path}{krate}/index.html'><img src='#' alt=''/></a>
54+
<a href='{root_path}{krate}/index.html'><img src='\#' alt=''/></a>
5555
}}
5656
5757
{sidebar}
5858
</section>
5959
60-
<nav class=\"sub\">
61-
<form class=\"search-form js-only\">
62-
<button class=\"do-search\">Search</button>
63-
<div class=\"search-container\">
64-
<input class=\"search-input\" name=\"search\"
65-
autocomplete=\"off\"
66-
placeholder=\"Search documentation...\"
67-
type=\"search\" />
60+
<nav class="sub">
61+
<form class="search-form js-only">
62+
<button class="do-search">Search</button>
63+
<div class="search-container">
64+
<input class="search-input" name="search"
65+
autocomplete="off"
66+
placeholder="Search documentation..."
67+
type="search" />
6868
</div>
6969
</form>
7070
</nav>
7171
72-
<section id='main' class=\"content {ty}\">{content}</section>
73-
<section id='search' class=\"content hidden\"></section>
72+
<section id='main' class="content {ty}">{content}</section>
73+
<section id='search' class="content hidden"></section>
7474
75-
<section class=\"footer\"></section>
75+
<section class="footer"></section>
7676
77-
<div id=\"help\" class=\"hidden\">
78-
<div class=\"shortcuts\">
77+
<div id="help" class="hidden">
78+
<div class="shortcuts">
7979
<h1>Keyboard shortcuts</h1>
8080
<dl>
8181
<dt>?</dt>
@@ -86,11 +86,11 @@ pub fn render<T: fmt::Show, S: fmt::Show>(
8686
<dd>Move up in search results</dd>
8787
<dt>&darr;</dt>
8888
<dd>Move down in search results</dd>
89-
<dt>&\\#9166;</dt>
89+
<dt>&\#9166;</dt>
9090
<dd>Go to active search result</dd>
9191
</dl>
9292
</div>
93-
<div class=\"infos\">
93+
<div class="infos">
9494
<h1>Search tricks</h1>
9595
<p>
9696
Prefix searches with a type followed by a colon (e.g.
@@ -106,15 +106,15 @@ pub fn render<T: fmt::Show, S: fmt::Show>(
106106
</div>
107107
108108
<script>
109-
var rootPath = \"{root_path}\";
110-
var currentCrate = \"{krate}\";
109+
var rootPath = "{root_path}";
110+
var currentCrate = "{krate}";
111111
</script>
112-
<script src=\"{root_path}jquery.js\"></script>
113-
<script src=\"{root_path}main.js\"></script>
114-
<script async src=\"{root_path}search-index.js\"></script>
112+
<script src="{root_path}jquery.js"></script>
113+
<script src="{root_path}main.js"></script>
114+
<script async src="{root_path}search-index.js"></script>
115115
</body>
116116
</html>
117-
",
117+
"##,
118118
content = *t,
119119
root_path = page.root_path,
120120
ty = page.ty,

branches/snap-stage3/src/librustdoc/html/render.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,8 +1517,22 @@ fn render_methods(w: &mut Writer, it: &clean::Item) -> fmt::Result {
15171517
if traits.len() > 0 {
15181518
try!(write!(w, "<h2 id='implementations'>Trait \
15191519
Implementations</h2>"));
1520-
for &(ref i, ref dox) in traits.move_iter() {
1521-
try!(render_impl(w, i, dox));
1520+
let mut any_derived = false;
1521+
for & &(ref i, ref dox) in traits.iter() {
1522+
if !i.derived {
1523+
try!(render_impl(w, i, dox));
1524+
} else {
1525+
any_derived = true;
1526+
}
1527+
}
1528+
if any_derived {
1529+
try!(write!(w, "<h3 id='derived_implementations'>Derived Implementations \
1530+
</h3>"));
1531+
for &(ref i, ref dox) in traits.move_iter() {
1532+
if i.derived {
1533+
try!(render_impl(w, i, dox));
1534+
}
1535+
}
15221536
}
15231537
}
15241538
}

branches/snap-stage3/src/libstd/kinds.rs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,51 @@ pub trait Pod {
4040
// Empty.
4141
}
4242

43-
/// Types that can be safely shared between threads, hence thread-safe.
43+
/// Types that can be safely shared between tasks when aliased.
44+
///
45+
/// The precise definition is: a type `T` is `Share` if `&T` is
46+
/// thread-safe. In other words, there is no possibility of data races
47+
/// when passing `&T` references between tasks.
48+
///
49+
/// As one would expect, primitive types like `u8` and `f64` are all
50+
/// `Share`, and so are simple aggregate types containing them (like
51+
/// tuples, structs and enums). More instances of basic `Share` types
52+
/// include "immutable" types like `&T` and those with simple
53+
/// inherited mutability, such as `~T`, `Vec<T>` and most other
54+
/// collection types. (Generic parameters need to be `Share` for their
55+
/// container to be `Share`.)
56+
///
57+
/// A somewhat surprising consequence of the definition is `&mut T` is
58+
/// `Share` (if `T` is `Share`) even though it seems that it might
59+
/// provide unsynchronised mutation. The trick is a mutable reference
60+
/// stored in an aliasable reference (that is, `& &mut T`) becomes
61+
/// read-only, as if it were a `& &T`, hence there is no risk of a data
62+
/// race.
63+
///
64+
/// Types that are not `Share` are those that have "interior
65+
/// mutability" in a non-thread-safe way, such as `Cell` and `RefCell`
66+
/// in `std::cell`. These types allow for mutation of their contents
67+
/// even when in an immutable, aliasable slot, e.g. the contents of
68+
/// `&Cell<T>` can be `.set`, and do not ensure data races are
69+
/// impossible, hence they cannot be `Share`. A higher level example
70+
/// of a non-`Share` type is the reference counted pointer
71+
/// `std::rc::Rc`, because any reference `&Rc<T>` can clone a new
72+
/// reference, which modifies the reference counts in a non-atomic
73+
/// way.
74+
///
75+
/// For cases when one does need thread-safe interior mutability,
76+
/// types like the atomics in `std::sync` and `Mutex` & `RWLock` in
77+
/// the `sync` crate do ensure that any mutation cannot cause data
78+
/// races. Hence these types are `Share`.
79+
///
80+
/// Users writing their own types with interior mutability (or anything
81+
/// else that is not thread-safe) should use the `NoShare` marker type
82+
/// (from `std::kinds::marker`) to ensure that the compiler doesn't
83+
/// consider the user-defined type to be `Share`. Any types with
84+
/// interior mutability must also use the `std::ty::Unsafe` wrapper
85+
/// around the value(s) which can be mutated when behind a `&`
86+
/// reference; not doing this is undefined behaviour (for example,
87+
/// `transmute`-ing from `&T` to `&mut T` is illegal).
4488
#[lang="share"]
4589
pub trait Share {
4690
// Empty

0 commit comments

Comments
 (0)