]> git.lizzy.rs Git - rust.git/commitdiff
librustc: remove unnecessary `as_slice()` calls
authorJorge Aparicio <japaricious@gmail.com>
Thu, 27 Nov 2014 18:53:34 +0000 (13:53 -0500)
committerJorge Aparicio <japaricious@gmail.com>
Sun, 7 Dec 2014 00:05:58 +0000 (19:05 -0500)
15 files changed:
src/librustc/lint/builtin.rs
src/librustc/metadata/creader.rs
src/librustc/metadata/cstore.rs
src/librustc/metadata/encoder.rs
src/librustc/metadata/filesearch.rs
src/librustc/metadata/loader.rs
src/librustc/middle/borrowck/fragments.rs
src/librustc/middle/cfg/graphviz.rs
src/librustc/middle/dead.rs
src/librustc/middle/liveness.rs
src/librustc/middle/resolve.rs
src/librustc/middle/ty.rs
src/librustc/session/config.rs
src/librustc/session/mod.rs
src/librustc/util/ppaux.rs

index b0ac98c94e748b3f0404369fb027251f461237b6..c474820c3c934e5cd9f054642b854fb39628379e 100644 (file)
@@ -902,7 +902,7 @@ fn to_snake_case(str: &str) -> String {
                 let mut buf = String::new();
                 if s.is_empty() { continue; }
                 for ch in s.chars() {
-                    if !buf.is_empty() && buf.as_slice() != "'"
+                    if !buf.is_empty() && buf != "'"
                                        && ch.is_uppercase()
                                        && !last_upper {
                         words.push(buf);
index 5a8d60fbecd6c3c71ac369bdeec91e6e74454a15..deeab18de7c139cb51ce59acc5bd8513269eb248 100644 (file)
@@ -277,7 +277,7 @@ fn visit_item(e: &Env, i: &ast::Item) {
 
 fn register_native_lib(sess: &Session, span: Option<Span>, name: String,
                        kind: cstore::NativeLibaryKind) {
-    if name.as_slice().is_empty() {
+    if name.is_empty() {
         match span {
             Some(span) => {
                 sess.span_err(span, "#[link(name = \"\")] given with \
@@ -304,7 +304,7 @@ fn existing_match(e: &Env, name: &str,
                   hash: Option<&Svh>) -> Option<ast::CrateNum> {
     let mut ret = None;
     e.sess.cstore.iter_crate_data(|cnum, data| {
-        if data.name.as_slice() != name { return }
+        if data.name != name { return }
 
         match hash {
             Some(hash) if *hash == data.hash() => { ret = Some(cnum); return }
index c844c8940fe6247ec17d83a8c349657206a002fa..07a8888c531cfd7f3228c1d5d793d5887982766a 100644 (file)
@@ -162,7 +162,7 @@ pub fn get_used_crates(&self, prefer: LinkagePreference)
         let mut ordering = Vec::new();
         fn visit(cstore: &CStore, cnum: ast::CrateNum,
                  ordering: &mut Vec<ast::CrateNum>) {
-            if ordering.as_slice().contains(&cnum) { return }
+            if ordering.contains(&cnum) { return }
             let meta = cstore.get_crate_data(cnum);
             for (_, &dep) in meta.cnum_map.iter() {
                 visit(cstore, dep, ordering);
@@ -173,7 +173,6 @@ fn visit(cstore: &CStore, cnum: ast::CrateNum,
             visit(self, num, &mut ordering);
         }
         ordering.as_mut_slice().reverse();
-        let ordering = ordering.as_slice();
         let mut libs = self.used_crate_sources.borrow()
             .iter()
             .map(|src| (src.cnum, match prefer {
index f7ee9fa65229ce0d0aa4cae02c757185000c926e..3a111a3223b686446f320d771bada7f6b7f2cd87 100644 (file)
@@ -474,7 +474,7 @@ fn encode_reexported_static_methods(ecx: &EncodeContext,
         // encoded metadata for static methods relative to Bar,
         // but not yet for Foo.
         //
-        if path_differs || original_name.get() != exp.name.as_slice() {
+        if path_differs || original_name.get() != exp.name {
             if !encode_reexported_static_base_methods(ecx, rbml_w, exp) {
                 if encode_reexported_static_trait_methods(ecx, rbml_w, exp) {
                     debug!("(encode reexported static methods) {} [trait]",
index 89f3343ef123ac7bf5150057b91e8c7d4617dc2a..63fc2af492cb0de4ea94f694113c91d797495aa9 100644 (file)
@@ -214,7 +214,7 @@ pub fn rust_path() -> Vec<Path> {
     let mut env_rust_path: Vec<Path> = match get_rust_path() {
         Some(env_path) => {
             let env_path_components =
-                env_path.as_slice().split_str(PATH_ENTRY_SEPARATOR);
+                env_path.split_str(PATH_ENTRY_SEPARATOR);
             env_path_components.map(|s| Path::new(s)).collect()
         }
         None => Vec::new()
index bd0446dd67ff291fef3c16bfc4ebb0a335b48852..14b1eea2eb819714e88ce5d43cc45b55f48947f1 100644 (file)
@@ -545,7 +545,7 @@ fn extract_one(&mut self, m: HashSet<Path>, flavor: &str,
     fn crate_matches(&mut self, crate_data: &[u8], libpath: &Path) -> bool {
         if self.should_match_name {
             match decoder::maybe_get_crate_name(crate_data) {
-                Some(ref name) if self.crate_name == name.as_slice() => {}
+                Some(ref name) if self.crate_name == *name => {}
                 _ => { info!("Rejecting via crate name"); return false }
             }
         }
@@ -560,7 +560,7 @@ fn crate_matches(&mut self, crate_data: &[u8], libpath: &Path) -> bool {
             None => { debug!("triple not present"); return false }
             Some(t) => t,
         };
-        if triple.as_slice() != self.triple {
+        if triple != self.triple {
             info!("Rejecting via crate triple: expected {} got {}", self.triple, triple);
             self.rejected_via_triple.push(CrateMismatch {
                 path: libpath.clone(),
@@ -743,7 +743,7 @@ fn get_metadata_section_imp(is_osx: bool, filename: &Path) -> Result<MetadataBlo
             let name = String::from_raw_buf_len(name_buf as *const u8,
                                                 name_len as uint);
             debug!("get_metadata_section: name {}", name);
-            if read_meta_section_name(is_osx).as_slice() == name.as_slice() {
+            if read_meta_section_name(is_osx) == name {
                 let cbuf = llvm::LLVMGetSectionContents(si.llsi);
                 let csz = llvm::LLVMGetSectionSize(si.llsi) as uint;
                 let cvbuf: *const u8 = cbuf as *const u8;
index 24273e49c73131579bbdfc62b4225c779ff548e0..5785972c484bbb5a55eedac6b0813db17f6688e3 100644 (file)
@@ -234,15 +234,15 @@ pub fn fixup_fragment_sets<'tcx>(this: &MoveData<'tcx>, tcx: &ty::ctxt<'tcx>) {
     debug!("fragments 3 assigned: {}", path_lps(assigned.as_slice()));
 
     // Fourth, build the leftover from the moved, assigned, and parents.
-    for m in moved.as_slice().iter() {
+    for m in moved.iter() {
         let lp = this.path_loan_path(*m);
         add_fragment_siblings(this, tcx, &mut unmoved, lp, None);
     }
-    for a in assigned.as_slice().iter() {
+    for a in assigned.iter() {
         let lp = this.path_loan_path(*a);
         add_fragment_siblings(this, tcx, &mut unmoved, lp, None);
     }
-    for p in parents.as_slice().iter() {
+    for p in parents.iter() {
         let lp = this.path_loan_path(*p);
         add_fragment_siblings(this, tcx, &mut unmoved, lp, None);
     }
index 92c87aacc7dc5bf75e276fdb9a1b6be4d2f455a1..e33f44967f1ad4661aae2dcc24ad8981baa11344 100644 (file)
@@ -31,14 +31,14 @@ pub struct LabelledCFG<'a, 'ast: 'a> {
 fn replace_newline_with_backslash_l(s: String) -> String {
     // Replacing newlines with \\l causes each line to be left-aligned,
     // improving presentation of (long) pretty-printed expressions.
-    if s.as_slice().contains("\n") {
+    if s.contains("\n") {
         let mut s = s.replace("\n", "\\l");
         // Apparently left-alignment applies to the line that precedes
         // \l, not the line that follows; so, add \l at end of string
         // if not already present, ensuring last line gets left-aligned
         // as well.
         let mut last_two: Vec<_> =
-            s.as_slice().chars().rev().take(2).collect();
+            s.chars().rev().take(2).collect();
         last_two.reverse();
         if last_two != ['\\', 'l'] {
             s.push_str("\\l");
index 03fe87824215925b36e09b4f8338a41f4bc56377..d2f43faa003559c8d5fe32b971db959289a7c4e0 100644 (file)
@@ -321,7 +321,7 @@ fn has_allow_dead_code_or_lang_attr(attrs: &[ast::Attribute]) -> bool {
     for attr in lint::gather_attrs(attrs).into_iter() {
         match attr {
             Ok((ref name, lint::Allow, _))
-                if name.get() == dead_code.as_slice() => return true,
+                if name.get() == dead_code => return true,
             _ => (),
         }
     }
index 523c9f3330968cd875f01ebd58e378e8e4c682c2..a6d3c15df8a7488ff7d37c1b0537b0bafc41846f 100644 (file)
@@ -1065,7 +1065,7 @@ fn propagate_through_expr(&mut self, expr: &Expr, succ: LiveNode)
                 // the same bindings, and we also consider the first pattern to be
                 // the "authoritative" set of ids
                 let arm_succ =
-                    self.define_bindings_in_arm_pats(arm.pats.as_slice().head().map(|p| &**p),
+                    self.define_bindings_in_arm_pats(arm.pats.head().map(|p| &**p),
                                                      guard_succ);
                 self.merge_from_succ(ln, arm_succ, first_merge);
                 first_merge = false;
@@ -1431,7 +1431,7 @@ fn check_arm(this: &mut Liveness, arm: &ast::Arm) {
     // only consider the first pattern; any later patterns must have
     // the same bindings, and we also consider the first pattern to be
     // the "authoritative" set of ids
-    this.arm_pats_bindings(arm.pats.as_slice().head().map(|p| &**p), |this, ln, var, sp, id| {
+    this.arm_pats_bindings(arm.pats.head().map(|p| &**p), |this, ln, var, sp, id| {
         this.warn_about_unused(sp, id, ln, var);
     });
     visit::walk_arm(this, arm);
index b958bdce0a7e87b1ebad6369f4e29e84452d4ee6..66acda782460711394ae84edcdbecfd65896178c 100644 (file)
@@ -1668,7 +1668,7 @@ fn build_reduced_graph_for_view_item(&mut self, view_item: &ViewItem,
                 let module_path = match view_path.node {
                     ViewPathSimple(_, ref full_path, _) => {
                         full_path.segments
-                            .as_slice().init()
+                            .init()
                             .iter().map(|ident| ident.identifier.name)
                             .collect()
                     }
@@ -1739,7 +1739,7 @@ fn build_reduced_graph_for_view_item(&mut self, view_item: &ViewItem,
                                             continue;
                                         }
                                     };
-                                    let module_path = module_path.as_slice().init();
+                                    let module_path = module_path.init();
                                     (module_path.to_vec(), name)
                                 }
                             };
@@ -3735,12 +3735,12 @@ fn report_unresolved_imports(&mut self, module_: Rc<Module>) {
                          .codemap()
                          .span_to_snippet((*imports)[index].span)
                          .unwrap();
-            if sn.as_slice().contains("::") {
+            if sn.contains("::") {
                 self.resolve_error((*imports)[index].span,
                                    "unresolved import");
             } else {
                 let err = format!("unresolved import (maybe you meant `{}::*`?)",
-                                  sn.as_slice().slice(0, sn.len()));
+                                  sn.slice(0, sn.len()));
                 self.resolve_error((*imports)[index].span, err.as_slice());
             }
         }
@@ -5748,7 +5748,7 @@ fn resolve_expr(&mut self, expr: &Expr) {
                                 });
 
                                 if method_scope && token::get_name(self.self_name).get()
-                                                                   == wrong_name.as_slice() {
+                                                                   == wrong_name {
                                         self.resolve_error(
                                             expr.span,
                                             "`self` is not available \
index 994f0c2090a57245964898f223f1d740c4df1b78..8a2529701bbb38433001719f2253c6ab48ddfd3f 100644 (file)
@@ -2907,7 +2907,7 @@ fn tc_ty<'tcx>(cx: &ctxt<'tcx>,
                         res = res | TC::ReachesFfiUnsafe;
                     }
 
-                    match repr_hints.as_slice().get(0) {
+                    match repr_hints.get(0) {
                         Some(h) => if !h.is_ffi_safe() {
                             res = res | TC::ReachesFfiUnsafe;
                         },
@@ -3566,23 +3566,23 @@ pub fn positional_element_ty<'tcx>(cx: &ctxt<'tcx>,
                                    variant: Option<ast::DefId>) -> Option<Ty<'tcx>> {
 
     match (&ty.sty, variant) {
-        (&ty_tup(ref v), None) => v.as_slice().get(i).map(|&t| t),
+        (&ty_tup(ref v), None) => v.get(i).map(|&t| t),
 
 
         (&ty_struct(def_id, ref substs), None) => lookup_struct_fields(cx, def_id)
-            .as_slice().get(i)
+            .get(i)
             .map(|&t|lookup_item_type(cx, t.id).ty.subst(cx, substs)),
 
         (&ty_enum(def_id, ref substs), Some(variant_def_id)) => {
             let variant_info = enum_variant_with_id(cx, def_id, variant_def_id);
-            variant_info.args.as_slice().get(i).map(|t|t.subst(cx, substs))
+            variant_info.args.get(i).map(|t|t.subst(cx, substs))
         }
 
         (&ty_enum(def_id, ref substs), None) => {
             assert!(enum_is_univariant(cx, def_id));
             let enum_variants = enum_variants(cx, def_id);
             let variant_info = &(*enum_variants)[0];
-            variant_info.args.as_slice().get(i).map(|t|t.subst(cx, substs))
+            variant_info.args.get(i).map(|t|t.subst(cx, substs))
         }
 
         _ => None
index cbc9dd9145bfb7fd4382d676ce37f4e30b10bd51..8701248d1f58eec0e2ec38cf6b4d62dd9856be1d 100644 (file)
@@ -512,13 +512,13 @@ pub fn build_codegen_options(matches: &getopts::Matches) -> CodegenOptions
 {
     let mut cg = basic_codegen_options();
     for option in matches.opt_strs("C").into_iter() {
-        let mut iter = option.as_slice().splitn(1, '=');
+        let mut iter = option.splitn(1, '=');
         let key = iter.next().unwrap();
         let value = iter.next();
         let option_to_lookup = key.replace("-", "_");
         let mut found = false;
         for &(candidate, setter, opt_type_desc, _) in CG_OPTIONS.iter() {
-            if option_to_lookup.as_slice() != candidate { continue }
+            if option_to_lookup != candidate { continue }
             if !setter(&mut cg, value) {
                 match (value, opt_type_desc) {
                     (Some(..), None) => {
@@ -714,7 +714,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
 
     for &level in [lint::Allow, lint::Warn, lint::Deny, lint::Forbid].iter() {
         for lint_name in matches.opt_strs(level.as_str()).into_iter() {
-            if lint_name.as_slice() == "help" {
+            if lint_name == "help" {
                 describe_lints = true;
             } else {
                 lint_opts.push((lint_name.replace("-", "_").into_string(), level));
@@ -727,9 +727,8 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
     let debug_map = debugging_opts_map();
     for debug_flag in debug_flags.iter() {
         let mut this_bit = 0;
-        for tuple in debug_map.iter() {
-            let (name, bit) = match *tuple { (ref a, _, b) => (a, b) };
-            if *name == debug_flag.as_slice() {
+        for &(name, _, bit) in debug_map.iter() {
+            if name == *debug_flag {
                 this_bit = bit;
                 break;
             }
@@ -749,7 +748,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
     if !parse_only && !no_trans {
         let unparsed_output_types = matches.opt_strs("emit");
         for unparsed_output_type in unparsed_output_types.iter() {
-            for part in unparsed_output_type.as_slice().split(',') {
+            for part in unparsed_output_type.split(',') {
                 let output_type = match part.as_slice() {
                     "asm"  => OutputTypeAssembly,
                     "ir"   => OutputTypeLlvmAssembly,
@@ -824,7 +823,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
     }).collect();
 
     let libs = matches.opt_strs("l").into_iter().map(|s| {
-        let mut parts = s.as_slice().rsplitn(1, ':');
+        let mut parts = s.rsplitn(1, ':');
         let kind = parts.next().unwrap();
         let (name, kind) = match (parts.next(), kind) {
             (None, name) |
@@ -875,7 +874,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
 
     let mut externs = HashMap::new();
     for arg in matches.opt_strs("extern").iter() {
-        let mut parts = arg.as_slice().splitn(1, '=');
+        let mut parts = arg.splitn(1, '=');
         let name = match parts.next() {
             Some(s) => s,
             None => early_error("--extern value must not be empty"),
@@ -925,7 +924,7 @@ pub fn parse_crate_types_from_list(list_list: Vec<String>) -> Result<Vec<CrateTy
 
     let mut crate_types: Vec<CrateType> = Vec::new();
     for unparsed_crate_type in list_list.iter() {
-        for part in unparsed_crate_type.as_slice().split(',') {
+        for part in unparsed_crate_type.split(',') {
             let new_part = match part {
                 "lib"       => default_lib_output(),
                 "rlib"      => CrateTypeRlib,
index 047e5985569ae41f0f2f4cb0f56194151da5112c..e4d34e09d330a5cc64bc00e8c6ad4576fdbdcc63 100644 (file)
@@ -257,7 +257,7 @@ pub fn build_session_(sopts: config::Options,
 
     let can_print_warnings = sopts.lint_opts
         .iter()
-        .filter(|&&(ref key, _)| key.as_slice() == "warnings")
+        .filter(|&&(ref key, _)| *key == "warnings")
         .map(|&(_, ref level)| *level != lint::Allow)
         .last()
         .unwrap_or(true);
index 1283e89c29d0cdf79b02e1724ff50d2426330deb..3895a1137267433b93468922e8aa041c5d2ee43d 100644 (file)
@@ -538,7 +538,7 @@ pub fn parameterized<'tcx>(cx: &ctxt<'tcx>,
 pub fn ty_to_short_str<'tcx>(cx: &ctxt<'tcx>, typ: Ty<'tcx>) -> String {
     let mut s = typ.repr(cx).to_string();
     if s.len() >= 32u {
-        s = s.as_slice().slice(0u, 32u).to_string();
+        s = s.slice(0u, 32u).to_string();
     }
     return s;
 }