Skip to content

Commit 8aa2987

Browse files
committed
---
yaml --- r: 162300 b: refs/heads/auto c: c56e59c h: refs/heads/master v: v3
1 parent 3ec4c21 commit 8aa2987

File tree

8 files changed

+110
-31
lines changed

8 files changed

+110
-31
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1010
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1111
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1212
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
13-
refs/heads/auto: fcd1f53e4351d241b27c8a3af37e37962811a124
13+
refs/heads/auto: c56e59c722ac5de216ec70f0d1834963ae197ddb
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/libcollections/vec.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,9 @@ impl<T> Vec<T> {
218218
}
219219
}
220220

221-
/// Creates a `Vec<T>` directly from the raw constituents.
221+
/// Creates a `Vec<T>` directly from the raw components of another vector.
222222
///
223-
/// This is highly unsafe:
224-
///
225-
/// - if `ptr` is null, then `length` and `capacity` should be 0
226-
/// - `ptr` must point to an allocation of size `capacity`
227-
/// - there must be `length` valid instances of type `T` at the
228-
/// beginning of that allocation
229-
/// - `ptr` must be allocated by the default `Vec` allocator
223+
/// This is highly unsafe, due to the number of invariants that aren't checked.
230224
///
231225
/// # Example
232226
///
@@ -688,11 +682,12 @@ impl<T> Vec<T> {
688682
Some(new_cap) => {
689683
let amort_cap = new_cap.next_power_of_two();
690684
// next_power_of_two will overflow to exactly 0 for really big capacities
691-
if amort_cap == 0 {
692-
self.grow_capacity(new_cap);
685+
let cap = if amort_cap == 0 {
686+
new_cap
693687
} else {
694-
self.grow_capacity(amort_cap);
695-
}
688+
amort_cap
689+
};
690+
self.grow_capacity(cap)
696691
}
697692
}
698693
}

branches/auto/src/libcore/ops.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,3 +864,53 @@ impl<F,A,R> FnOnce<A,R> for F
864864
self.call_mut(args)
865865
}
866866
}
867+
868+
#[cfg(stage0)]
869+
mod fn_impls {
870+
use super::Fn;
871+
872+
impl<Result> Fn<(),Result> for extern "Rust" fn() -> Result {
873+
#[allow(non_snake_case)]
874+
extern "rust-call" fn call(&self, _args: ()) -> Result {
875+
(*self)()
876+
}
877+
}
878+
879+
impl<Result,A0> Fn<(A0,),Result> for extern "Rust" fn(A0) -> Result {
880+
#[allow(non_snake_case)]
881+
extern "rust-call" fn call(&self, args: (A0,)) -> Result {
882+
let (a0,) = args;
883+
(*self)(a0)
884+
}
885+
}
886+
887+
macro_rules! def_fn(
888+
($($args:ident)*) => (
889+
impl<Result$(,$args)*>
890+
Fn<($($args,)*),Result>
891+
for extern "Rust" fn($($args: $args,)*) -> Result {
892+
#[allow(non_snake_case)]
893+
extern "rust-call" fn call(&self, args: ($($args,)*)) -> Result {
894+
let ($($args,)*) = args;
895+
(*self)($($args,)*)
896+
}
897+
}
898+
)
899+
)
900+
901+
def_fn!(A0 A1)
902+
def_fn!(A0 A1 A2)
903+
def_fn!(A0 A1 A2 A3)
904+
def_fn!(A0 A1 A2 A3 A4)
905+
def_fn!(A0 A1 A2 A3 A4 A5)
906+
def_fn!(A0 A1 A2 A3 A4 A5 A6)
907+
def_fn!(A0 A1 A2 A3 A4 A5 A6 A7)
908+
def_fn!(A0 A1 A2 A3 A4 A5 A6 A7 A8)
909+
def_fn!(A0 A1 A2 A3 A4 A5 A6 A7 A8 A9)
910+
def_fn!(A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10)
911+
def_fn!(A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11)
912+
def_fn!(A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12)
913+
def_fn!(A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13)
914+
def_fn!(A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13 A14)
915+
def_fn!(A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13 A14 A15)
916+
}

branches/auto/src/librustc_typeck/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ fn check_bare_fn<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
410410
decl, id, body, &inh);
411411

412412
vtable::select_all_fcx_obligations_or_error(&fcx);
413-
regionck::regionck_fn(&fcx, id, body);
413+
regionck::regionck_fn(&fcx, id, decl, body);
414414
fcx.default_diverging_type_variables_to_nil();
415415
writeback::resolve_type_vars_in_fn(&fcx, decl, body);
416416
}

branches/auto/src/librustc_typeck/check/regionck.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,11 @@ pub fn regionck_item(fcx: &FnCtxt, item: &ast::Item) {
158158
fcx.infcx().resolve_regions_and_report_errors();
159159
}
160160

161-
pub fn regionck_fn(fcx: &FnCtxt, id: ast::NodeId, blk: &ast::Block) {
161+
pub fn regionck_fn(fcx: &FnCtxt, id: ast::NodeId, decl: &ast::FnDecl, blk: &ast::Block) {
162162
let mut rcx = Rcx::new(fcx, blk.id);
163163
if fcx.err_count_since_creation() == 0 {
164164
// regionck assumes typeck succeeded
165-
rcx.visit_fn_body(id, blk);
165+
rcx.visit_fn_body(id, decl, blk);
166166
}
167167

168168
// Region checking a fn can introduce new trait obligations,
@@ -328,6 +328,7 @@ impl<'a, 'tcx> Rcx<'a, 'tcx> {
328328

329329
fn visit_fn_body(&mut self,
330330
id: ast::NodeId,
331+
fn_decl: &ast::FnDecl,
331332
body: &ast::Block)
332333
{
333334
// When we enter a function, we can derive
@@ -343,6 +344,7 @@ impl<'a, 'tcx> Rcx<'a, 'tcx> {
343344

344345
let len = self.region_param_pairs.len();
345346
self.relate_free_regions(fn_sig.as_slice(), body.id);
347+
link_fn_args(self, CodeExtent::from_node_id(body.id), fn_decl.inputs.as_slice());
346348
self.visit_block(body);
347349
self.visit_region_obligations(body.id);
348350
self.region_param_pairs.truncate(len);
@@ -480,9 +482,9 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Rcx<'a, 'tcx> {
480482
// hierarchy, and in particular the relationships between free
481483
// regions, until regionck, as described in #3238.
482484

483-
fn visit_fn(&mut self, _fk: visit::FnKind<'v>, _fd: &'v ast::FnDecl,
485+
fn visit_fn(&mut self, _fk: visit::FnKind<'v>, fd: &'v ast::FnDecl,
484486
b: &'v ast::Block, _s: Span, id: ast::NodeId) {
485-
self.visit_fn_body(id, b)
487+
self.visit_fn_body(id, fd, b)
486488
}
487489

488490
fn visit_item(&mut self, i: &ast::Item) { visit_item(self, i); }
@@ -1288,7 +1290,6 @@ fn link_local(rcx: &Rcx, local: &ast::Local) {
12881290
/// then ensures that the lifetime of the resulting pointer is
12891291
/// linked to the lifetime of its guarantor (if any).
12901292
fn link_match(rcx: &Rcx, discr: &ast::Expr, arms: &[ast::Arm]) {
1291-
12921293
debug!("regionck::for_match()");
12931294
let mc = mc::MemCategorizationContext::new(rcx);
12941295
let discr_cmt = ignore_err!(mc.cat_expr(discr));
@@ -1300,12 +1301,32 @@ fn link_match(rcx: &Rcx, discr: &ast::Expr, arms: &[ast::Arm]) {
13001301
}
13011302
}
13021303

1304+
/// Computes the guarantors for any ref bindings in a match and
1305+
/// then ensures that the lifetime of the resulting pointer is
1306+
/// linked to the lifetime of its guarantor (if any).
1307+
fn link_fn_args(rcx: &Rcx, body_scope: CodeExtent, args: &[ast::Arg]) {
1308+
debug!("regionck::link_fn_args(body_scope={})", body_scope);
1309+
let mc = mc::MemCategorizationContext::new(rcx);
1310+
for arg in args.iter() {
1311+
let arg_ty = rcx.fcx.node_ty(arg.id);
1312+
let re_scope = ty::ReScope(body_scope);
1313+
let arg_cmt = mc.cat_rvalue(arg.id, arg.ty.span, re_scope, arg_ty);
1314+
debug!("arg_ty={} arg_cmt={}",
1315+
arg_ty.repr(rcx.tcx()),
1316+
arg_cmt.repr(rcx.tcx()));
1317+
link_pattern(rcx, mc, arg_cmt, &*arg.pat);
1318+
}
1319+
}
1320+
13031321
/// Link lifetimes of any ref bindings in `root_pat` to the pointers found in the discriminant, if
13041322
/// needed.
13051323
fn link_pattern<'a, 'tcx>(rcx: &Rcx<'a, 'tcx>,
13061324
mc: mc::MemCategorizationContext<Rcx<'a, 'tcx>>,
13071325
discr_cmt: mc::cmt<'tcx>,
13081326
root_pat: &ast::Pat) {
1327+
debug!("link_pattern(discr_cmt={}, root_pat={})",
1328+
discr_cmt.repr(rcx.tcx()),
1329+
root_pat.repr(rcx.tcx()));
13091330
let _ = mc.cat_pattern(discr_cmt, root_pat, |mc, sub_cmt, sub_pat| {
13101331
match sub_pat.node {
13111332
// `ref x` pattern

branches/auto/src/libsyntax/parse/lexer/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ impl<'a> StringReader<'a> {
763763
}
764764
}
765765

766-
// SNAP 361baab
766+
// SNAP c9f6d69
767767
#[allow(unused)]
768768
fn old_escape_warning(&mut self, sp: Span) {
769769
self.span_diagnostic
@@ -796,15 +796,15 @@ impl<'a> StringReader<'a> {
796796
self.scan_unicode_escape(delim)
797797
} else {
798798
let res = self.scan_hex_digits(4u, delim, false);
799-
// SNAP 361baab
799+
// SNAP c9f6d69
800800
//let sp = codemap::mk_sp(escaped_pos, self.last_pos);
801801
//self.old_escape_warning(sp);
802802
res
803803
}
804804
}
805805
'U' if !ascii_only => {
806806
let res = self.scan_hex_digits(8u, delim, false);
807-
// SNAP 361baab
807+
// SNAP c9f6d69
808808
//let sp = codemap::mk_sp(escaped_pos, self.last_pos);
809809
//self.old_escape_warning(sp);
810810
res

branches/auto/src/snapshots.txt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
S 2014-12-05 361baab
2-
freebsd-x86_64 73cbae4168538a07facd81cca45ed672badb7c3a
3-
linux-i386 211cf0fbdbc7045b765e7b92d92049bbe6788513
4-
linux-x86_64 f001cec306fc1ac77504884acf5dac2e7b39e164
5-
macos-i386 751dc02fac96114361c56eb45ce52e7a58d555e0
6-
macos-x86_64 58cad0275d7b33412501d7dd3386b924d2304e83
7-
winnt-i386 872c56b88cebd7d590fd00bcbd264f0003b4427b
8-
winnt-x86_64 2187d8b3187c03f95cd4e56a582f55ec0cfa8df9
9-
101
S 2014-11-21 c9f6d69
112
freebsd-x86_64 0ef316e7c369177de043e69e964418bd637cbfc0
123
linux-i386 c8342e762a1720be939ed7c6a39bdaa27892f66f
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test that region inference correctly links up the regions when a
12+
// `ref` borrow occurs inside a fn argument.
13+
14+
#![allow(dead_code)]
15+
16+
fn with<'a>(_: |&'a Vec<int>| -> &'a Vec<int>) { }
17+
18+
fn foo() {
19+
with(|&ref ints| ints);
20+
}
21+
22+
fn main() { }

0 commit comments

Comments
 (0)