Skip to content

Commit 25f558f

Browse files
committed
---
yaml --- r: 207995 b: refs/heads/snap-stage3 c: 7413052 h: refs/heads/master i: 207993: e0bae55 207991: 0c91c77 v: v3
1 parent 934b912 commit 25f558f

Some content is hidden

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

45 files changed

+600
-87
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: 38a97becdf3e6a6157f6f7ec2d98ade8d8edc193
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 92d49cf6c5dec016fc1262e4436c62dc199f2b9d
4+
refs/heads/snap-stage3: 74130520fbd41755c0220436dc79a7b59863bdd7
55
refs/heads/try: 7b4ef47b7805a402d756fb8157101f64880a522f
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2044,21 +2044,21 @@ A complete list of the built-in language items will be added in the future.
20442044

20452045
### Inline attributes
20462046

2047-
The inline attribute is used to suggest to the compiler to perform an inline
2048-
expansion and place a copy of the function or static in the caller rather than
2049-
generating code to call the function or access the static where it is defined.
2047+
The inline attribute suggests that the compiler should place a copy of
2048+
the function or static in the caller, rather than generating code to
2049+
call the function or access the static where it is defined.
20502050

20512051
The compiler automatically inlines functions based on internal heuristics.
2052-
Incorrectly inlining functions can actually making the program slower, so it
2052+
Incorrectly inlining functions can actually make the program slower, so it
20532053
should be used with care.
20542054

20552055
Immutable statics are always considered inlineable unless marked with
20562056
`#[inline(never)]`. It is undefined whether two different inlineable statics
20572057
have the same memory address. In other words, the compiler is free to collapse
20582058
duplicate inlineable statics together.
20592059

2060-
`#[inline]` and `#[inline(always)]` always causes the function to be serialized
2061-
into crate metadata to allow cross-crate inlining.
2060+
`#[inline]` and `#[inline(always)]` always cause the function to be serialized
2061+
into the crate metadata to allow cross-crate inlining.
20622062

20632063
There are three different types of inline attributes:
20642064

branches/snap-stage3/src/doc/trpl/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ want to dive in with a project, or ‘Syntax and Semantics’ if you prefer to
4040
start small, and learn a single concept thoroughly before moving onto the next.
4141
Copious cross-linking connects these parts together.
4242

