]> git.lizzy.rs Git - rust.git/commitdiff
auto merge of #19378 : japaric/rust/no-as-slice, r=alexcrichton
authorbors <bors@rust-lang.org>
Mon, 8 Dec 2014 02:32:31 +0000 (02:32 +0000)
committerbors <bors@rust-lang.org>
Mon, 8 Dec 2014 02:32:31 +0000 (02:32 +0000)
Now that we have an overloaded comparison (`==`) operator, and that `Vec`/`String` deref to `[T]`/`str` on method calls, many `as_slice()`/`as_mut_slice()`/`to_string()` calls have become redundant. This patch removes them. These were the most common patterns:

- `assert_eq(test_output.as_slice(), "ground truth")` -> `assert_eq(test_output, "ground truth")`
- `assert_eq(test_output, "ground truth".to_string())` -> `assert_eq(test_output, "ground truth")`
- `vec.as_mut_slice().sort()` -> `vec.sort()`
- `vec.as_slice().slice(from, to)` -> `vec.slice(from_to)`

---

Note that e.g. `a_string.push_str(b_string.as_slice())` has been left untouched in this PR, since we first need to settle down whether we want to favor the `&*b_string` or the `b_string[]` notation.

This is rebased on top of #19167

cc @alexcrichton @aturon

30 files changed:
1  2 
src/liballoc/arc.rs
src/liballoc/boxed.rs
src/libcollections/btree/set.rs
src/libcollections/str.rs
src/libcollections/tree/set.rs
src/libgetopts/lib.rs
src/librustc/middle/resolve.rs
src/libstd/ascii.rs
src/libstd/collections/hash/map.rs
src/libstd/collections/hash/set.rs
src/libstd/collections/lru_cache.rs
src/libstd/io/buffered.rs
src/libstd/io/comm_adapters.rs
src/libstd/io/fs.rs
src/libstd/io/mem.rs
src/libstd/io/mod.rs
src/libstd/io/net/ip.rs
src/libstd/io/stdio.rs
src/libstd/os.rs
src/libstd/path/mod.rs
src/libstd/path/posix.rs
src/libstd/path/windows.rs
src/libstd/rand/mod.rs
src/libstd/rt/backtrace.rs
src/libstd/sys/unix/fs.rs
src/libstd/task.rs
src/libstd/time/duration.rs
src/libsyntax/parse/lexer/mod.rs
src/libterm/terminfo/parm.rs
src/libtime/lib.rs

Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
index e146e3c76eb2f22cb582d7e694e2ccfa8ca4f287,daf0f7f3818d7f760876a303b27caa5f7219d764..ffcc0eb22f6138fc434ddec2b18e8eb52ee4ba8a
@@@ -1437,13 -1436,13 +1436,13 @@@ mod tests 
          let opts = vec!(optmulti("L", "", "library directory", "LIB"),
                       optmulti("M", "", "something", "MMMM"));
          let matches = &match getopts(args.as_slice(), opts.as_slice()) {
 -          result::Ok(m) => m,
 -          result::Err(_) => panic!()
 +          result::Result::Ok(m) => m,
 +          result::Result::Err(_) => panic!()
          };
          assert!(matches.opts_present(&["L".to_string()]));
-         assert_eq!(matches.opts_str(&["L".to_string()]).unwrap(), "foo".to_string());
+         assert_eq!(matches.opts_str(&["L".to_string()]).unwrap(), "foo");
          assert!(matches.opts_present(&["M".to_string()]));
-         assert_eq!(matches.opts_str(&["M".to_string()]).unwrap(), ".".to_string());
+         assert_eq!(matches.opts_str(&["M".to_string()]).unwrap(), ".");
  
      }
  
          let opts = vec!(optmulti("L", "", "library directory", "LIB"),
                       optflagmulti("v", "verbose", "Verbose"));
          let matches = &match getopts(args.as_slice(), opts.as_slice()) {
 -          result::Ok(m) => m,
 -          result::Err(e) => panic!( "{}", e )
 +          result::Result::Ok(m) => m,
 +          result::Result::Err(e) => panic!( "{}", e )
          };
          assert!(matches.opts_present(&["L".to_string()]));
-         assert_eq!(matches.opts_str(&["L".to_string()]).unwrap(), "verbose".to_string());
+         assert_eq!(matches.opts_str(&["L".to_string()]).unwrap(), "verbose");
          assert!(matches.opts_present(&["v".to_string()]));
          assert_eq!(3, matches.opt_count("v"));
      }
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
index e0857fd27ffdf35a0649cd60dedd87bfdbda3d2e,a9e653e267a804bfd94e4f073262b1429a1b5b0f..d43a7a66c5b58355c08bfdcb97a7573fcf57a639
@@@ -233,15 -233,13 +233,15 @@@ use int
  use iter::{Iterator, IteratorExt};
  use mem::transmute;
  use ops::{BitOr, BitXor, BitAnd, Sub, Not};
 -use option::{Option, Some, None};
 +use option::Option;
 +use option::Option::{Some, None};
  use os;
  use boxed::Box;
 -use result::{Ok, Err, Result};
 +use result::Result;
 +use result::Result::{Ok, Err};
  use sys;
- use slice::{AsSlice, SlicePrelude};
- use str::{Str, StrPrelude};
+ use slice::SlicePrelude;
+ use str::StrPrelude;
  use str;
  use string::String;
  use uint;
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge