Skip to content

Commit bb9b5f5

Browse files
committed
Auto merge of #29666 - Manishearth:rollup, r=Manishearth
- Successful merges: #29617, #29622, #29656, #29659, #29660 - Failed merges:
2 parents 1e3e7e7 + d9dd67d commit bb9b5f5

File tree

10 files changed

+68
-21
lines changed

10 files changed

+68
-21
lines changed

src/compiler-rt

Submodule compiler-rt updated 95 files

src/doc/trpl/concurrency.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ languages. It will not compile:
121121

122122
```ignore
123123
use std::thread;
124+
use std::time::Duration;
124125
125126
fn main() {
126127
let mut data = vec![1, 2, 3];
@@ -131,7 +132,7 @@ fn main() {
131132
});
132133
}
133134
134-
thread::sleep_ms(50);
135+
thread::sleep(Duration::from_millis(50));
135136
}
136137
```
137138

@@ -165,6 +166,7 @@ indivisible operations which can't have data races.
165166
```ignore
166167
use std::thread;
167168
use std::sync::Arc;
169+
use std::time::Duration;
168170
169171
fn main() {
170172
let mut data = Arc::new(vec![1, 2, 3]);
@@ -176,7 +178,7 @@ fn main() {
176178
});
177179
}
178180
179-
thread::sleep_ms(50);
181+
thread::sleep(Duration::from_millis(50));
180182
}
181183
```
182184

@@ -207,6 +209,7 @@ Here's the working version:
207209
```rust
208210
use std::sync::{Arc, Mutex};
209211
use std::thread;
212+
use std::time::Duration;
210213

211214
fn main() {
212215
let data = Arc::new(Mutex::new(vec![1, 2, 3]));
@@ -219,7 +222,7 @@ fn main() {
219222
});
220223
}
221224

222-
thread::sleep_ms(50);
225+
thread::sleep(Duration::from_millis(50));
223226
}
224227
```
225228

@@ -241,6 +244,7 @@ Let's examine the body of the thread more closely:
241244
```rust
242245
# use std::sync::{Arc, Mutex};
243246
# use std::thread;
247+
# use std::time::Duration;
244248
# fn main() {
245249
# let data = Arc::new(Mutex::new(vec![1, 2, 3]));
246250
# for i in 0..3 {
@@ -250,7 +254,7 @@ thread::spawn(move || {
250254
data[i] += 1;
251255
});
252256
# }
253-
# thread::sleep_ms(50);
257+
# thread::sleep(Duration::from_millis(50));
254258
# }
255259
```
256260

src/doc/trpl/dining-philosophers.md

+13-10
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ eat. Here’s the next version:
264264

265265
```rust
266266
use std::thread;
267+
use std::time::Duration;
267268

268269
struct Philosopher {
269270
name: String,
@@ -279,7 +280,7 @@ impl Philosopher {
279280
fn eat(&self) {
280281
println!("{} is eating.", self.name);
281282

282-
thread::sleep_ms(1000);
283+
thread::sleep(Duration::from_millis(1000));
283284

284285
println!("{} is done eating.", self.name);
285286
}
@@ -313,13 +314,13 @@ from the standard library, and so we need to `use` it.
313314
fn eat(&self) {
314315
println!("{} is eating.", self.name);
315316
316-
thread::sleep_ms(1000);
317+
thread::sleep(Duration::from_millis(1000));
317318
318319
println!("{} is done eating.", self.name);
319320
}
320321
```
321322

322-
We now print out two messages, with a `sleep_ms()` in the middle. This will
323+
We now print out two messages, with a `sleep` in the middle. This will
323324
simulate the time it takes a philosopher to eat.
324325

325326
If you run this program, you should see each philosopher eat in turn:
@@ -345,6 +346,7 @@ Here’s the next iteration:
345346

346347
```rust
347348
use std::thread;
349+
use std::time::Duration;
348350

349351
struct Philosopher {
350352
name: String,
@@ -360,7 +362,7 @@ impl Philosopher {
360362
fn eat(&self) {
361363
println!("{} is eating.", self.name);
362364

363-
thread::sleep_ms(1000);
365+
thread::sleep(Duration::from_millis(1000));
364366

365367
println!("{} is done eating.", self.name);
366368
}
@@ -493,6 +495,7 @@ Let’s modify the program to use the `Table`:
493495

494496
```rust
495497
use std::thread;
498+
use std::time::Duration;
496499
use std::sync::{Mutex, Arc};
497500

