Skip to content

Commit 9e3fc69

Browse files
committed
---
yaml --- r: 153828 b: refs/heads/try2 c: e0d10bb h: refs/heads/master v: v3
1 parent f18d079 commit 9e3fc69

File tree

252 files changed

+759
-555
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

252 files changed

+759
-555
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: c05cfab7f979f72a25821060576a2aaea4c61ef9
8+
refs/heads/try2: e0d10bb69ab04ab041b39c71f7537d8c63ef9669
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/etc/licenseck.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"libsync/mpsc_intrusive.rs", # BSD
4545
"test/bench/shootout-binarytrees.rs", # BSD
4646
"test/bench/shootout-fannkuch-redux.rs", # BSD
47+
"test/bench/shootout-k-nucleotide.rs", # BSD
4748
"test/bench/shootout-mandelbrot.rs", # BSD
4849
"test/bench/shootout-meteor.rs", # BSD
4950
"test/bench/shootout-pidigits.rs", # BSD

branches/try2/src/grammar/raw-string-literal-ambiguity.md

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
Rust's lexical grammar is not context-free. Raw string literals are the source
22
of the problem. Informally, a raw string literal is an `r`, followed by `N`
33
hashes (where N can be zero), a quote, any characters, then a quote followed
4-
by `N` hashes. This grammar describes this as best possible:
4+
by `N` hashes. Critically, once inside the first pair of quotes,
5+
another quote cannot be followed by `N` consecutive hashes. e.g.
6+
`r###""###"###` is invalid.
7+
8+
This grammar describes this as best possible:
59

