Skip to content

Commit 6f3f61d

Browse files
committed
---
yaml --- r: 275993 b: refs/heads/master c: b9dd8aa h: refs/heads/master i: 275991: 884c337
1 parent 1cbe538 commit 6f3f61d

Some content is hidden

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

64 files changed

+1402
-1034
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: e6b9760df21f580e8210f97c01a957a91eeb91b5
2+
refs/heads/master: b9dd8aa4c291ce464655735802e68b26fe9c6862
33
refs/heads/snap-stage3: 235d77457d80b549dad3ac36d94f235208a1eafb
44
refs/heads/try: 49312a405e14a449b98fe0056b12a40ac128be4a
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

trunk/src/doc/book/lifetimes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
% Lifetimes
22

3-
This guide is three of three presenting Rust’s ownership system. This is one of
4-
Rust’s most unique and compelling features, with which Rust developers should
3+
This is the last of three sections presenting Rust’s ownership system. This is one of
4+
Rust’s most distinct and compelling features, with which Rust developers should
55
become quite acquainted. Ownership is how Rust achieves its largest goal,
66
memory safety. There are a few distinct concepts, each with its own chapter:
77

trunk/src/doc/book/ownership.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
% Ownership
22

3-
This guide is one of three presenting Rust’s ownership system. This is one of
4-
Rust’s most unique and compelling features, with which Rust developers should
3+
This is the first of three sections presenting Rust’s ownership system. This is one of
4+
Rust’s most distinct and compelling features, with which Rust developers should
55
become quite acquainted. Ownership is how Rust achieves its largest goal,
66
memory safety. There are a few distinct concepts, each with its own
77
chapter:

trunk/src/doc/book/references-and-borrowing.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
% References and Borrowing
22

3-
This guide is two of three presenting Rust’s ownership system. This is one of
4-
Rust’s most unique and compelling features, with which Rust developers should
3+
This is the second of three sections presenting Rust’s ownership system. This is one of
4+
Rust’s most distinct and compelling features, with which Rust developers should
55
become quite acquainted. Ownership is how Rust achieves its largest goal,
66
memory safety. There are a few distinct concepts, each with its own
77
chapter:
@@ -77,6 +77,32 @@ let answer = foo(&v1, &v2);
7777
// we can use v1 and v2 here!
7878
```
7979

80+
A more concrete example:
81+
82+
```rust
83+
fn main() {
84+
// Don't worry if you don't understand how `fold` works, the point here is that an immutable reference is borrowed.
85+
fn sum_vec(v: &Vec<i32>) -> i32 {
86+
return v.iter().fold(0, |a, &b| a + b);
87+
}
88+
// Borrow two vectors and and sum them.
89+
// This kind of borrowing does not allow mutation to the borrowed.
90+
fn foo(v1: &Vec<i32>, v2: &Vec<i32>) -> i32 {
91+
// do stuff with v1 and v2
92+
let s1 = sum_vec(v1);
93+
let s2 = sum_vec(v2);
94+
// return the answer
95+
s1 + s2
96+
}
97+
98+
let v1 = vec![1, 2, 3];
99+
let v2 = vec![4, 5, 6];
100+
101+
let answer = foo(&v1, &v2);
102+
println!("{}", answer);
103+
}
104+
```
105+
80106
Instead of taking `Vec<i32>`s as our arguments, we take a reference:
81107
`&Vec<i32>`. And instead of passing `v1` and `v2` directly, we pass `&v1` and
82108
`&v2`. We call the `&T` type a ‘reference’, and rather than owning the resource,

trunk/src/libcore/ptr.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,9 @@ impl<T: ?Sized> *mut T {
459459
/// ```
460460
/// let mut s = [1, 2, 3];
461461
/// let ptr: *mut u32 = s.as_mut_ptr();
462+
/// let first_value = unsafe { ptr.as_mut().unwrap() };
463+
/// *first_value = 4;
464+
/// println!("{:?}", s); // It'll print: "[4, 2, 3]".
462465
/// ```
463466
#[stable(feature = "ptr_as_ref", since = "1.9.0")]
464467
#[inline]

