]> git.lizzy.rs Git - rust.git/blobdiff - src/libgetopts/lib.rs
rollup merge of #21457: alexcrichton/issue-21436
[rust.git] / src / libgetopts / lib.rs
index 0dd6a430a88defde895609aa0c18b1299c69f514..70f2429282b9adc1f91ffb8768e872f0677ea6be 100644 (file)
@@ -78,7 +78,7 @@
 //! ```
 
 #![crate_name = "getopts"]
-#![experimental = "use the crates.io `getopts` library instead"]
+#![unstable = "use the crates.io `getopts` library instead"]
 #![staged_api]
 #![crate_type = "rlib"]
 #![crate_type = "dylib"]
@@ -87,6 +87,8 @@
        html_root_url = "http://doc.rust-lang.org/nightly/",
        html_playground_url = "http://play.rust-lang.org/")]
 #![feature(slicing_syntax)]
+#![allow(unknown_features)] #![feature(int_uint)]
+#![allow(unstable)]
 #![deny(missing_docs)]
 
 #[cfg(test)] #[macro_use] extern crate log;
@@ -281,7 +283,7 @@ pub fn long_to_short(&self) -> Opt {
 
 impl Matches {
     fn opt_vals(&self, nm: &str) -> Vec<Optval> {
-        match find_opt(self.opts.index(&FullRange), Name::from_str(nm)) {
+        match find_opt(&self.opts[], Name::from_str(nm)) {
             Some(id) => self.vals[id].clone(),
             None => panic!("No option '{}' defined", nm)
         }
@@ -309,7 +311,7 @@ pub fn opt_count(&self, nm: &str) -> uint {
     /// Returns true if any of several options were matched.
     pub fn opts_present(&self, names: &[String]) -> bool {
         for nm in names.iter() {
-            match find_opt(self.opts.as_slice(), Name::from_str(nm.index(&FullRange))) {
+            match find_opt(self.opts.as_slice(), Name::from_str(&nm[])) {
                 Some(id) if !self.vals[id].is_empty() => return true,
                 _ => (),
             };
@@ -320,7 +322,7 @@ pub fn opts_present(&self, names: &[String]) -> bool {
     /// Returns the string argument supplied to one of several matching options or `None`.
     pub fn opts_str(&self, names: &[String]) -> Option<String> {
         for nm in names.iter() {
-            match self.opt_val(nm.index(&FullRange)) {
+            match self.opt_val(&nm[]) {
                 Some(Val(ref s)) => return Some(s.clone()),
                 _ => ()
             }
@@ -542,7 +544,7 @@ pub fn to_err_msg(self) -> String {
     }
 }
 
-impl fmt::String for Fail {
+impl fmt::Display for Fail {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         match *self {
             ArgumentMissing(ref nm) => {
@@ -585,7 +587,7 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
     while i < l {
         let cur = args[i].clone();
         let curlen = cur.len();
-        if !is_arg(cur.index(&FullRange)) {
+        if !is_arg(&cur[]) {
             free.push(cur);
         } else if cur == "--" {
             let mut j = i + 1;
@@ -595,7 +597,7 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
             let mut names;
             let mut i_arg = None;
             if cur.as_bytes()[1] == b'-' {
-                let tail = cur.index(&(2..curlen));
+                let tail = &cur[2..curlen];
                 let tail_eq: Vec<&str> = tail.split('=').collect();
                 if tail_eq.len() <= 1 {
                     names = vec!(Long(tail.to_string()));
@@ -631,7 +633,7 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
                     };
 
                     if arg_follows && range.next < curlen {
-                        i_arg = Some(cur.index(&(range.next..curlen)).to_string());
+                        i_arg = Some((&cur[range.next..curlen]).to_string());
                         break;
                     }
 
@@ -659,7 +661,7 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
                         v.push(Val((i_arg.clone())
                             .unwrap()));
                     } else if name_pos < names.len() || i + 1 == l ||
-                            is_arg(args[i + 1].index(&FullRange)) {
+                            is_arg(&args[i + 1][]) {
                         let v = &mut vals[optid];
                         v.push(Given);
                     } else {
@@ -722,7 +724,7 @@ pub fn usage(brief: &str, opts: &[OptGroup]) -> String {
             0 => {}
             1 => {
                 row.push('-');
-                row.push_str(short_name.index(&FullRange));
+                row.push_str(&short_name[]);
                 row.push(' ');
             }
             _ => panic!("the short name should only be 1 ascii char long"),
@@ -733,7 +735,7 @@ pub fn usage(brief: &str, opts: &[OptGroup]) -> String {
             0 => {}
             _ => {
                 row.push_str("--");
-                row.push_str(long_name.index(&FullRange));
+                row.push_str(&long_name[]);
                 row.push(' ');
             }
         }
@@ -741,10 +743,10 @@ pub fn usage(brief: &str, opts: &[OptGroup]) -> String {
         // arg
         match hasarg {
             No => {}
-            Yes => row.push_str(hint.index(&FullRange)),
+            Yes => row.push_str(&hint[]),
             Maybe => {
                 row.push('[');
-                row.push_str(hint.index(&FullRange));
+                row.push_str(&hint[]);
                 row.push(']');
             }
         }
@@ -757,7 +759,7 @@ pub fn usage(brief: &str, opts: &[OptGroup]) -> String {
                 row.push(' ');
             }
         } else {
-            row.push_str(desc_sep.index(&FullRange));
+            row.push_str(&desc_sep[]);
         }
 
         // Normalize desc to contain words separated by one space character
@@ -769,14 +771,14 @@ pub fn usage(brief: &str, opts: &[OptGroup]) -> String {
 
         // FIXME: #5516 should be graphemes not codepoints
         let mut desc_rows = Vec::new();
-        each_split_within(desc_normalized_whitespace.index(&FullRange), 54, |substr| {
+        each_split_within(&desc_normalized_whitespace[], 54, |substr| {
             desc_rows.push(substr.to_string());
             true
         });
 
         // FIXME: #5516 should be graphemes not codepoints
         // wrapped description
-        row.push_str(desc_rows.connect(desc_sep.index(&FullRange)).index(&FullRange));
+        row.push_str(&desc_rows.connect(&desc_sep[])[]);
 
         row
     });
@@ -795,10 +797,10 @@ fn format_option(opt: &OptGroup) -> String {
     // Use short_name is possible, but fallback to long_name.
     if opt.short_name.len() > 0 {
         line.push('-');
-        line.push_str(opt.short_name.index(&FullRange));
+        line.push_str(&opt.short_name[]);
     } else {
         line.push_str("--");
-        line.push_str(opt.long_name.index(&FullRange));
+        line.push_str(&opt.long_name[]);
     }
 
     if opt.hasarg != No {
@@ -806,7 +808,7 @@ fn format_option(opt: &OptGroup) -> String {
         if opt.hasarg == Maybe {
             line.push('[');
         }
-        line.push_str(opt.hint.index(&FullRange));
+        line.push_str(&opt.hint[]);
         if opt.hasarg == Maybe {
             line.push(']');
         }
@@ -825,10 +827,10 @@ fn format_option(opt: &OptGroup) -> String {
 /// Derive a short one-line usage summary from a set of long options.
 pub fn short_usage(program_name: &str, opts: &[OptGroup]) -> String {
     let mut line = format!("Usage: {} ", program_name);
-    line.push_str(opts.iter()
-                      .map(format_option)
-                      .collect::<Vec<String>>()
-                      .connect(" ").index(&FullRange));
+    line.push_str(&opts.iter()
+                       .map(format_option)
+                       .collect::<Vec<String>>()
+                       .connect(" ")[]);
     line
 }
 
@@ -891,9 +893,9 @@ fn each_split_within<F>(ss: &str, lim: uint, mut it: F) -> bool where
             (B, Cr, UnderLim) => { B }
             (B, Cr, OverLim)  if (i - last_start + 1) > lim
                             => panic!("word starting with {} longer than limit!",
-                                    ss.index(&(last_start..(i + 1)))),
+                                      &ss[last_start..i + 1]),
             (B, Cr, OverLim)  => {
-                *cont = it(ss.index(&(slice_start..last_end)));
+                *cont = it(&ss[slice_start..last_end]);
                 slice_start = last_start;
                 B
             }
@@ -903,7 +905,7 @@ fn each_split_within<F>(ss: &str, lim: uint, mut it: F) -> bool where
             }
             (B, Ws, OverLim)  => {
                 last_end = i;
-                *cont = it(ss.index(&(slice_start..last_end)));
+                *cont = it(&ss[slice_start..last_end]);
                 A
             }
 
@@ -912,14 +914,14 @@ fn each_split_within<F>(ss: &str, lim: uint, mut it: F) -> bool where
                 B
             }
             (C, Cr, OverLim)  => {
-                *cont = it(ss.index(&(slice_start..last_end)));
+                *cont = it(&ss[slice_start..last_end]);
                 slice_start = i;
                 last_start = i;
                 last_end = i;
                 B
             }
             (C, Ws, OverLim)  => {
-                *cont = it(ss.index(&(slice_start..last_end)));
+                *cont = it(&ss[slice_start..last_end]);
                 A
             }
             (C, Ws, UnderLim) => {