Skip to content

Commit b5b345b

Browse files
committed
---
yaml --- r: 137181 b: refs/heads/release-prep c: 1e22b20 h: refs/heads/master i: 137179: b2015f5 v: v3
1 parent 081ec62 commit b5b345b

File tree

12 files changed

+59
-168
lines changed

12 files changed

+59
-168
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2929
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
3030
refs/heads/libuv-update-temp-branch: 6ed22c618766f1f2a2e108eef8ce3f51be0f70b7
3131
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
32-
refs/heads/release-prep: 8794107f74682607f368776cc8b78820629778e6
32+
refs/heads/release-prep: 1e22b2088466eb0e19a58aefcbdaa29858af68e4

branches/release-prep/src/doc/guide.md

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ struct Point {
961961
}
962962

963963
fn main() {
964-
let origin = Point { x: 0i, y: 0i };
964+
let origin = Point { x: 0i, y: 0i };
965965

966966
println!("The origin is at ({}, {})", origin.x, origin.y);
967967
}
@@ -988,7 +988,7 @@ struct Point {
988988
}
989989
990990
fn main() {
991-
let mut point = Point { x: 0i, y: 0i };
991+
let mut point = Point { x: 0i, y: 0i };
992992
993993
point.x = 5;
994994
@@ -1140,13 +1140,13 @@ You can have any number of values in an enum:
11401140
```{rust}
11411141
enum OptionalColor {
11421142
Color(int, int, int),
1143-
Missing,
1143+
Missing
11441144
}
11451145
```
11461146

11471147
Enums with values are quite useful, but as I mentioned, they're even more
11481148
useful when they're generic across types. But before we get to generics, let's
1149-
talk about how to fix these big `if`/`else` statements we've been writing. We'll
1149+
talk about how to fix this big `if`/`else` statements we've been writing. We'll
11501150
do that with `match`.
11511151

11521152
# Match
@@ -1561,7 +1561,7 @@ println!("The second name is: {}", names[1]);
15611561

15621562
These subscripts start at zero, like in most programming languages, so the
15631563
first name is `names[0]` and the second name is `names[1]`. The above example
1564-
prints `The second name is: Brian`.
1564+
prints `The second name is Brian`.
15651565

15661566
There's a whole lot more to vectors, but that's enough to get started. We have
15671567
now learned all of the most basic Rust concepts. We're ready to start building
@@ -2084,7 +2084,7 @@ fn main() {
20842084
match cmp(input, secret_number) {
20852085
Less => println!("Too small!"),
20862086
Greater => println!("Too big!"),
2087-
Equal => println!("You win!"),
2087+
Equal => { println!("You win!"); },
20882088
}
20892089
}
20902090
@@ -2176,12 +2176,14 @@ fn main() {
21762176
.expect("Failed to read line");
21772177
let input_num: Option<uint> = from_str(input.as_slice());
21782178
2179+
2180+
21792181
println!("You guessed: {}", input_num);
21802182
21812183
match cmp(input_num, secret_number) {
21822184
Less => println!("Too small!"),
21832185
Greater => println!("Too big!"),
2184-
Equal => println!("You win!"),
2186+
Equal => { println!("You win!"); },
21852187
}
21862188
}
21872189
@@ -2239,7 +2241,7 @@ fn main() {
22392241
match cmp(num, secret_number) {
22402242
Less => println!("Too small!"),
22412243
Greater => println!("Too big!"),
2242-
Equal => println!("You win!"),
2244+
Equal => { println!("You win!"); },
22432245
}
22442246
}
22452247
@@ -2305,7 +2307,7 @@ fn main() {
23052307
match cmp(num, secret_number) {
23062308
Less => println!("Too small!"),
23072309
Greater => println!("Too big!"),
2308-
Equal => println!("You win!"),
2310+
Equal => { println!("You win!"); },
23092311
}
23102312
}
23112313
@@ -2380,7 +2382,7 @@ fn main() {
23802382
match cmp(num, secret_number) {
23812383
Less => println!("Too small!"),
23822384
Greater => println!("Too big!"),
2383-
Equal => println!("You win!"),
2385+
Equal => { println!("You win!"); },
23842386
}
23852387
}
23862388
}
@@ -2617,7 +2619,7 @@ Rust's more unique features.
26172619

