Skip to content

Commit 9a60dec

Browse files
committed
---
yaml --- r: 138363 b: refs/heads/auto c: c121cba h: refs/heads/master i: 138361: d23b144 138359: 7875d31 v: v3
1 parent 0e696c7 commit 9a60dec

34 files changed

+510
-163
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: 2a668149c26744e906018f13c33a315a1ba79bbd
16+
refs/heads/auto: c121cbab35c9ff9ba133c578976a4ec35c011bcf
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/doc/guide.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ but it will still print "Hello, world!":
482482
Compiling hello_world v0.0.1 (file:///home/you/projects/hello_world)
483483
src/main.rs:2:9: 2:10 warning: unused variable: `x`, #[warn(unused_variable)] on by default
484484
src/main.rs:2 let x: int;
485-
^
485+
^
486486
```
487487

488488
Rust warns us that we never use the variable binding, but since we never use it,
@@ -1255,8 +1255,9 @@ version, if we had forgotten the `Greater` case, for example, our program would
12551255
have happily compiled. If we forget in the `match`, it will not. Rust helps us
12561256
make sure to cover all of our bases.
12571257

1258-
`match` is also an expression, which means we can use it on the right hand side
1259-
of a `let` binding. We could also implement the previous line like this:
1258+
`match` is also an expression, which means we can use it on the right
1259+
hand side of a `let` binding or directly where an expression is
1260+
used. We could also implement the previous line like this:
12601261

12611262
```{rust}
12621263
fn cmp(a: int, b: int) -> Ordering {
@@ -1269,18 +1270,15 @@ fn main() {
12691270
let x = 5i;
12701271
let y = 10i;
12711272
1272-
let result = match cmp(x, y) {
1273+
println!("{}", match cmp(x, y) {
12731274
Less => "less",
12741275
Greater => "greater",
12751276
Equal => "equal",
1276-
};
1277-
1278-
println!("{}", result);
1277+
});
12791278
}
12801279
```
12811280

1282-
In this case, it doesn't make a lot of sense, as we are just making a temporary
1283-
string where we don't need to, but sometimes, it's a nice pattern.
1281+
Sometimes, it's a nice pattern.
12841282

12851283
# Looping
12861284

branches/auto/src/libcore/cmp.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ pub trait PartialOrd: PartialEq {
209209
fn partial_cmp(&self, other: &Self) -> Option<Ordering>;
210210

211211
/// This method tests less than (for `self` and `other`) and is used by the `<` operator.
212+
#[inline]
212213
fn lt(&self, other: &Self) -> bool {
213214
match self.partial_cmp(other) {
214215
Some(Less) => true,

branches/auto/src/librustc/middle/check_static.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,15 @@ struct GlobalChecker {
5757
static_consumptions: NodeSet,
5858
const_borrows: NodeSet,
5959
static_interior_borrows: NodeSet,
60+
static_local_borrows: NodeSet,
6061
}
6162

6263
pub fn check_crate(tcx: &ty::ctxt) {
6364
let mut checker = GlobalChecker {
6465
static_consumptions: NodeSet::new(),
6566
const_borrows: NodeSet::new(),
6667
static_interior_borrows: NodeSet::new(),
68+
static_local_borrows: NodeSet::new(),
6769
};
6870
{
6971
let visitor = euv::ExprUseVisitor::new(&mut checker, tcx);
@@ -200,6 +202,14 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckStaticVisitor<'a, 'tcx> {
200202
}
201203
}
202204

205+
// local variables in a block expression in a static context (i.e. being
206+
// assigned to a static variable) cannot be borrowed.
207+
if self.checker.static_local_borrows.remove(&e.id) {
208+
self.tcx.sess.span_err(e.span, "cannot borrow a local variable inside \
209+
a static block, define a separate static \
210+
instead");
211+
}
212+
203213
match e.node {
204214
ast::ExprAddrOf(ast::MutMutable, _) => {
205215
if self.mode != InStaticMut {
@@ -298,8 +308,12 @@ impl euv::Delegate for GlobalChecker {
298308

299309
mc::cat_downcast(..) |
300310
mc::cat_discr(..) |
301-
mc::cat_upvar(..) |
302-
mc::cat_local(..) => unreachable!(),
311+
mc::cat_upvar(..) => unreachable!(),
312+
313+
mc::cat_local(..) => {
314+
self.static_local_borrows.insert(borrow_id);
315+
break
316+
}
303317
}
304318
}
305319
}

branches/auto/src/librustc/middle/trans/_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,7 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
10901090
let sw = if kind == Switch {
10911091
build::Switch(bcx, test_val, else_cx.llbb, opts.len())
10921092
} else {
1093-
C_int(ccx, 0) // Placeholder for when not using a switch
1093+
C_int(ccx, 0i) // Placeholder for when not using a switch
10941094
};
10951095

10961096
let defaults = enter_default(else_cx, dm, m, col, val);

0 commit comments

Comments
 (0)