From 00f3c3f7a7058ac1b049810cffc2a8fa71ef7daa Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 13:53:34 -0500 Subject: [PATCH] librustc: remove unnecessary `as_slice()` calls --- src/librustc/lint/builtin.rs | 2 +- src/librustc/metadata/creader.rs | 4 ++-- src/librustc/metadata/cstore.rs | 3 +-- src/librustc/metadata/encoder.rs | 2 +- src/librustc/metadata/filesearch.rs | 2 +- src/librustc/metadata/loader.rs | 6 +++--- src/librustc/middle/borrowck/fragments.rs | 6 +++--- src/librustc/middle/cfg/graphviz.rs | 4 ++-- src/librustc/middle/dead.rs | 2 +- src/librustc/middle/liveness.rs | 4 ++-- src/librustc/middle/resolve.rs | 10 +++++----- src/librustc/middle/ty.rs | 10 +++++----- src/librustc/session/config.rs | 19 +++++++++---------- src/librustc/session/mod.rs | 2 +- src/librustc/util/ppaux.rs | 2 +- 15 files changed, 38 insertions(+), 40 deletions(-) diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index b0ac98c94e7..c474820c3c9 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -902,7 +902,7 @@ impl NonSnakeCase { 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); diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs index 5a8d60fbecd..deeab18de7c 100644 --- a/src/librustc/metadata/creader.rs +++ b/src/librustc/metadata/creader.rs @@ -277,7 +277,7 @@ fn visit_item(e: &Env, i: &ast::Item) { fn register_native_lib(sess: &Session, span: Option, 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 { 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 } diff --git a/src/librustc/metadata/cstore.rs b/src/librustc/metadata/cstore.rs index c844c8940fe..07a8888c531 100644 --- a/src/librustc/metadata/cstore.rs +++ b/src/librustc/metadata/cstore.rs @@ -162,7 +162,7 @@ impl CStore { let mut ordering = Vec::new(); fn visit(cstore: &CStore, cnum: ast::CrateNum, ordering: &mut Vec) { - 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 @@ impl CStore { 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 { diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index f7ee9fa6522..3a111a3223b 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -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]", diff --git a/src/librustc/metadata/filesearch.rs b/src/librustc/metadata/filesearch.rs index 89f3343ef12..63fc2af492c 100644 --- a/src/librustc/metadata/filesearch.rs +++ b/src/librustc/metadata/filesearch.rs @@ -214,7 +214,7 @@ pub fn rust_path() -> Vec { let mut env_rust_path: Vec = 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() diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs index bd0446dd67f..14b1eea2eb8 100644 --- a/src/librustc/metadata/loader.rs +++ b/src/librustc/metadata/loader.rs @@ -545,7 +545,7 @@ impl<'a> Context<'a> { 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 @@ impl<'a> Context<'a> { 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(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); } diff --git a/src/librustc/middle/cfg/graphviz.rs b/src/librustc/middle/cfg/graphviz.rs index 92c87aacc7d..e33f44967f1 100644 --- a/src/librustc/middle/cfg/graphviz.rs +++ b/src/librustc/middle/cfg/graphviz.rs @@ -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"); diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index 03fe8782421..d2f43faa003 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -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, _ => (), } } diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 523c9f33309..a6d3c15df8a 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -1065,7 +1065,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { // 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); diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index b958bdce0a7..66acda78246 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -1668,7 +1668,7 @@ impl<'a> Resolver<'a> { 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 @@ impl<'a> Resolver<'a> { continue; } }; - let module_path = module_path.as_slice().init(); + let module_path = module_path.init(); (module_path.to_vec(), name) } }; @@ -3735,12 +3735,12 @@ impl<'a> Resolver<'a> { .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 @@ impl<'a> Resolver<'a> { }); 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 \ diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 994f0c2090a..8a2529701bb 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -2907,7 +2907,7 @@ pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents { 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) -> Option> { 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 diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index cbc9dd9145b..8701248d1f5 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -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) -> Result = 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, diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index 047e5985569..e4d34e09d33 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -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); diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 1283e89c29d..3895a113726 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -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; }