498501
struct Philosopher {
@@ -512,12 +515,12 @@ impl Philosopher {
512515

513516
fn eat(&self, table: &Table) {
514517
let _left = table.forks[self.left].lock().unwrap();
515-
thread::sleep_ms(150);
518+
thread::sleep(Duration::from_millis(150));
516519
let _right = table.forks[self.right].lock().unwrap();
517520

518521
println!("{} is eating.", self.name);
519522

520-
thread::sleep_ms(1000);
523+
thread::sleep(Duration::from_millis(1000));
521524

522525
println!("{} is done eating.", self.name);
523526
}
@@ -598,12 +601,12 @@ We now need to construct those `left` and `right` values, so we add them to
598601
```rust,ignore
599602
fn eat(&self, table: &Table) {
600603
let _left = table.forks[self.left].lock().unwrap();
601-
thread::sleep_ms(150);
604+
thread::sleep(Duration::from_millis(150));
602605
let _right = table.forks[self.right].lock().unwrap();
603606
604607
println!("{} is eating.", self.name);
605608
606-
thread::sleep_ms(1000);
609+
thread::sleep(Duration::from_millis(1000));
607610
608611
println!("{} is done eating.", self.name);
609612
}
@@ -614,8 +617,8 @@ We have three new lines. We’ve added an argument, `table`. We access the
614617
the fork at that particular index. That gives us access to the `Mutex` at that
615618
index, and we call `lock()` on it. If the mutex is currently being accessed by
616619
someone else, we’ll block until it becomes available. We have also a call to
617-
`thread::sleep_ms` between the moment first fork is picked and the moment the
618-
second forked is picked, as the process of picking up the fork is not
620+
`thread::sleep` between the moment the first fork is picked and the moment the
621+
second forked is picked, as the process of picking up the fork is not
619622
immediate.
620623

621624
The call to `lock()` might fail, and if it does, we want to crash. In this

src/doc/trpl/strings.md

+23-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,29 @@ compiled program, and exists for the entire duration it runs. The `greeting`
2424
binding is a reference to this statically allocated string. String slices
2525
have a fixed size, and cannot be mutated.
2626

27-
A `String`, on the other hand, is a heap-allocated string. This string is
28-
growable, and is also guaranteed to be UTF-8. `String`s are commonly created by
29-
converting from a string slice using the `to_string` method.
27+
String literals can span multiple lines. There are two forms. The first will
28+
include the newline and the leading spaces:
29+
30+
```rust
31+
let s = "foo
32+
bar";
33+
34+
assert_eq!("foo\n bar", s);
35+
```
36+
37+
The second, with a `\`, does not trim the spaces:
38+
39+
```rust
40+
let s = "foo\
41+
bar";
42+
43+
assert_eq!("foobar", s);
44+
```
45+
46+
Rust has more than just `&str`s though. A `String`, is a heap-allocated string.
47+
This string is growable, and is also guaranteed to be UTF-8. `String`s are
48+
commonly created by converting from a string slice using the `to_string`
49+
method.
3050

3151
```rust
3252
let mut s = "Hello".to_string(); // mut s: String

src/doc/trpl/the-stack-and-the-heap.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ visualize what’s going on with memory. Your operating system presents a view o
7474
memory to your program that’s pretty simple: a huge list of addresses, from 0
7575
to a large number, representing how much RAM your computer has. For example, if
7676
you have a gigabyte of RAM, your addresses go from `0` to `1,073,741,823`. That
77-
number comes from 2<sup>30</sup>, the number of bytes in a gigabyte.
77+
number comes from 2<sup>30</sup>, the number of bytes in a gigabyte. [^gigabyte]
78+
79+
[^gigabyte]: ‘Gigabyte’ can mean two things: 10^9, or 2^30. The SI standard resolved this by stating that ‘gigabyte’ is 10^9, and ‘gibibyte’ is 2^30. However, very few people use this terminology, and rely on context to differentiate. We follow in that tradition here.
7880

7981
This memory is kind of like a giant array: addresses start at zero and go
8082
up to the final number. So here’s a diagram of our first stack frame:

src/librustc/metadata/csearch.rs

+5
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,11 @@ pub fn is_const_fn(cstore: &cstore::CStore, did: DefId) -> bool {
344344
decoder::is_const_fn(&*cdata, did.index)
345345
}
346346

347+
pub fn is_static(cstore: &cstore::CStore, did: DefId) -> bool {
348+
let cdata = cstore.get_crate_data(did.krate);
349+
decoder::is_static(&*cdata, did.index)
350+
}
351+
347352
pub fn is_impl(cstore: &cstore::CStore, did: DefId) -> bool {
348353
let cdata = cstore.get_crate_data(did.krate);
349354
decoder::is_impl(&*cdata, did.index)

src/librustc/metadata/decoder.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,14 @@ pub fn is_const_fn(cdata: Cmd, id: DefIndex) -> bool {
14251425
}
14261426
}
14271427

1428+
pub fn is_static(cdata: Cmd, id: DefIndex) -> bool {
1429+
let item_doc = cdata.lookup_item(id);
1430+
match item_family(item_doc) {
1431+
ImmStatic | MutStatic => true,
1432+
_ => false,
1433+
}
1434+
}
1435+
14281436
pub fn is_impl(cdata: Cmd, id: DefIndex) -> bool {
14291437
let item_doc = cdata.lookup_item(id);
14301438
match item_family(item_doc) {

src/librustc_trans/trans/base.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2875,7 +2875,8 @@ pub fn trans_crate<'tcx>(tcx: &ty::ctxt<'tcx>,
28752875
sess.cstore.iter_crate_data(|cnum, _| {
28762876
let syms = csearch::get_reachable_ids(&sess.cstore, cnum);
28772877
reachable_symbols.extend(syms.into_iter().filter(|did| {
2878-
csearch::is_extern_fn(&sess.cstore, *did, shared_ccx.tcx())
2878+
csearch::is_extern_fn(&sess.cstore, *did, shared_ccx.tcx()) ||
2879+
csearch::is_static(&sess.cstore, *did)
28792880
}).map(|did| {
28802881
csearch::get_symbol(&sess.cstore, did)
28812882
}));

src/test/run-make/issue-14500/foo.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
// except according to those terms.
1010

1111
extern void foo();
12+
extern char FOO_STATIC;
1213

1314
int main() {
1415
foo();
15-
return 0;
16+
return (int)FOO_STATIC;
1617
}

src/test/run-make/issue-14500/foo.rs

+3
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@
1010

1111
#[no_mangle]
1212
pub extern fn foo() {}
13+
14+
#[no_mangle]
15+
pub static FOO_STATIC: u8 = 0;

0 commit comments

Comments
 (0)