Skip to content

Commit fe1fde2

Browse files
committed
---
yaml --- r: 129013 b: refs/heads/master c: d0104d0 h: refs/heads/master i: 129011: 84a8eaa v: v3
1 parent f54ca68 commit fe1fde2

File tree

22 files changed

+398
-109
lines changed

22 files changed

+398
-109
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: f59cfd9711e34d9152ea58409051985c362fc3ad
2+
refs/heads/master: d0104d04fdf5126bdc3f76eac93906f25a201ad3
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a86d9ad15e339ab343a12513f9c90556f677b9ca
55
refs/heads/try: 961753763fb87ddcbbccaec4ea87648608d19a58

trunk/src/doc/guide.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,8 +1073,8 @@ destructuring `let`.
10731073
## Enums
10741074

10751075
Finally, Rust has a "sum type", an **enum**. Enums are an incredibly useful
1076-
feature of Rust, and are used throughout the standard library. Enums look
1077-
like this:
1076+
feature of Rust, and are used throughout the standard library. This is an enum
1077+
that is provided by the Rust standard library:
10781078

10791079
```{rust}
10801080
enum Ordering {
@@ -1084,9 +1084,8 @@ enum Ordering {
10841084
}
10851085
```
10861086

1087-
This is an enum that is provided by the Rust standard library. An `Ordering`
1088-
can only be _one_ of `Less`, `Equal`, or `Greater` at any given time. Here's
1089-
an example:
1087+
An `Ordering` can only be _one_ of `Less`, `Equal`, or `Greater` at any given
1088+
time. Here's an example:
10901089

10911090
```{rust}
10921091
fn cmp(a: int, b: int) -> Ordering {
@@ -2897,9 +2896,11 @@ pub fn print_hello() {
28972896
}
28982897
```
28992898

2900-
When we include a module like this, we don't need to make the `mod` declaration,
2901-
it's just understood. This helps prevent 'rightward drift': when you end up
2902-
indenting so many times that your code is hard to read.
2899+
When we include a module like this, we don't need to make the `mod` declaration
2900+
in `hello.rs`, because it's already been declared in `lib.rs`. `hello.rs` just
2901+
contains the body of the module which is defined (by the `pub mod hello`) in
2902+
`lib.rs`. This helps prevent 'rightward drift': when you end up indenting so
2903+
many times that your code is hard to read.
29032904

29042905
Finally, make a new directory, `src/goodbye`, and make a new file in it,
29052906
`src/goodbye/mod.rs`:

trunk/src/libarena/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ mod tests {
563563

564564
struct Noncopy {
565565
string: String,
566-
array: Vec<int> ,
566+
array: Vec<int>,
567567
}
568568

569569
#[test]

trunk/src/libcollections/bitv.rs

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2566,7 +2566,9 @@ mod tests {
25662566
let mut r = rng();
25672567
let mut bitv = 0 as uint;
25682568
b.iter(|| {
2569-
bitv |= 1 << ((r.next_u32() as uint) % uint::BITS);
2569+
for _ in range(0u, 100) {
2570+
bitv |= 1 << ((r.next_u32() as uint) % uint::BITS);
2571+
}
25702572
&bitv
25712573
})
25722574
}
@@ -2576,7 +2578,9 @@ mod tests {
25762578
let mut r = rng();
25772579
let mut bitv = Bitv::with_capacity(BENCH_BITS, false);
25782580
b.iter(|| {
2579-
bitv.set((r.next_u32() as uint) % BENCH_BITS, true);
2581+
for _ in range(0u, 100) {
2582+
bitv.set((r.next_u32() as uint) % BENCH_BITS, true);
2583+
}
25802584
&bitv
25812585
})
25822586
}
@@ -2586,7 +2590,9 @@ mod tests {
25862590
let mut r = rng();
25872591
let mut bitv = Bitv::with_capacity(uint::BITS, false);
25882592
b.iter(|| {
2589-
bitv.set((r.next_u32() as uint) % uint::BITS, true);
2593+
for _ in range(0u, 100) {
2594+
bitv.set((r.next_u32() as uint) % uint::BITS, true);
2595+
}
25902596
&bitv
25912597
})
25922598
}
@@ -2596,7 +2602,9 @@ mod tests {
25962602
let mut r = rng();
25972603
let mut bitv = BitvSet::new();
25982604
b.iter(|| {
2599-
bitv.insert((r.next_u32() as uint) % uint::BITS);
2605+
for _ in range(0u, 100) {
2606+
bitv.insert((r.next_u32() as uint) % uint::BITS);
2607+
}
26002608
&bitv
26012609
})
26022610
}
@@ -2606,7 +2614,9 @@ mod tests {
26062614
let mut r = rng();
26072615
let mut bitv = BitvSet::new();
26082616
b.iter(|| {
2609-
bitv.insert((r.next_u32() as uint) % BENCH_BITS);
2617+
for _ in range(0u, 100) {
2618+
bitv.insert((r.next_u32() as uint) % BENCH_BITS);
2619+
}
26102620
&bitv
26112621
})
26122622
}
@@ -2616,29 +2626,33 @@ mod tests {
26162626
let mut b1 = Bitv::with_capacity(BENCH_BITS, false);
26172627
let b2 = Bitv::with_capacity(BENCH_BITS, false);
26182628
b.iter(|| {
2619-
b1.union(&b2);
2629+
b1.union(&b2)
26202630
})
26212631
}
26222632

26232633
#[bench]
2624-
fn bench_btv_small_iter(b: &mut Bencher) {
2634+
fn bench_bitv_small_iter(b: &mut Bencher) {
26252635
let bitv = Bitv::with_capacity(uint::BITS, false);
26262636
b.iter(|| {
2627-
let mut _sum = 0;
2628-
for pres in bitv.iter() {
2629-
_sum += pres as uint;
2637+
let mut sum = 0;
2638+
for _ in range(0u, 10) {
2639+
for pres in bitv.iter() {
2640+
sum += pres as uint;
2641+
}
26302642
}
2643+
sum
26312644
})
26322645
}
26332646

26342647
#[bench]
26352648
fn bench_bitv_big_iter(b: &mut Bencher) {
26362649
let bitv = Bitv::with_capacity(BENCH_BITS, false);
26372650
b.iter(|| {
2638-
let mut _sum = 0;
2651+
let mut sum = 0;
26392652
for pres in bitv.iter() {
2640-
_sum += pres as uint;
2653+
sum += pres as uint;
26412654
}
2655+
sum
26422656
})
26432657
}
26442658

@@ -2647,10 +2661,11 @@ mod tests {
26472661
let bitv = BitvSet::from_bitv(from_fn(BENCH_BITS,
26482662
|idx| {idx % 3 == 0}));
26492663
b.iter(|| {
2650-
let mut _sum = 0;
2664+
let mut sum = 0;
26512665
for idx in bitv.iter() {
2652-
_sum += idx;
2666+
sum += idx;
26532667
}
2668+
sum
26542669
})
26552670
}
26562671
}

trunk/src/libcore/mem.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ use ptr;
1919

2020
pub use intrinsics::transmute;
2121

22+
/// Moves a thing into the void.
23+
///
24+
/// The forget function will take ownership of the provided value but neglect
25+
/// to run any required cleanup or memory management operations on it.
26+
///
27+
/// This function is the unsafe version of the `drop` function because it does
28+
/// not run any destructors.
29+
#[stable]
30+
pub use intrinsics::forget;
31+
2232
/// Returns the size of a type in bytes.
2333
#[inline]
2434
#[stable]
@@ -337,17 +347,6 @@ pub fn replace<T>(dest: &mut T, mut src: T) -> T {
337347
#[stable]
338348
pub fn drop<T>(_x: T) { }
339349

340-
/// Moves a thing into the void.
341-
///
342-
/// The forget function will take ownership of the provided value but neglect
343-
/// to run any required cleanup or memory management operations on it.
344-
///
345-
/// This function is the unsafe version of the `drop` function because it does
346-
/// not run any destructors.
347-
#[inline]
348-
#[stable]
349-
pub unsafe fn forget<T>(thing: T) { intrinsics::forget(thing) }
350-
351350
/// Interprets `src` as `&U`, and then reads `src` without moving the contained
352351
/// value.
353352
///

trunk/src/libgetopts/lib.rs

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,6 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
571571
}
572572
} else {
573573
let mut j = 1;
574-
let mut last_valid_opt_id = None;
575574
names = Vec::new();
576575
while j < curlen {
577576
let range = cur.as_slice().char_range_at(j);
@@ -584,27 +583,24 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
584583
interpreted correctly
585584
*/
586585

587-
match find_opt(opts.as_slice(), opt.clone()) {
588-
Some(id) => last_valid_opt_id = Some(id),
589-
None => {
590-
let arg_follows =
591-
last_valid_opt_id.is_some() &&
592-
match opts[last_valid_opt_id.unwrap()]
593-
.hasarg {
594-
595-
Yes | Maybe => true,
596-
No => false
597-
};
598-
if arg_follows && j < curlen {
599-
i_arg = Some(cur.as_slice()
600-
.slice(j, curlen).to_string());
601-
break;
602-
} else {
603-
last_valid_opt_id = None;
604-
}
605-
}
606-
}
586+
let opt_id = match find_opt(opts.as_slice(), opt.clone()) {
587+
Some(id) => id,
588+
None => return Err(UnrecognizedOption(opt.to_string()))
589+
};
590+
607591
names.push(opt);
592+
593+
let arg_follows = match opts[opt_id].hasarg {
594+
Yes | Maybe => true,
595+
No => false
596+
};
597+
598+
if arg_follows && range.next < curlen {
599+
i_arg = Some(cur.as_slice()
600+
.slice(range.next, curlen).to_string());
601+
break;
602+
}
603+
608604
j = range.next;
609605
}
610606
}
@@ -617,7 +613,7 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
617613
};
618614
match opts[optid].hasarg {
619615
No => {
620-
if !i_arg.is_none() {
616+
if name_pos == names.len() && !i_arg.is_none() {
621617
return Err(UnexpectedArgument(nm.to_string()));
622618
}
623619
vals.get_mut(optid).push(Given);
@@ -1441,6 +1437,21 @@ mod tests {
14411437

14421438
}
14431439

1440+
#[test]
1441+
fn test_nospace_conflict() {
1442+
let args = vec!("-vvLverbose".to_string(), "-v".to_string() );
1443+
let opts = vec!(optmulti("L", "", "library directory", "LIB"),
1444+
optflagmulti("v", "verbose", "Verbose"));
1445+
let matches = &match getopts(args.as_slice(), opts.as_slice()) {
1446+
result::Ok(m) => m,
1447+
result::Err(e) => fail!( "{}", e )
1448+
};
1449+
assert!(matches.opts_present(["L".to_string()]));
1450+
assert_eq!(matches.opts_str(["L".to_string()]).unwrap(), "verbose".to_string());
1451+
assert!(matches.opts_present(["v".to_string()]));
1452+
assert_eq!(3, matches.opt_count("v"));
1453+
}
1454+
14441455
#[test]
14451456
fn test_long_to_short() {
14461457
let mut short = Opt {

trunk/src/librustc/middle/resolve_lifetime.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ impl<'a> LifetimeContext<'a> {
206206

207207
self.check_lifetime_names(&generics.lifetimes);
208208

209-
let referenced_idents = free_lifetimes(&generics.ty_params);
209+
let referenced_idents = free_lifetimes(&generics.ty_params,
210+
&generics.where_clause);
210211
debug!("pushing fn scope id={} due to fn item/method\
211212
referenced_idents={:?}",
212213
n,
@@ -403,7 +404,8 @@ fn search_lifetimes(lifetimes: &Vec<ast::LifetimeDef>,
403404
///////////////////////////////////////////////////////////////////////////
404405

405406
pub fn early_bound_lifetimes<'a>(generics: &'a ast::Generics) -> Vec<ast::LifetimeDef> {
406-
let referenced_idents = free_lifetimes(&generics.ty_params);
407+
let referenced_idents = free_lifetimes(&generics.ty_params,
408+
&generics.where_clause);
407409
if referenced_idents.is_empty() {
408410
return Vec::new();
409411
}
@@ -414,7 +416,9 @@ pub fn early_bound_lifetimes<'a>(generics: &'a ast::Generics) -> Vec<ast::Lifeti
414416
.collect()
415417
}
416418

417-
pub fn free_lifetimes(ty_params: &OwnedSlice<ast::TyParam>) -> Vec<ast::Name> {
419+
pub fn free_lifetimes(ty_params: &OwnedSlice<ast::TyParam>,
420+
where_clause: &ast::WhereClause)
421+
-> Vec<ast::Name> {
418422
/*!
419423
* Gathers up and returns the names of any lifetimes that appear
420424
* free in `ty_params`. Of course, right now, all lifetimes appear
@@ -426,6 +430,9 @@ pub fn free_lifetimes(ty_params: &OwnedSlice<ast::TyParam>) -> Vec<ast::Name> {
426430
for ty_param in ty_params.iter() {
427431
visit::walk_ty_param_bounds(&mut collector, &ty_param.bounds, ());
428432
}
433+
for predicate in where_clause.predicates.iter() {
434+
visit::walk_ty_param_bounds(&mut collector, &predicate.bounds, ());
435+
}
429436
return collector.names;
430437

431438
struct FreeLifetimeCollector {

trunk/src/librustc/middle/trans/base.rs

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,26 +2240,44 @@ pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t)
22402240
ty::ty_bare_fn(ref f) => (f.sig.clone(), f.abi, false),
22412241
ty::ty_unboxed_closure(closure_did, _) => {
22422242
let unboxed_closures = ccx.tcx.unboxed_closures.borrow();
2243-
let function_type = unboxed_closures.get(&closure_did)
2244-
.closure_type
2245-
.clone();
2243+
let ref function_type = unboxed_closures.get(&closure_did)
2244+
.closure_type;
2245+
22462246
(function_type.sig.clone(), RustCall, true)
22472247
}
2248-
_ => fail!("expected closure or function.")
2248+
_ => ccx.sess().bug("expected closure or function.")
22492249
};
22502250

2251+
22512252
// Since index 0 is the return value of the llvm func, we start
22522253
// at either 1 or 2 depending on whether there's an env slot or not
22532254
let mut first_arg_offset = if has_env { 2 } else { 1 };
22542255
let mut attrs = llvm::AttrBuilder::new();
22552256
let ret_ty = fn_sig.output;
22562257

2257-
// These have an odd calling convention, so we skip them for now.
2258-
//
2259-
// FIXME(pcwalton): We don't have to skip them; just untuple the result.
2260-
if abi == RustCall {
2261-
return attrs;
2262-
}
2258+
// These have an odd calling convention, so we need to manually
2259+
// unpack the input ty's
2260+
let input_tys = match ty::get(fn_ty).sty {
2261+
ty::ty_unboxed_closure(_, _) => {
2262+
assert!(abi == RustCall);
2263+
2264+
match ty::get(fn_sig.inputs[0]).sty {
2265+
ty::ty_nil => Vec::new(),
2266+
ty::ty_tup(ref inputs) => inputs.clone(),
2267+
_ => ccx.sess().bug("expected tuple'd inputs")
2268+
}
2269+
},
2270+
ty::ty_bare_fn(_) if abi == RustCall => {
2271+
let inputs = vec![fn_sig.inputs[0]];
2272+
2273+
match ty::get(fn_sig.inputs[1]).sty {
2274+
ty::ty_nil => inputs,
2275+
ty::ty_tup(ref t_in) => inputs.append(t_in.as_slice()),
2276+
_ => ccx.sess().bug("expected tuple'd inputs")
2277+
}
2278+
}
2279+
_ => fn_sig.inputs.clone()
2280+
};
22632281

22642282
// A function pointer is called without the declaration
22652283
// available, so we have to apply any attributes with ABI
@@ -2315,7 +2333,7 @@ pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t)
23152333
}
23162334
}
23172335

2318-
for (idx, &t) in fn_sig.inputs.iter().enumerate().map(|(i, v)| (i + first_arg_offset, v)) {
2336+
for (idx, &t) in input_tys.iter().enumerate().map(|(i, v)| (i + first_arg_offset, v)) {
23192337
match ty::get(t).sty {
23202338
// this needs to be first to prevent fat pointers from falling through
23212339
_ if !type_is_immediate(ccx, t) => {

0 commit comments

Comments
 (0)