trunk/src/librustc/infer/error_reporting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl<'tcx> TyCtxt<'tcx> {
157157
"scope of call-site for function"
158158
}
159159
region::CodeExtentData::ParameterScope { .. } => {
160-
"scope of parameters for function"
160+
"scope of function body"
161161
}
162162
region::CodeExtentData::DestructionScope(_) => {
163163
new_string = format!("destruction scope surrounding {}", tag);

trunk/src/librustc_const_eval/eval.rs

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -562,44 +562,51 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &TyCtxt<'tcx>,
562562
let result = match e.node {
563563
hir::ExprUnary(hir::UnNeg, ref inner) => {
564564
// unary neg literals already got their sign during creation
565-
if let hir::ExprLit(ref lit) = inner.node {
566-
use syntax::ast::*;
567-
use syntax::ast::LitIntType::*;
568-
const I8_OVERFLOW: u64 = ::std::i8::MAX as u64 + 1;
569-
const I16_OVERFLOW: u64 = ::std::i16::MAX as u64 + 1;
570-
const I32_OVERFLOW: u64 = ::std::i32::MAX as u64 + 1;
571-
const I64_OVERFLOW: u64 = ::std::i64::MAX as u64 + 1;
572-
match (&lit.node, ety.map(|t| &t.sty)) {
573-
(&LitKind::Int(I8_OVERFLOW, Unsuffixed), Some(&ty::TyInt(IntTy::I8))) |
574-
(&LitKind::Int(I8_OVERFLOW, Signed(IntTy::I8)), _) => {
575-
return Ok(Integral(I8(::std::i8::MIN)))
576-
},
577-
(&LitKind::Int(I16_OVERFLOW, Unsuffixed), Some(&ty::TyInt(IntTy::I16))) |
578-
(&LitKind::Int(I16_OVERFLOW, Signed(IntTy::I16)), _) => {
579-
return Ok(Integral(I16(::std::i16::MIN)))
580-
},
581-
(&LitKind::Int(I32_OVERFLOW, Unsuffixed), Some(&ty::TyInt(IntTy::I32))) |
582-
(&LitKind::Int(I32_OVERFLOW, Signed(IntTy::I32)), _) => {
583-
return Ok(Integral(I32(::std::i32::MIN)))
584-
},
585-
(&LitKind::Int(I64_OVERFLOW, Unsuffixed), Some(&ty::TyInt(IntTy::I64))) |
586-
(&LitKind::Int(I64_OVERFLOW, Signed(IntTy::I64)), _) => {
587-
return Ok(Integral(I64(::std::i64::MIN)))
588-
},
589-
(&LitKind::Int(n, Unsuffixed), Some(&ty::TyInt(IntTy::Is))) |
590-
(&LitKind::Int(n, Signed(IntTy::Is)), _) => {
591-
match tcx.sess.target.int_type {
592-
IntTy::I32 => if n == I32_OVERFLOW {
593-
return Ok(Integral(Isize(Is32(::std::i32::MIN))));
594-
},
595-
IntTy::I64 => if n == I64_OVERFLOW {
596-
return Ok(Integral(Isize(Is64(::std::i64::MIN))));
597-
},
598-
_ => bug!(),
599-
}
600-
},
601-
_ => {},
602-
}
565+
match inner.node {
566+
hir::ExprLit(ref lit) => {
567+
use syntax::ast::*;
568+
use syntax::ast::LitIntType::*;
569+
const I8_OVERFLOW: u64 = ::std::i8::MAX as u64 + 1;
570+
const I16_OVERFLOW: u64 = ::std::i16::MAX as u64 + 1;
571+
const I32_OVERFLOW: u64 = ::std::i32::MAX as u64 + 1;
572+
const I64_OVERFLOW: u64 = ::std::i64::MAX as u64 + 1;
573+
match (&lit.node, ety.map(|t| &t.sty)) {
574+
(&LitKind::Int(I8_OVERFLOW, Unsuffixed), Some(&ty::TyInt(IntTy::I8))) |
575+
(&LitKind::Int(I8_OVERFLOW, Signed(IntTy::I8)), _) => {
576+
return Ok(Integral(I8(::std::i8::MIN)))
577+
},
578+
(&LitKind::Int(I16_OVERFLOW, Unsuffixed), Some(&ty::TyInt(IntTy::I16))) |
579+
(&LitKind::Int(I16_OVERFLOW, Signed(IntTy::I16)), _) => {
580+
return Ok(Integral(I16(::std::i16::MIN)))
581+
},
582+
(&LitKind::Int(I32_OVERFLOW, Unsuffixed), Some(&ty::TyInt(IntTy::I32))) |
583+
(&LitKind::Int(I32_OVERFLOW, Signed(IntTy::I32)), _) => {
584+
return Ok(Integral(I32(::std::i32::MIN)))
585+
},
586+
(&LitKind::Int(I64_OVERFLOW, Unsuffixed), Some(&ty::TyInt(IntTy::I64))) |
587+
(&LitKind::Int(I64_OVERFLOW, Signed(IntTy::I64)), _) => {
588+
return Ok(Integral(I64(::std::i64::MIN)))
589+
},
590+
(&LitKind::Int(n, Unsuffixed), Some(&ty::TyInt(IntTy::Is))) |
591+
(&LitKind::Int(n, Signed(IntTy::Is)), _) => {
592+
match tcx.sess.target.int_type {
593+
IntTy::I32 => if n == I32_OVERFLOW {
594+
return Ok(Integral(Isize(Is32(::std::i32::MIN))));
595+
},
596+
IntTy::I64 => if n == I64_OVERFLOW {
597+
return Ok(Integral(Isize(Is64(::std::i64::MIN))));
598+
},
599+
_ => bug!(),
600+
}
601+
},
602+
_ => {},
603+
}
604+
},
605+
hir::ExprUnary(hir::UnNeg, ref inner) => {
606+
// skip `--$expr`
607+
return eval_const_expr_partial(tcx, inner, ty_hint, fn_args);
608+
},
609+
_ => {},
603610
}
604611
match eval_const_expr_partial(tcx, &inner, ty_hint, fn_args)? {
605612
Float(f) => Float(-f),

trunk/src/librustc_const_math/int.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ impl ::std::ops::Shr<ConstInt> for ConstInt {
503503
I8(a) => Ok(I8(overflowing!(a.overflowing_shr(b), Op::Shr))),
504504
I16(a) => Ok(I16(overflowing!(a.overflowing_shr(b), Op::Shr))),
505505
I32(a) => Ok(I32(overflowing!(a.overflowing_shr(b), Op::Shr))),
506-
I64(a) => Ok(I64(overflowing!(a.overflowing_shr(b), Op::Shl))),
506+
I64(a) => Ok(I64(overflowing!(a.overflowing_shr(b), Op::Shr))),
507507
Isize(Is32(a)) => Ok(Isize(Is32(overflowing!(a.overflowing_shr(b), Op::Shr)))),
508508
Isize(Is64(a)) => Ok(Isize(Is64(overflowing!(a.overflowing_shr(b), Op::Shr)))),
509509
U8(a) => Ok(U8(overflowing!(a.overflowing_shr(b), Op::Shr))),

trunk/src/librustc_const_math/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ mod err;
4040
pub use int::*;
4141
pub use us::*;
4242
pub use is::*;
43-
pub use err::ConstMathErr;
43+
pub use err::{ConstMathErr, Op};

trunk/src/librustc_driver/driver.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -528,19 +528,13 @@ pub fn phase_2_configure_and_expand(sess: &Session,
528528
middle::recursion_limit::update_recursion_limit(sess, &krate);
529529
});
530530

531-
time(time_passes, "gated macro checking", || {
532-
sess.track_errors(|| {
533-
let features =
534-
syntax::feature_gate::check_crate_macros(sess.codemap(),
535-
&sess.parse_sess.span_diagnostic,
536-
&krate);
537-
538-
// these need to be set "early" so that expansion sees `quote` if enabled.
539-
*sess.features.borrow_mut() = features;
540-
})
531+
// these need to be set "early" so that expansion sees `quote` if enabled.
532+
sess.track_errors(|| {
533+
*sess.features.borrow_mut() =
534+
syntax::feature_gate::get_features(&sess.parse_sess.span_diagnostic,
535+
&krate);
541536
})?;
542537

543-
544538
krate = time(time_passes, "crate injection", || {
545539
syntax::std_inject::maybe_inject_crates_ref(krate, sess.opts.alt_std_name.clone())
546540
});

trunk/src/librustc_mir/build/block.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
4444
StmtKind::Expr { scope, expr } => {
4545
unpack!(block = this.in_scope(scope, block, |this, _| {
4646
let expr = this.hir.mirror(expr);
47-
let expr_span = expr.span;
48-
let temp = this.temp(expr.ty.clone());
49-
unpack!(block = this.into(&temp, block, expr));
50-
unpack!(block = this.build_drop(block, expr_span, temp));
51-
block.unit()
47+
this.stmt_expr(block, expr)
5248
}));
5349
}
5450
StmtKind::Let { remainder_scope, init_scope, pattern, initializer } => {

trunk/src/librustc_mir/build/expr/as_rvalue.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ impl<'a,'tcx> Builder<'a,'tcx> {
189189
block.and(Rvalue::Aggregate(AggregateKind::Adt(adt_def, variant_index, substs),
190190
fields))
191191
}
192+
ExprKind::Assign { .. } |
193+
ExprKind::AssignOp { .. } => {
194+
block = unpack!(this.stmt_expr(block, expr));
195+
block.and(this.unit_rvalue())
196+
}
192197
ExprKind::Literal { .. } |
193198
ExprKind::Block { .. } |
194199
ExprKind::Match { .. } |
@@ -201,8 +206,6 @@ impl<'a,'tcx> Builder<'a,'tcx> {
201206
ExprKind::Index { .. } |
202207
ExprKind::VarRef { .. } |
203208
ExprKind::SelfRef |
204-
ExprKind::Assign { .. } |
205-
ExprKind::AssignOp { .. } |
206209
ExprKind::Break { .. } |
207210
ExprKind::Continue { .. } |
208211
ExprKind::Return { .. } |

trunk/src/librustc_mir/build/expr/into.rs

Lines changed: 9 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@
1212
1313
use build::{BlockAnd, BlockAndExtension, Builder};
1414
use build::expr::category::{Category, RvalueFunc};
15-
use build::scope::LoopScope;
1615
use hair::*;
17-
use rustc::middle::region::CodeExtent;
1816
use rustc::ty;
1917
use rustc::mir::repr::*;
20-
use syntax::codemap::Span;
2118

2219
impl<'a,'tcx> Builder<'a,'tcx> {
2320
/// Compile `expr`, storing the result into `destination`, which
@@ -207,65 +204,6 @@ impl<'a,'tcx> Builder<'a,'tcx> {
207204
}
208205
exit_block.unit()
209206
}
210-
ExprKind::Assign { lhs, rhs } => {
211-
// Note: we evaluate assignments right-to-left. This
212-
// is better for borrowck interaction with overloaded
213-
// operators like x[j] = x[i].
214-
let lhs = this.hir.mirror(lhs);
215-
let lhs_span = lhs.span;
216-
let rhs = unpack!(block = this.as_operand(block, rhs));
217-
let lhs = unpack!(block = this.as_lvalue(block, lhs));
218-
unpack!(block = this.build_drop(block, lhs_span, lhs.clone()));
219-
this.cfg.push_assign(block, scope_id, expr_span, &lhs, Rvalue::Use(rhs));
220-
block.unit()
221-
}
222-
ExprKind::AssignOp { op, lhs, rhs } => {
223-
// FIXME(#28160) there is an interesting semantics
224-
// question raised here -- should we "freeze" the
225-
// value of the lhs here? I'm inclined to think not,
226-
// since it seems closer to the semantics of the
227-
// overloaded version, which takes `&mut self`. This
228-
// only affects weird things like `x += {x += 1; x}`
229-
// -- is that equal to `x + (x + 1)` or `2*(x+1)`?
230-
231-
// As above, RTL.
232-
let rhs = unpack!(block = this.as_operand(block, rhs));
233-
let lhs = unpack!(block = this.as_lvalue(block, lhs));
234-
235-
// we don't have to drop prior contents or anything
236-
// because AssignOp is only legal for Copy types
237-
// (overloaded ops should be desugared into a call).
238-
this.cfg.push_assign(block, scope_id, expr_span, &lhs,
239-
Rvalue::BinaryOp(op,
240-
Operand::Consume(lhs.clone()),
241-
rhs));
242-
243-
block.unit()
244-
}
245-
ExprKind::Continue { label } => {
246-
this.break_or_continue(expr_span, label, block,
247-
|loop_scope| loop_scope.continue_block)
248-
}
249-
ExprKind::Break { label } => {
250-
this.break_or_continue(expr_span, label, block, |loop_scope| {
251-
loop_scope.might_break = true;
252-
loop_scope.break_block
253-
})
254-
}
255-
ExprKind::Return { value } => {
256-
block = match value {
257-
Some(value) => unpack!(this.into(&Lvalue::ReturnPointer, block, value)),
258-
None => {
259-
this.cfg.push_assign_unit(block, scope_id,
260-
expr_span, &Lvalue::ReturnPointer);
261-
block
262-
}
263-
};
264-
let extent = this.extent_of_return_scope();
265-
let return_block = this.return_block();
266-
this.exit_scope(expr_span, extent, block, return_block);
267-
this.cfg.start_new_block().unit()
268-
}
269207
ExprKind::Call { ty, fun, args } => {
270208
let diverges = match ty.sty {
271209
ty::TyFnDef(_, _, ref f) | ty::TyFnPtr(ref f) => {
@@ -294,6 +232,15 @@ impl<'a,'tcx> Builder<'a,'tcx> {
294232
success.unit()
295233
}
296234

235+
// These cases don't actually need a destination
236+
ExprKind::Assign { .. } |
237+
ExprKind::AssignOp { .. } |
238+
ExprKind::Continue { .. } |
239+
ExprKind::Break { .. } |
240+
ExprKind::Return {.. } => {
241+
this.stmt_expr(block, expr)
242+
}
243+
297244
// these are the cases that are more naturally handled by some other mode
298245
ExprKind::Unary { .. } |
299246
ExprKind::Binary { .. } |
@@ -327,20 +274,4 @@ impl<'a,'tcx> Builder<'a,'tcx> {
327274
}
328275
}
329276
}
330-
331-
fn break_or_continue<F>(&mut self,
332-
span: Span,
333-
label: Option<CodeExtent>,
334-
block: BasicBlock,
335-
exit_selector: F)
336-
-> BlockAnd<()>
337-
where F: FnOnce(&mut LoopScope) -> BasicBlock
338-
{
339-
let (exit_block, extent) = {
340-
let loop_scope = self.find_loop_scope(span, label);
341-
(exit_selector(loop_scope), loop_scope.extent)
342-
};
343-
self.exit_scope(span, extent, block, exit_block);
344-
self.cfg.start_new_block().unit()
345-
}
346277
}

trunk/src/librustc_mir/build/expr/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,4 @@ mod as_operand;
7777
mod as_temp;
7878
mod category;
7979
mod into;
80+
mod stmt;

0 commit comments

Comments
 (0)