Skip to content

Commit 9acf8c6

Browse files
committed
---
yaml --- r: 129462 b: refs/heads/snap-stage3 c: 47b9a6f h: refs/heads/master v: v3
1 parent 4262fd0 commit 9acf8c6

File tree

3 files changed

+44
-34
lines changed

3 files changed

+44
-34
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 566b470e138e929e8a93d613372db1ba177c494f
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 24a213726940836e5d57b51fdc0dcd4b1bffeba9
4+
refs/heads/snap-stage3: 47b9a6fb419a7b96b1622d2f411b90d301dc203a
55
refs/heads/try: 80b45ddbd351f0a4a939c3a3c4e20b4defec4b35
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/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
///

branches/snap-stage3/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 {

0 commit comments

Comments
 (0)