Skip to content

Commit 4e1c791

Browse files
committed
---
yaml --- r: 67016 b: refs/heads/master c: 78f8b40 h: refs/heads/master v: v3
1 parent 37978a2 commit 4e1c791

File tree

11 files changed

+150
-195
lines changed

11 files changed

+150
-195
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 93fa7a4b09d755e1dba3a71f56b3dc34d900776f
2+
refs/heads/master: 78f8b407e3ab5590a57467fce1febd5289bf7fe5
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 18e3db7392d2d0697b7e27d6d986139960144d85
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9

trunk/doc/rust.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,41 @@ static bits_n_strings: BitsNStrings<'static> = BitsNStrings {
11221122
};
11231123
~~~~
11241124

1125+
#### Mutable statics
1126+
1127+
If a static item is declared with the ```mut``` keyword, then it is allowed to
1128+
be modified by the program. One of Rust's goals is to make concurrency bugs hard
1129+
to run into, and this is obviously a very large source of race conditions or
1130+
other bugs. For this reason, an ```unsafe``` block is required when either
1131+
reading or writing a mutable static variable. Care should be taken to ensure
1132+
that modifications to a mutable static are safe with respect to other tasks
1133+
running in the same process.
1134+
1135+
Mutable statics are still very useful, however. They can be used with C
1136+
libraries and can also be bound from C libraries (in an ```extern``` block).
1137+
1138+
~~~
1139+
# fn atomic_add(_: &mut uint, _: uint) -> uint { 2 }
1140+
1141+
static mut LEVELS: uint = 0;
1142+
1143+
// This violates the idea of no shared state, and this doesn't internally
1144+
// protect against races, so this function is `unsafe`
1145+
unsafe fn bump_levels_unsafe1() -> uint {
1146+
let ret = LEVELS;
1147+
LEVELS += 1;
1148+
return ret;
1149+
}
1150+
1151+
// Assuming that we have an atomic_add function which returns the old value,
1152+
// this function is "safe" but the meaning of the return value may not be what
1153+
// callers expect, so it's still marked as `unsafe`
1154+
unsafe fn bump_levels_unsafe2() -> uint {
1155+
return atomic_add(&mut LEVELS, 1);
1156+
}
1157+
1158+
~~~
1159+
11251160
### Traits
11261161

11271162
A _trait_ describes a set of method types.

trunk/doc/tutorial.md

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ supported build environments that are most likely to work.
8484
> know.
8585
8686
[bug-3319]: https://github.com/mozilla/rust/issues/3319
87-
[wiki-start]: https://github.com/mozilla/rust/wiki/Note-getting-started-developing-Rust
87+
[wiki-start]: https://github.com/mozilla/rust/wiki/Note-getting-started-developing-Rust
8888

8989
To build from source you will also need the following prerequisite
9090
packages:
@@ -118,7 +118,6 @@ API-documentation tool; `rustpkg`, the Rust package manager;
118118
`rusti`, the Rust REPL; and `rust`, a tool which acts both as a unified
119119
interface for them, and for a few common command line scenarios.
120120

121-
[wiki-start]: https://github.com/mozilla/rust/wiki/Note-getting-started-developing-Rust
122121
[tarball]: http://static.rust-lang.org/dist/rust-0.7.tar.gz
123122
[win-exe]: http://static.rust-lang.org/dist/rust-0.7-install.exe
124123

@@ -410,8 +409,6 @@ println(fmt!("what is this thing: %?", mystery_object));
410409

411410
You can define your own syntax extensions with the macro system. For details, see the [macro tutorial][macros].
412411

413-
[macros]: tutorial-macros.html
414-
415412
# Control structures
416413

417414
## Conditionals
@@ -1517,8 +1514,6 @@ closures, but they also own them: that is, no other code can access
15171514
them. Owned closures are used in concurrent code, particularly
15181515
for spawning [tasks][tasks].
15191516

1520-
[tasks]: tutorial-tasks.html
1521-
15221517
## Closure compatibility
15231518

15241519
Rust closures have a convenient subtyping property: you can pass any kind of
@@ -2543,9 +2538,4 @@ There is further documentation on the [wiki].
25432538
[ffi]: tutorial-ffi.html
25442539

25452540
[wiki]: https://github.com/mozilla/rust/wiki/Docs
2546-
[unit testing]: https://github.com/mozilla/rust/wiki/Doc-unit-testing
2547-
[rustdoc]: https://github.com/mozilla/rust/wiki/Doc-using-rustdoc
2548-
[cargo]: https://github.com/mozilla/rust/wiki/Doc-using-cargo-to-manage-packages
2549-
[attributes]: https://github.com/mozilla/rust/wiki/Doc-attributes
25502541

2551-
[pound-rust]: http://chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust

trunk/src/libextra/json.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,9 +1086,8 @@ impl serialize::Decoder for Decoder {
10861086
debug!("read_map()");
10871087
let len = match self.stack.pop() {
10881088
Object(obj) => {
1089-
let mut obj = obj;
10901089
let len = obj.len();
1091-
do obj.consume |key, value| {
1090+
for obj.consume().advance |(key, value)| {
10921091
self.stack.push(value);
10931092
self.stack.push(String(key));
10941093
}

trunk/src/librustc/middle/borrowck/check_loans.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,10 @@ use syntax::codemap::span;
3131
use syntax::visit;
3232
use util::ppaux::Repr;
3333

34-
#[deriving(Clone)]
3534
struct CheckLoanCtxt<'self> {
3635
bccx: @BorrowckCtxt,
3736
dfcx_loans: &'self LoanDataFlow,
38-
move_data: @move_data::FlowedMoveData,
37+
move_data: move_data::FlowedMoveData,
3938
all_loans: &'self [Loan],
4039
reported: @mut HashSet<ast::node_id>,
4140
}
@@ -47,10 +46,10 @@ pub fn check_loans(bccx: @BorrowckCtxt,
4746
body: &ast::blk) {
4847
debug!("check_loans(body id=%?)", body.id);
4948

50-
let clcx = CheckLoanCtxt {
49+
let clcx = @mut CheckLoanCtxt {
5150
bccx: bccx,
5251
dfcx_loans: dfcx_loans,
53-
move_data: @move_data,
52+
move_data: move_data,
5453
all_loans: all_loans,
5554
reported: @mut HashSet::new(),
5655
};
@@ -140,7 +139,7 @@ impl<'self> CheckLoanCtxt<'self> {
140139
return result;
141140
}
142141

143-
pub fn check_for_conflicting_loans(&self, scope_id: ast::node_id) {
142+
pub fn check_for_conflicting_loans(&mut self, scope_id: ast::node_id) {
144143
//! Checks to see whether any of the loans that are issued
145144
//! by `scope_id` conflict with loans that have already been
146145
//! issued when we enter `scope_id` (for example, we do not
@@ -597,7 +596,7 @@ impl<'self> CheckLoanCtxt<'self> {
597596
MoveOk
598597
}
599598

600-
pub fn check_call(&self,
599+
pub fn check_call(&mut self,
601600
_expr: @ast::expr,
602601
_callee: Option<@ast::expr>,
603602
_callee_id: ast::node_id,
@@ -618,8 +617,8 @@ fn check_loans_in_fn<'a>(fk: &visit::fn_kind,
618617
body: &ast::blk,
619618
sp: span,
620619
id: ast::node_id,
621-
(this, visitor): (CheckLoanCtxt<'a>,
622-
visit::vt<CheckLoanCtxt<'a>>)) {
620+
(this, visitor): (@mut CheckLoanCtxt<'a>,
621+
visit::vt<@mut CheckLoanCtxt<'a>>)) {
623622
match *fk {
624623
visit::fk_item_fn(*) |
625624
visit::fk_method(*) => {
@@ -635,7 +634,7 @@ fn check_loans_in_fn<'a>(fk: &visit::fn_kind,
635634

636635
visit::visit_fn(fk, decl, body, sp, id, (this, visitor));
637636

638-
fn check_captured_variables(this: CheckLoanCtxt,
637+
fn check_captured_variables(this: @mut CheckLoanCtxt,
639638
closure_id: ast::node_id,
640639
span: span) {
641640
let cap_vars = this.bccx.capture_map.get(&closure_id);
@@ -653,7 +652,7 @@ fn check_loans_in_fn<'a>(fk: &visit::fn_kind,
653652
}
654653
return;
655654

656-
fn check_by_move_capture(this: CheckLoanCtxt,
655+
fn check_by_move_capture(this: @mut CheckLoanCtxt,
657656
closure_id: ast::node_id,
658657
cap_var: &moves::CaptureVar,
659658
move_path: @LoanPath) {
@@ -677,14 +676,14 @@ fn check_loans_in_fn<'a>(fk: &visit::fn_kind,
677676
}
678677

679678
fn check_loans_in_local<'a>(local: @ast::local,
680-
(this, vt): (CheckLoanCtxt<'a>,
681-
visit::vt<CheckLoanCtxt<'a>>)) {
679+
(this, vt): (@mut CheckLoanCtxt<'a>,
680+
visit::vt<@mut CheckLoanCtxt<'a>>)) {
682681
visit::visit_local(local, (this, vt));
683682
}
684683

685684
fn check_loans_in_expr<'a>(expr: @ast::expr,
686-
(this, vt): (CheckLoanCtxt<'a>,
687-
visit::vt<CheckLoanCtxt<'a>>)) {
685+
(this, vt): (@mut CheckLoanCtxt<'a>,
686+
visit::vt<@mut CheckLoanCtxt<'a>>)) {
688687
visit::visit_expr(expr, (this, vt));
689688

690689
debug!("check_loans_in_expr(expr=%s)",
@@ -737,17 +736,17 @@ fn check_loans_in_expr<'a>(expr: @ast::expr,
737736
}
738737

739738
fn check_loans_in_pat<'a>(pat: @ast::pat,
740-
(this, vt): (CheckLoanCtxt<'a>,
741-
visit::vt<CheckLoanCtxt<'a>>))
739+
(this, vt): (@mut CheckLoanCtxt<'a>,
740+
visit::vt<@mut CheckLoanCtxt<'a>>))
742741
{
743742
this.check_for_conflicting_loans(pat.id);
744743
this.check_move_out_from_id(pat.id, pat.span);
745744
visit::visit_pat(pat, (this, vt));
746745
}
747746

748747
fn check_loans_in_block<'a>(blk: &ast::blk,
749-
(this, vt): (CheckLoanCtxt<'a>,
750-
visit::vt<CheckLoanCtxt<'a>>))
748+
(this, vt): (@mut CheckLoanCtxt<'a>,
749+
visit::vt<@mut CheckLoanCtxt<'a>>))
751750
{
752751
visit::visit_block(blk, (this, vt));
753752
this.check_for_conflicting_loans(blk.id);

0 commit comments

Comments
 (0)