26182620
Rust features a strong module system, but it works a bit differently than in
26192621
other programming languages. Rust's module system has two main components:
2620-
**crate**s and **module**s.
2622+
**crate**s, and **module**s.
26212623

26222624
A crate is Rust's unit of independent compilation. Rust always compiles one
26232625
crate at a time, producing either a library or an executable. However, executables
@@ -2638,7 +2640,6 @@ Enough talk, let's build something! Let's make a new project called `modules`.
26382640
```{bash,ignore}
26392641
$ cd ~/projects
26402642
$ cargo new modules --bin
2641-
$ cd modules
26422643
```
26432644

26442645
Let's double check our work by compiling:
@@ -3621,7 +3622,7 @@ let x = box 5i;
36213622
```
36223623

36233624
This allocates an integer `5` on the heap, and creates a binding `x` that
3624-
refers to it. The great thing about boxed pointers is that we don't have to
3625+
refers to it.. The great thing about boxed pointers is that we don't have to
36253626
manually free this allocation! If we write
36263627

36273628
```{rust}
@@ -3993,7 +3994,7 @@ Let's make a closure:
39933994
```{rust}
39943995
let add_one = |x| { 1i + x };
39953996
3996-
println!("The sum of 5 plus 1 is {}.", add_one(5i));
3997+
println!("The 5 plus 1 is {}.", add_one(5i));
39973998
```
39983999

39994000
We create a closure using the `|...| { ... }` syntax, and then we create a
@@ -4088,7 +4089,7 @@ fn main() {
40884089
}
40894090
```
40904091

4091-
Let's break the example down, starting with `main`:
4092+
Let's break example down, starting with `main`:
40924093

40934094
```{rust}
40944095
let square = |x: int| { x * x };
@@ -4209,7 +4210,7 @@ loop {
42094210
match range.next() {
42104211
Some(x) => {
42114212
println!("{}", x);
4212-
},
4213+
}
42134214
None => { break }
42144215
}
42154216
}
@@ -5073,7 +5074,7 @@ The `channel()` function returns two endpoints: a `Receiver<T>` and a
50735074
`Sender<T>`. You can use the `.send()` method on the `Sender<T>` end, and
50745075
receive the message on the `Receiver<T>` side with the `recv()` method. This
50755076
method blocks until it gets a message. There's a similar method, `.try_recv()`,
5076-
which returns an `Result<T, TryRecvError>` and does not block.
5077+
which returns an `Option<T>` and does not block.
50775078

50785079
If you want to send messages to the task as well, create two channels!
50795080