610
R -> 'r' S
711
S -> '"' B '"'
@@ -22,8 +26,39 @@ accepted as one by the above grammar, using the derivation:
2226
(Where `T : U` means the rule `T` is applied, and `U` is the remainder of the
2327
string.) The difficulty arises from the fact that it is fundamentally
2428
context-sensitive. In particular, the context needed is the number of hashes.
25-
I know of no way to resolve this, but also have not come up with a proof that
26-
it is not context sensitive. Such a proof would probably use the pumping lemma
27-
for context-free languages, but I (cmr) could not come up with a proof after
28-
spending a few hours on it, and decided my time best spent elsewhere. Pull
29-
request welcome!
29+
30+
To prove that Rust's string literals are not context-free, we will use
31+
the fact that context-free languages are closed under intersection with
32+
regular languages, and the
33+
[pumping lemma for context-free languages](https://en.wikipedia.org/wiki/Pumping_lemma_for_context-free_languages).
34+
35+
Consider the regular language `R = r#+""#*"#+`. If Rust's raw string literals are
36+
context-free, then their intersection with `R`, `R'`, should also be context-free.
37+
Therefore, to prove that raw string literals are not context-free,
38+
it is sufficient to prove that `R'` is not context-free.
39+
40+
The language `R'` is `{r#^n""#^m"#^n | m < n}`.
41+
42+
Assume `R'` *is* context-free. Then `R'` has some pumping length `p > 0` for which
43+
the pumping lemma applies. Consider the following string `s` in `R'`:
44+
45+
`r#^p""#^{p-1}"#^p`
46+
47+
e.g. for `p = 2`: `s = r##""#"##`
48+
49+
Then `s = uvwxy` for some choice of `uvwxy` such that `vx` is non-empty,
50+
`|vwx| < p+1`, and `uv^iwx^iy` is in `R'` for all `i >= 0`.
51+
52+
Neither `v` nor `x` can contain a `"` or `r`, as the number of these characters
53+
in any string in `R'` is fixed. So `v` and `x` contain only hashes.
54+
Consequently, of the three sequences of hashes, `v` and `x` combined
55+
can only pump two of them.
56+
If we ever choose the central sequence of hashes, then one of the outer sequences
57+
will not grow when we pump, leading to an imbalance between the outer sequences.
58+
Therefore, we must pump both outer sequences of hashes. However,
59+
there are `p+2` characters between these two sequences of hashes, and `|vwx|` must
60+
be less than `p+1`. Therefore we have a contradiction, and `R'` must not be
61+
context-free.
62+
63+
Since `R'` is not context-free, it follows that the Rust's raw string literals
64+
must not be context-free.

branches/try2/src/liballoc/arc.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
/*!
12-
* Concurrency-enabled mechanisms for sharing mutable and/or immutable state
13-
* between tasks.
14-
*/
11+
#![stable]
12+
13+
//! Concurrency-enabled mechanisms for sharing mutable and/or immutable state
14+
//! between tasks.
1515
1616
use core::atomics;
1717
use core::clone::Clone;
@@ -51,6 +51,7 @@ use heap::deallocate;
5151
/// }
5252
/// ```
5353
#[unsafe_no_drop_flag]
54+
#[stable]
5455
pub struct Arc<T> {
5556
// FIXME #12808: strange name to try to avoid interfering with
5657
// field accesses of the contained type via Deref
@@ -62,6 +63,7 @@ pub struct Arc<T> {
6263
/// Weak pointers will not keep the data inside of the `Arc` alive, and can be
6364
/// used to break cycles between `Arc` pointers.
6465
#[unsafe_no_drop_flag]
66+
#[experimental = "Weak pointers may not belong in this module."]
6567
pub struct Weak<T> {
6668
// FIXME #12808: strange name to try to avoid interfering with
6769
// field accesses of the contained type via Deref
@@ -77,6 +79,7 @@ struct ArcInner<T> {
7779
impl<T: Share + Send> Arc<T> {
7880
/// Create an atomically reference counted wrapper.
7981
#[inline]
82+
#[stable]
8083
pub fn new(data: T) -> Arc<T> {
8184
// Start the weak pointer count as 1 which is the weak pointer that's
8285
// held by all the strong pointers (kinda), see std/rc.rs for more info
@@ -103,14 +106,15 @@ impl<T: Share + Send> Arc<T> {
103106
/// Weak pointers will not keep the data alive. Once all strong references
104107
/// to the underlying data have been dropped, the data itself will be
105108
/// destroyed.
109+
#[experimental = "Weak pointers may not belong in this module."]
106110
pub fn downgrade(&self) -> Weak<T> {
107111
// See the clone() impl for why this is relaxed
108112
self.inner().weak.fetch_add(1, atomics::Relaxed);
109113
Weak { _ptr: self._ptr }
110114
}
111115
}
112116

113-
#[unstable]
117+
#[unstable = "waiting on stability of Clone"]
114118
impl<T: Share + Send> Clone for Arc<T> {
115119
/// Duplicate an atomically reference counted wrapper.
116120
///
@@ -135,6 +139,7 @@ impl<T: Share + Send> Clone for Arc<T> {
135139
}
136140
}
137141

142+
#[experimental = "Deref is experimental."]
138143
impl<T: Send + Share> Deref<T> for Arc<T> {
139144
#[inline]
140145
fn deref<'a>(&'a self) -> &'a T {
@@ -169,6 +174,7 @@ impl<T: Send + Share + Clone> Arc<T> {
169174
}
170175

171176
#[unsafe_destructor]
177+
#[experimental = "waiting on stability of Drop"]
172178
impl<T: Share + Send> Drop for Arc<T> {
173179
fn drop(&mut self) {
174180
// This structure has #[unsafe_no_drop_flag], so this drop glue may run
@@ -212,6 +218,7 @@ impl<T: Share + Send> Drop for Arc<T> {
212218
}
213219
}
214220

221+
#[experimental = "Weak pointers may not belong in this module."]
215222
impl<T: Share + Send> Weak<T> {
216223
/// Attempts to upgrade this weak reference to a strong reference.
217224
///
@@ -237,7 +244,7 @@ impl<T: Share + Send> Weak<T> {
237244
}
238245
}
239246

240-
#[unstable]
247+
#[experimental = "Weak pointers may not belong in this module."]
241248
impl<T: Share + Send> Clone for Weak<T> {
242249
#[inline]
243250
fn clone(&self) -> Weak<T> {
@@ -248,6 +255,7 @@ impl<T: Share + Send> Clone for Weak<T> {
248255
}
249256

250257
#[unsafe_destructor]
258+
#[experimental = "Weak pointers may not belong in this module."]
251259
impl<T: Share + Send> Drop for Weak<T> {
252260
fn drop(&mut self) {
253261
// see comments above for why this check is here

branches/try2/src/liballoc/boxed.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,12 @@ impl<T: Ord> Ord for Box<T> {
8787
impl<T: Eq> Eq for Box<T> {}
8888

8989
/// Extension methods for an owning `Any` trait object
90-
#[unstable = "post-DST, the signature of `downcast` will change to take `Box<Self>`"]
90+
#[unstable = "post-DST and coherence changes, this will not be a trait but \
91+
rather a direct `impl` on `Box<Any>`"]
9192
pub trait BoxAny {
9293
/// Returns the boxed value if it is of type `T`, or
9394
/// `Err(Self)` if it isn't.
95+
#[unstable = "naming conventions around accessing innards may change"]
9496
fn downcast<T: 'static>(self) -> Result<Box<T>, Self>;
9597

9698
/// Deprecated; this method has been renamed to `downcast`.
@@ -100,6 +102,7 @@ pub trait BoxAny {
100102
}
101103
}
102104

105+
#[stable]
103106
impl BoxAny for Box<Any> {
104107
#[inline]
105108
fn downcast<T: 'static>(self) -> Result<Box<T>, Box<Any>> {

branches/try2/src/liballoc/rc.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,6 @@ impl<T> Drop for Weak<T> {
379379
}
380380
}
381381

382-
#[unstable]
383382
#[experimental = "Weak pointers may not belong in this module."]
384383
impl<T> Clone for Weak<T> {
385384
#[inline]

branches/try2/src/libcollections/ringbuf.rs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,18 @@ impl<T> RingBuf<T> {
133133
/// Retrieve an element in the RingBuf by index
134134
///
135135
/// Fails if there is no element with the given index
136+
///
137+
/// # Example
138+
///
139+
/// ```rust
140+
/// use std::collections::RingBuf;
141+
///
142+
/// let mut buf = RingBuf::new();
143+
/// buf.push(3i);
144+
/// buf.push(4);
145+
/// buf.push(5);
146+
/// assert_eq!(buf.get(1), &4);
147+
/// ```
136148
pub fn get<'a>(&'a self, i: uint) -> &'a T {
137149
let idx = self.raw_index(i);
138150
match *self.elts.get(idx) {
@@ -144,6 +156,19 @@ impl<T> RingBuf<T> {
144156
/// Retrieve an element in the RingBuf by index
145157
///
146158
/// Fails if there is no element with the given index
159+
///
160+
/// # Example
161+
///
162+
/// ```rust
163+
/// use std::collections::RingBuf;
164+
///
165+
/// let mut buf = RingBuf::new();
166+
/// buf.push(3i);
167+
/// buf.push(4);
168+
/// buf.push(5);
169+
/// *buf.get_mut(1) = 7;
170+
/// assert_eq!(buf.get(1), &7);
171+
/// ```
147172
pub fn get_mut<'a>(&'a mut self, i: uint) -> &'a mut T {
148173
let idx = self.raw_index(i);
149174
match *self.elts.get_mut(idx) {
@@ -157,6 +182,20 @@ impl<T> RingBuf<T> {
157182
/// `i` and `j` may be equal.
158183
///
159184
/// Fails if there is no element with the given index
185+
///
186+
/// # Example
187+
///
188+
/// ```rust
189+
/// use std::collections::RingBuf;
190+
///
191+
/// let mut buf = RingBuf::new();
192+
/// buf.push(3i);
193+
/// buf.push(4);
194+
/// buf.push(5);
195+
/// buf.swap(0, 2);
196+
/// assert_eq!(buf.get(0), &5);
197+
/// assert_eq!(buf.get(2), &3);
198+
/// ```
160199
pub fn swap(&mut self, i: uint, j: uint) {
161200
assert!(i < self.len());
162201
assert!(j < self.len());
@@ -196,11 +235,38 @@ impl<T> RingBuf<T> {
196235
}
197236

198237
/// Front-to-back iterator.
238+
///
239+
/// # Example
240+
///
241+
/// ```rust
242+
/// use std::collections::RingBuf;
243+
///
244+
/// let mut buf = RingBuf::new();
245+
/// buf.push(5i);
246+
/// buf.push(3);
247+
/// buf.push(4);
248+
/// assert_eq!(buf.iter().collect::<Vec<&int>>().as_slice(), &[&5, &3, &4]);
249+
/// ```
199250
pub fn iter<'a>(&'a self) -> Items<'a, T> {
200251
Items{index: 0, rindex: self.nelts, lo: self.lo, elts: self.elts.as_slice()}
201252
}
202253

203254
/// Front-to-back iterator which returns mutable values.
255+
///
256+
/// # Example
257+
///
258+
/// ```rust
259+
/// use std::collections::RingBuf;
260+
///
261+
/// let mut buf = RingBuf::new();
262+
/// buf.push(5i);
263+
/// buf.push(3);
264+
/// buf.push(4);
265+
/// for num in buf.mut_iter() {
266+
/// *num = *num - 2;
267+
/// }
268+
/// assert_eq!(buf.mut_iter().collect::<Vec<&mut int>>().as_slice(), &[&mut 3, &mut 1, &mut 2]);
269+
/// ```
204270
pub fn mut_iter<'a>(&'a mut self) -> MutItems<'a, T> {
205271
let start_index = raw_index(self.lo, self.elts.len(), 0);
206272
let end_index = raw_index(self.lo, self.elts.len(), self.nelts);

0 commit comments

Comments
 (0)