43+
### Contributing
44+
45+
The source files from which this book is generated can be found on Github:
46+
[github.com/rust-lang/rust/tree/master/src/doc/trpl](https://github.com/rust-lang/rust/tree/master/src/doc/trpl)
47+
4348
## A brief introduction to Rust
4449

4550
Is Rust a language you might be interested in? Let’s examine a few small code

branches/snap-stage3/src/doc/trpl/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,6 @@
6464
* [Benchmark Tests](benchmark-tests.md)
6565
* [Box Syntax and Patterns](box-syntax-and-patterns.md)
6666
* [Slice Patterns](slice-patterns.md)
67+
* [Associated Constants](associated-constants.md)
6768
* [Glossary](glossary.md)
6869
* [Academic Research](academic-research.md)
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
% Associated Constants
2+
3+
With the `associated_consts` feature, you can define constants like this:
4+
5+
```rust
6+
#![feature(associated_consts)]
7+
8+
trait Foo {
9+
const ID: i32;
10+
}
11+
12+
impl Foo for i32 {
13+
const ID: i32 = 1;
14+
}
15+
16+
fn main() {
17+
assert_eq!(1, i32::ID);
18+
}
19+
```
20+
21+
Any implementor of `Foo` will have to define `ID`. Without the definition:
22+
23+
```rust,ignore
24+
#![feature(associated_consts)]
25+
26+
trait Foo {
27+
const ID: i32;
28+
}
29+
30+
impl Foo for i32 {
31+
}
32+
```
33+
34+
gives
35+
36+
```text
37+
error: not all trait items implemented, missing: `ID` [E0046]
38+
impl Foo for i32 {
39+
}
40+
```
41+
42+
A default value can be implemented as well:
43+
44+
```rust
45+
#![feature(associated_consts)]
46+
47+
trait Foo {
48+
const ID: i32 = 1;
49+
}
50+
51+
impl Foo for i32 {
52+
}
53+
54+
impl Foo for i64 {
55+
const ID: i32 = 5;
56+
}
57+
58+
fn main() {
59+
assert_eq!(1, i32::ID);
60+
assert_eq!(5, i64::ID);
61+
}
62+
```
63+
64+
As you can see, when implementing `Foo`, you can leave it unimplemented, as
65+
with `i32`. It will then use the default value. But, as in `i64`, we can also
66+
add our own definition.
67+
68+
Associated constants don’t have to be associated with a trait. An `impl` block
69+
for a `struct` works fine too:
70+
71+
```rust
72+
#![feature(associated_consts)]
73+
74+
struct Foo;
75+
76+
impl Foo {
77+
pub const FOO: u32 = 3;
78+
}
79+
```

branches/snap-stage3/src/doc/trpl/error-handling.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ struct Info {
252252
}
253253

254254
fn write_info(info: &Info) -> io::Result<()> {
255-
let mut file = File::open("my_best_friends.txt").unwrap();
255+
let mut file = File::create("my_best_friends.txt").unwrap();
256256

257257
if let Err(e) = writeln!(&mut file, "name: {}", info.name) {
258258
return Err(e)
@@ -282,7 +282,7 @@ struct Info {
282282
}
283283

284284
fn write_info(info: &Info) -> io::Result<()> {
285-
let mut file = try!(File::open("my_best_friends.txt"));
285+
let mut file = try!(File::create("my_best_friends.txt"));
286286

287287
try!(writeln!(&mut file, "name: {}", info.name));
288288
try!(writeln!(&mut file, "age: {}", info.age));

branches/snap-stage3/src/libcollections/vec.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,6 +1777,11 @@ impl<T> Iterator for IntoIter<T> {
17771777
let exact = diff / (if size == 0 {1} else {size});
17781778
(exact, Some(exact))
17791779
}
1780+
1781+
#[inline]
1782+
fn count(self) -> usize {
1783+
self.size_hint().0
1784+
}
17801785
}
17811786

17821787
#[stable(feature = "rust1", since = "1.0.0")]

branches/snap-stage3/src/libcollectionstest/vec.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,11 @@ fn test_split_off() {
542542
assert_eq!(vec2, [5, 6]);
543543
}
544544

545+
#[test]
546+
fn test_into_iter_count() {
547+
assert_eq!(vec![1, 2, 3].into_iter().count(), 3);
548+
}
549+
545550
#[bench]
546551
fn bench_new(b: &mut Bencher) {
547552
b.iter(|| {

branches/snap-stage3/src/libcore/hash/sip.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ impl SipHasher {
111111
state
112112
}
113113

114+
#[inline]
114115
fn reset(&mut self) {
115116
self.length = 0;
116117
self.v0 = self.k0 ^ 0x736f6d6570736575;
@@ -120,6 +121,7 @@ impl SipHasher {
120121
self.ntail = 0;
121122
}
122123

124+
#[inline]
123125
fn write(&mut self, msg: &[u8]) {
124126
let length = msg.len();
125127
self.length += length;
@@ -173,6 +175,7 @@ impl Hasher for SipHasher {
173175
self.write(msg)
174176
}
175177

178+
#[inline]
176179
fn finish(&self) -> u64 {
177180
let mut v0 = self.v0;
178181
let mut v1 = self.v1;

branches/snap-stage3/src/libcore/str/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ pub fn from_utf8(v: &[u8]) -> Result<&str, Utf8Error> {
136136

137137
/// Converts a slice of bytes to a string slice without checking
138138
/// that the string contains valid UTF-8.
139+
#[inline(always)]
139140
#[stable(feature = "rust1", since = "1.0.0")]
140141
pub unsafe fn from_utf8_unchecked<'a>(v: &'a [u8]) -> &'a str {
141142
mem::transmute(v)

branches/snap-stage3/src/librustc_trans/back/link.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,7 @@ fn add_local_native_libraries(cmd: &mut Command, sess: &Session) {
10781078
sess.target_filesearch(PathKind::All).for_each_lib_search_path(|path, k| {
10791079
match k {
10801080
PathKind::Framework => { cmd.arg("-F").arg(path); }
1081-
_ => { cmd.arg("-L").arg(path); }
1081+
_ => { cmd.arg("-L").arg(&fix_windows_verbatim_for_gcc(path)); }
10821082
}
10831083
FileDoesntMatch
10841084
});

branches/snap-stage3/src/librustc_trans/trans/_match.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ use trans::consts;
210210
use trans::datum::*;
211211
use trans::debuginfo::{self, DebugLoc, ToDebugLoc};
212212
use trans::expr::{self, Dest};
213+
use trans::monomorphize;
213214
use trans::tvec;
214215
use trans::type_of;
215216
use middle::ty::{self, Ty};
@@ -1076,9 +1077,39 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
10761077
let adt_vals = if any_irrefutable_adt_pat(bcx.tcx(), m, col) {
10771078
let repr = adt::represent_type(bcx.ccx(), left_ty);
10781079
let arg_count = adt::num_args(&*repr, 0);
1079-
let field_vals: Vec<ValueRef> = (0..arg_count).map(|ix|
1080-
adt::trans_field_ptr(bcx, &*repr, val, 0, ix)
1080+
let (arg_count, struct_val) = if type_is_sized(bcx.tcx(), left_ty) {
1081+
(arg_count, val)
1082+
} else {
1083+
// For an unsized ADT (i.e. DST struct), we need to treat
1084+
// the last field specially: instead of simply passing a
1085+
// ValueRef pointing to that field, as with all the others,
1086+
// we skip it and instead construct a 'fat ptr' below.
1087+
(arg_count - 1, Load(bcx, expr::get_dataptr(bcx, val)))
1088+
};
1089+
let mut field_vals: Vec<ValueRef> = (0..arg_count).map(|ix|
1090+
adt::trans_field_ptr(bcx, &*repr, struct_val, 0, ix)
10811091
).collect();
1092+
1093+
match left_ty.sty {
1094+
ty::ty_struct(def_id, substs) if !type_is_sized(bcx.tcx(), left_ty) => {
1095+
// The last field is technically unsized but
1096+
// since we can only ever match that field behind
1097+
// a reference we construct a fat ptr here.
1098+
let fields = ty::lookup_struct_fields(bcx.tcx(), def_id);
1099+
let unsized_ty = fields.iter().last().map(|field| {
1100+
let fty = ty::lookup_field_type(bcx.tcx(), def_id, field.id, substs);
1101+
monomorphize::normalize_associated_type(bcx.tcx(), &fty)
1102+
}).unwrap();
1103+
let llty = type_of::type_of(bcx.ccx(), unsized_ty);
1104+
let scratch = alloca_no_lifetime(bcx, llty, "__struct_field_fat_ptr");
1105+
let data = adt::trans_field_ptr(bcx, &*repr, struct_val, 0, arg_count);
1106+
let len = Load(bcx, expr::get_len(bcx, val));
1107+
Store(bcx, data, expr::get_dataptr(bcx, scratch));
1108+
Store(bcx, len, expr::get_len(bcx, scratch));
1109+
field_vals.push(scratch);
1110+
}
1111+
_ => {}
1112+
}
10821113
Some(field_vals)
10831114
} else if any_uniq_pat(m, col) || any_region_pat(m, col) {
10841115
Some(vec!(Load(bcx, val)))

branches/snap-stage3/src/libstd/collections/hash/map.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,9 @@ fn test_resize_policy() {
212212
/// overridden with one of the constructors.
213213
///
214214
/// It is required that the keys implement the `Eq` and `Hash` traits, although
215-
/// this can frequently be achieved by using `#[derive(Eq, Hash)]`. If you
216-
/// implement these yourself, it is important that the following property holds:
215+
/// this can frequently be achieved by using `#[derive(PartialEq, Eq, Hash)]`.
216+
/// If you implement these yourself, it is important that the following
217+
/// property holds:
217218
///
218219
/// ```text
219220
/// k1 == k2 -> hash(k1) == hash(k2)
@@ -250,26 +251,26 @@ fn test_resize_policy() {
250251
/// book_reviews.insert("The Adventures of Sherlock Holmes", "Eye lyked it alot.");
251252
///
252253
/// // check for a specific one.
253-
/// if !book_reviews.contains_key(&("Les Misérables")) {
254+
/// if !book_reviews.contains_key("Les Misérables") {
254255
/// println!("We've got {} reviews, but Les Misérables ain't one.",
255256
/// book_reviews.len());
256257
/// }
257258
///
258259
/// // oops, this review has a lot of spelling mistakes, let's delete it.
259-
/// book_reviews.remove(&("The Adventures of Sherlock Holmes"));
260+
/// book_reviews.remove("The Adventures of Sherlock Holmes");
260261
///
261262
/// // look up the values associated with some keys.
262263
/// let to_find = ["Pride and Prejudice", "Alice's Adventure in Wonderland"];
263-
/// for book in to_find.iter() {
264+
/// for book in &to_find {
264265
/// match book_reviews.get(book) {
265-
/// Some(review) => println!("{}: {}", *book, *review),
266-
/// None => println!("{} is unreviewed.", *book)
266+
/// Some(review) => println!("{}: {}", book, review),
267+
/// None => println!("{} is unreviewed.", book)
267268
/// }
268269
/// }
269270
///
270271
/// // iterate over everything.
271-
/// for (book, review) in book_reviews.iter() {
272-
/// println!("{}: \"{}\"", *book, *review);
272+
/// for (book, review) in &book_reviews {
273+
/// println!("{}: \"{}\"", book, review);
273274
/// }
274275
/// ```
275276
///
@@ -300,7 +301,7 @@ fn test_resize_policy() {
300301
/// vikings.insert(Viking::new("Harald", "Iceland"), 12);
301302
///
302303
/// // Use derived implementation to print the status of the vikings.
303-
/// for (viking, health) in vikings.iter() {
304+
/// for (viking, health) in &vikings {
304305
/// println!("{:?} has {} hp", viking, health);
305306
/// }
306307
/// ```
@@ -1600,6 +1601,7 @@ impl RandomState {
16001601
reason = "hashing an hash maps may be altered")]
16011602
impl HashState for RandomState {
16021603
type Hasher = SipHasher;
1604+
#[inline]
16031605
fn hasher(&self) -> SipHasher {
16041606
SipHasher::new_with_keys(self.k0, self.k1)
16051607
}

branches/snap-stage3/src/libstd/collections/hash/set.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ use super::state::HashState;
3131
// to get rid of it properly.
3232

3333
/// An implementation of a hash set using the underlying representation of a
34-
/// HashMap where the value is (). As with the `HashMap` type, a `HashSet`
35-
/// requires that the elements implement the `Eq` and `Hash` traits. This can
36-
/// frequently be achieved by using `#[derive(Eq, Hash)]`. If you implement
37-
/// these yourself, it is important that the following property holds:
34+
/// HashMap where the value is ().
35+
///
36+
/// As with the `HashMap` type, a `HashSet` requires that the elements
37+
/// implement the `Eq` and `Hash` traits. This can frequently be achieved by
38+
/// using `#[derive(PartialEq, Eq, Hash)]`. If you implement these yourself,
39+
/// it is important that the following property holds:
3840
///
3941
/// ```text
4042
/// k1 == k2 -> hash(k1) == hash(k2)
@@ -64,17 +66,17 @@ use super::state::HashState;
6466
/// books.insert("The Great Gatsby");
6567
///
6668
/// // Check for a specific one.
67-
/// if !books.contains(&("The Winds of Winter")) {
69+
/// if !books.contains("The Winds of Winter") {
6870
/// println!("We have {} books, but The Winds of Winter ain't one.",
6971
/// books.len());
7072
/// }
7173
///
7274
/// // Remove a book.
73-
/// books.remove(&"The Odyssey");
75+
/// books.remove("The Odyssey");
7476
///
7577
/// // Iterate over everything.
76-
/// for book in books.iter() {
77-
/// println!("{}", *book);
78+
/// for book in &books {
79+
/// println!("{}", book);
7880
/// }
7981
/// ```
8082
///
@@ -98,7 +100,7 @@ use super::state::HashState;
98100
/// vikings.insert(Viking { name: "Harald", power: 8 });
99101
///
100102
/// // Use derived implementation to print the vikings.
101-
/// for x in vikings.iter() {
103+
/// for x in &vikings {
102104
/// println!("{:?}", x);
103105
/// }
104106
/// ```

0 commit comments

Comments
 (0)