branches/release-prep/src/libcollections/string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ impl String {
269269
/// ```
270270
#[unstable = "error value in return may change"]
271271
pub fn from_utf16(v: &[u16]) -> Option<String> {
272-
let mut s = String::with_capacity(v.len());
272+
let mut s = String::with_capacity(v.len() / 2);
273273
for c in str::utf16_items(v) {
274274
match c {
275275
str::ScalarValue(c) => s.push(c),

branches/release-prep/src/librustc/middle/mem_categorization.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -596,21 +596,17 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
596596
ty::FnMutUnboxedClosureKind => ast::Many,
597597
ty::FnOnceUnboxedClosureKind => ast::Once,
598598
};
599-
if self.typer.capture_mode(fn_node_id) == ast::CaptureByRef {
600-
self.cat_upvar(id, span, var_id, fn_node_id)
601-
} else {
602-
Ok(Rc::new(cmt_ {
603-
id: id,
604-
span: span,
605-
cat: cat_copied_upvar(CopiedUpvar {
606-
upvar_id: var_id,
607-
onceness: onceness,
608-
capturing_proc: fn_node_id,
609-
}),
610-
mutbl: MutabilityCategory::from_local(self.tcx(), var_id),
611-
ty: expr_ty
612-
}))
613-
}
599+
Ok(Rc::new(cmt_ {
600+
id: id,
601+
span: span,
602+
cat: cat_copied_upvar(CopiedUpvar {
603+
upvar_id: var_id,
604+
onceness: onceness,
605+
capturing_proc: fn_node_id,
606+
}),
607+
mutbl: MutabilityCategory::from_local(self.tcx(), var_id),
608+
ty: expr_ty
609+
}))
614610
}
615611
_ => {
616612
self.tcx().sess.span_bug(

branches/release-prep/src/librustc/middle/trans/closure.rs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,6 @@ fn load_environment<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
301301
fn load_unboxed_closure_environment<'blk, 'tcx>(
302302
bcx: Block<'blk, 'tcx>,
303303
arg_scope_id: ScopeId,
304-
freevar_mode: ast::CaptureClause,
305304
freevars: &Vec<ty::Freevar>,
306305
closure_id: ast::DefId)
307306
-> Block<'blk, 'tcx> {
@@ -327,14 +326,11 @@ fn load_unboxed_closure_environment<'blk, 'tcx>(
327326
};
328327

329328
for (i, freevar) in freevars.iter().enumerate() {
330-
let mut upvar_ptr = GEPi(bcx, llenv, [0, i]);
331-
if freevar_mode == ast::CaptureByRef {
332-
upvar_ptr = Load(bcx, upvar_ptr);
333-
}
329+
let upvar_ptr = GEPi(bcx, llenv, [0, i]);
334330
let def_id = freevar.def.def_id();
335331
bcx.fcx.llupvars.borrow_mut().insert(def_id.node, upvar_ptr);
336332

337-
if kind == ty::FnOnceUnboxedClosureKind && freevar_mode == ast::CaptureByValue {
333+
if kind == ty::FnOnceUnboxedClosureKind {
338334
bcx.fcx.schedule_drop_mem(arg_scope_id,
339335
upvar_ptr,
340336
node_id_type(bcx, def_id.node))
@@ -481,7 +477,6 @@ pub fn trans_unboxed_closure<'blk, 'tcx>(
481477
let freevars: Vec<ty::Freevar> =
482478
ty::with_freevars(bcx.tcx(), id, |fv| fv.iter().map(|&fv| fv).collect());
483479
let freevars_ptr = &freevars;
484-
let freevar_mode = bcx.tcx().capture_mode(id);
485480

486481
trans_closure(bcx.ccx(),
487482
decl,
@@ -498,7 +493,6 @@ pub fn trans_unboxed_closure<'blk, 'tcx>(
498493
|bcx, arg_scope| {
499494
load_unboxed_closure_environment(bcx,
500495
arg_scope,
501-
freevar_mode,
502496
freevars_ptr,
503497
closure_id)
504498
});
@@ -524,14 +518,7 @@ pub fn trans_unboxed_closure<'blk, 'tcx>(
524518
dest_addr,
525519
0,
526520
i);
527-
match freevar_mode {
528-
ast::CaptureByValue => {
529-
bcx = datum.store_to(bcx, upvar_slot_dest);
530-
}
531-
ast::CaptureByRef => {
532-
Store(bcx, datum.to_llref(), upvar_slot_dest);
533-
}
534-
}
521+
bcx = datum.store_to(bcx, upvar_slot_dest);
535522
}
536523
adt::trans_set_discr(bcx, &*repr, dest_addr, 0);
537524

branches/release-prep/src/librustc/middle/ty.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4634,27 +4634,15 @@ pub struct UnboxedClosureUpvar {
46344634
pub fn unboxed_closure_upvars(tcx: &ctxt, closure_id: ast::DefId)
46354635
-> Vec<UnboxedClosureUpvar> {
46364636
if closure_id.krate == ast::LOCAL_CRATE {
4637-
let capture_mode = tcx.capture_modes.borrow().get_copy(&closure_id.node);
46384637
match tcx.freevars.borrow().find(&closure_id.node) {
46394638
None => vec![],
46404639
Some(ref freevars) => {
46414640
freevars.iter().map(|freevar| {
46424641
let freevar_def_id = freevar.def.def_id();
4643-
let mut freevar_ty = node_id_to_type(tcx, freevar_def_id.node);
4644-
if capture_mode == ast::CaptureByRef {
4645-
let borrow = tcx.upvar_borrow_map.borrow().get_copy(&ty::UpvarId {
4646-
var_id: freevar_def_id.node,
4647-
closure_expr_id: closure_id.node
4648-
});
4649-
freevar_ty = mk_rptr(tcx, borrow.region, ty::mt {
4650-
ty: freevar_ty,
4651-
mutbl: borrow.kind.to_mutbl_lossy()
4652-
});
4653-
}
46544642
UnboxedClosureUpvar {
46554643
def: freevar.def,
46564644
span: freevar.span,
4657-
ty: freevar_ty
4645+
ty: node_id_to_type(tcx, freevar_def_id.node),
46584646
}
46594647
}).collect()
46604648
}

branches/release-prep/src/librustc/middle/typeck/check/regionck.rs

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ fn check_expr_fn_block(rcx: &mut Rcx,
836836
// has static lifetime.
837837
} else {
838838
// Variables being referenced must outlive closure.
839-
constrain_free_variables_in_by_ref_closure(
839+
constrain_free_variables_in_stack_closure(
840840
rcx, bounds.region_bound, expr, freevars);
841841

842842
// Closure is stack allocated and hence cannot
@@ -848,17 +848,20 @@ fn check_expr_fn_block(rcx: &mut Rcx,
848848
});
849849
}
850850
ty::ty_unboxed_closure(_, region) => {
851-
let bounds = ty::region_existential_bound(region);
852-
if tcx.capture_modes.borrow().get_copy(&expr.id) == ast::CaptureByRef {
853-
ty::with_freevars(tcx, expr.id, |freevars| {
854-
if !freevars.is_empty() {
855-
// Variables being referenced must be constrained and registered
856-
// in the upvar borrow map
857-
constrain_free_variables_in_by_ref_closure(
858-
rcx, bounds.region_bound, expr, freevars);
859-
}
860-
})
861-
}
851+
ty::with_freevars(tcx, expr.id, |freevars| {
852+
// No free variables means that there is no environment and
853+
// hence the closure has static lifetime. Otherwise, the
854+
// closure must not outlive the variables it closes over
855+
// by-reference.
856+
//
857+
// NDM -- this seems wrong, discuss with pcwalton, should
858+
// be straightforward enough.
859+
if !freevars.is_empty() {
860+
let bounds = ty::region_existential_bound(region);
861+
ensure_free_variable_types_outlive_closure_bound(
862+
rcx, bounds, expr, freevars);
863+
}
864+
})
862865
}
863866
_ => { }
864867
}
@@ -873,13 +876,6 @@ fn check_expr_fn_block(rcx: &mut Rcx,
873876
propagate_upupvar_borrow_kind(rcx, expr, freevars);
874877
})
875878
}
876-
ty::ty_unboxed_closure(..) => {
877-
if tcx.capture_modes.borrow().get_copy(&expr.id) == ast::CaptureByRef {
878-
ty::with_freevars(tcx, expr.id, |freevars| {
879-
propagate_upupvar_borrow_kind(rcx, expr, freevars);
880-
});
881-
}
882-
}
883879
_ => {}
884880
}
885881

@@ -889,12 +885,6 @@ fn check_expr_fn_block(rcx: &mut Rcx,
889885
ensure_free_variable_types_outlive_closure_bound(rcx, bounds, expr, freevars);
890886
})
891887
}
892-
ty::ty_unboxed_closure(_, region) => {
893-
ty::with_freevars(tcx, expr.id, |freevars| {
894-
let bounds = ty::region_existential_bound(region);
895-
ensure_free_variable_types_outlive_closure_bound(rcx, bounds, expr, freevars);
896-
})
897-
}
898888
_ => {}
899889
}
900890

@@ -961,7 +951,7 @@ fn check_expr_fn_block(rcx: &mut Rcx,
961951
}
962952
}
963953

964-
fn constrain_free_variables_in_by_ref_closure(
954+
fn constrain_free_variables_in_stack_closure(
965955
rcx: &mut Rcx,
966956
region_bound: ty::Region,
967957
expr: &ast::Expr,

branches/release-prep/src/test/compile-fail/unboxed-closure-region.rs

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)