Skip to content

Commit 00f3c3f

Browse files
author
Jorge Aparicio
committed
librustc: remove unnecessary as_slice() calls
1 parent ae555a9 commit 00f3c3f

File tree

15 files changed

+38
-40
lines changed

15 files changed

+38
-40
lines changed

src/librustc/lint/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ impl NonSnakeCase {
902902
let mut buf = String::new();
903903
if s.is_empty() { continue; }
904904
for ch in s.chars() {
905-
if !buf.is_empty() && buf.as_slice() != "'"
905+
if !buf.is_empty() && buf != "'"
906906
&& ch.is_uppercase()
907907
&& !last_upper {
908908
words.push(buf);

src/librustc/metadata/creader.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ fn visit_item(e: &Env, i: &ast::Item) {
277277

278278
fn register_native_lib(sess: &Session, span: Option<Span>, name: String,
279279
kind: cstore::NativeLibaryKind) {
280-
if name.as_slice().is_empty() {
280+
if name.is_empty() {
281281
match span {
282282
Some(span) => {
283283
sess.span_err(span, "#[link(name = \"\")] given with \
@@ -304,7 +304,7 @@ fn existing_match(e: &Env, name: &str,
304304
hash: Option<&Svh>) -> Option<ast::CrateNum> {
305305
let mut ret = None;
306306
e.sess.cstore.iter_crate_data(|cnum, data| {
307-
if data.name.as_slice() != name { return }
307+
if data.name != name { return }
308308

309309
match hash {
310310
Some(hash) if *hash == data.hash() => { ret = Some(cnum); return }

src/librustc/metadata/cstore.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl CStore {
162162
let mut ordering = Vec::new();
163163
fn visit(cstore: &CStore, cnum: ast::CrateNum,
164164
ordering: &mut Vec<ast::CrateNum>) {
165-
if ordering.as_slice().contains(&cnum) { return }
165+
if ordering.contains(&cnum) { return }
166166
let meta = cstore.get_crate_data(cnum);
167167
for (_, &dep) in meta.cnum_map.iter() {
168168
visit(cstore, dep, ordering);
@@ -173,7 +173,6 @@ impl CStore {
173173
visit(self, num, &mut ordering);
174174
}
175175
ordering.as_mut_slice().reverse();
176-
let ordering = ordering.as_slice();
177176
let mut libs = self.used_crate_sources.borrow()
178177
.iter()
179178
.map(|src| (src.cnum, match prefer {

src/librustc/metadata/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ fn encode_reexported_static_methods(ecx: &EncodeContext,
474474
// encoded metadata for static methods relative to Bar,
475475
// but not yet for Foo.
476476
//
477-
if path_differs || original_name.get() != exp.name.as_slice() {
477+
if path_differs || original_name.get() != exp.name {
478478
if !encode_reexported_static_base_methods(ecx, rbml_w, exp) {
479479
if encode_reexported_static_trait_methods(ecx, rbml_w, exp) {
480480
debug!("(encode reexported static methods) {} [trait]",

src/librustc/metadata/filesearch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ pub fn rust_path() -> Vec<Path> {
214214
let mut env_rust_path: Vec<Path> = match get_rust_path() {
215215
Some(env_path) => {
216216
let env_path_components =
217-
env_path.as_slice().split_str(PATH_ENTRY_SEPARATOR);
217+
env_path.split_str(PATH_ENTRY_SEPARATOR);
218218
env_path_components.map(|s| Path::new(s)).collect()
219219
}
220220
None => Vec::new()

src/librustc/metadata/loader.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ impl<'a> Context<'a> {
545545
fn crate_matches(&mut self, crate_data: &[u8], libpath: &Path) -> bool {
546546
if self.should_match_name {
547547
match decoder::maybe_get_crate_name(crate_data) {
548-
Some(ref name) if self.crate_name == name.as_slice() => {}
548+
Some(ref name) if self.crate_name == *name => {}
549549
_ => { info!("Rejecting via crate name"); return false }
550550
}
551551
}
@@ -560,7 +560,7 @@ impl<'a> Context<'a> {
560560
None => { debug!("triple not present"); return false }
561561
Some(t) => t,
562562
};
563-
if triple.as_slice() != self.triple {
563+
if triple != self.triple {
564564
info!("Rejecting via crate triple: expected {} got {}", self.triple, triple);
565565
self.rejected_via_triple.push(CrateMismatch {
566566
path: libpath.clone(),
@@ -743,7 +743,7 @@ fn get_metadata_section_imp(is_osx: bool, filename: &Path) -> Result<MetadataBlo
743743
let name = String::from_raw_buf_len(name_buf as *const u8,
744744
name_len as uint);
745745
debug!("get_metadata_section: name {}", name);
746-
if read_meta_section_name(is_osx).as_slice() == name.as_slice() {
746+
if read_meta_section_name(is_osx) == name {
747747
let cbuf = llvm::LLVMGetSectionContents(si.llsi);
748748
let csz = llvm::LLVMGetSectionSize(si.llsi) as uint;
749749
let cvbuf: *const u8 = cbuf as *const u8;

src/librustc/middle/borrowck/fragments.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,15 +234,15 @@ pub fn fixup_fragment_sets<'tcx>(this: &MoveData<'tcx>, tcx: &ty::ctxt<'tcx>) {
234234
debug!("fragments 3 assigned: {}", path_lps(assigned.as_slice()));
235235

236236
// Fourth, build the leftover from the moved, assigned, and parents.
237-
for m in moved.as_slice().iter() {
237+
for m in moved.iter() {
238238
let lp = this.path_loan_path(*m);
239239
add_fragment_siblings(this, tcx, &mut unmoved, lp, None);
240240
}
241-
for a in assigned.as_slice().iter() {
241+
for a in assigned.iter() {
242242
let lp = this.path_loan_path(*a);
243243
add_fragment_siblings(this, tcx, &mut unmoved, lp, None);
244244
}
245-
for p in parents.as_slice().iter() {
245+
for p in parents.iter() {
246246
let lp = this.path_loan_path(*p);
247247
add_fragment_siblings(this, tcx, &mut unmoved, lp, None);
248248
}

src/librustc/middle/cfg/graphviz.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ pub struct LabelledCFG<'a, 'ast: 'a> {
3131
fn replace_newline_with_backslash_l(s: String) -> String {
3232
// Replacing newlines with \\l causes each line to be left-aligned,
3333
// improving presentation of (long) pretty-printed expressions.
34-
if s.as_slice().contains("\n") {
34+
if s.contains("\n") {
3535
let mut s = s.replace("\n", "\\l");
3636
// Apparently left-alignment applies to the line that precedes
3737
// \l, not the line that follows; so, add \l at end of string
3838
// if not already present, ensuring last line gets left-aligned
3939
// as well.
4040
let mut last_two: Vec<_> =
41-
s.as_slice().chars().rev().take(2).collect();
41+
s.chars().rev().take(2).collect();
4242
last_two.reverse();
4343
if last_two != ['\\', 'l'] {
4444
s.push_str("\\l");

src/librustc/middle/dead.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ fn has_allow_dead_code_or_lang_attr(attrs: &[ast::Attribute]) -> bool {
321321
for attr in lint::gather_attrs(attrs).into_iter() {
322322
match attr {
323323
Ok((ref name, lint::Allow, _))
324-
if name.get() == dead_code.as_slice() => return true,
324+
if name.get() == dead_code => return true,
325325
_ => (),
326326
}
327327
}

src/librustc/middle/liveness.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
10651065
// the same bindings, and we also consider the first pattern to be
10661066
// the "authoritative" set of ids
10671067
let arm_succ =
1068-
self.define_bindings_in_arm_pats(arm.pats.as_slice().head().map(|p| &**p),
1068+
self.define_bindings_in_arm_pats(arm.pats.head().map(|p| &**p),
10691069
guard_succ);
10701070
self.merge_from_succ(ln, arm_succ, first_merge);
10711071
first_merge = false;
@@ -1431,7 +1431,7 @@ fn check_arm(this: &mut Liveness, arm: &ast::Arm) {
14311431
// only consider the first pattern; any later patterns must have
14321432
// the same bindings, and we also consider the first pattern to be
14331433
// the "authoritative" set of ids
1434-
this.arm_pats_bindings(arm.pats.as_slice().head().map(|p| &**p), |this, ln, var, sp, id| {
1434+
this.arm_pats_bindings(arm.pats.head().map(|p| &**p), |this, ln, var, sp, id| {
14351435
this.warn_about_unused(sp, id, ln, var);
14361436
});
14371437
visit::walk_arm(this, arm);

src/librustc/middle/resolve.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,7 +1668,7 @@ impl<'a> Resolver<'a> {
16681668
let module_path = match view_path.node {
16691669
ViewPathSimple(_, ref full_path, _) => {
16701670
full_path.segments
1671-
.as_slice().init()
1671+
.init()
16721672
.iter().map(|ident| ident.identifier.name)
16731673
.collect()
16741674
}
@@ -1739,7 +1739,7 @@ impl<'a> Resolver<'a> {
17391739
continue;
17401740
}
17411741
};
1742-
let module_path = module_path.as_slice().init();
1742+
let module_path = module_path.init();
17431743
(module_path.to_vec(), name)
17441744
}
17451745
};
@@ -3735,12 +3735,12 @@ impl<'a> Resolver<'a> {
37353735
.codemap()
37363736
.span_to_snippet((*imports)[index].span)
37373737
.unwrap();
3738-
if sn.as_slice().contains("::") {
3738+
if sn.contains("::") {
37393739
self.resolve_error((*imports)[index].span,
37403740
"unresolved import");
37413741
} else {
37423742
let err = format!("unresolved import (maybe you meant `{}::*`?)",
3743-
sn.as_slice().slice(0, sn.len()));
3743+
sn.slice(0, sn.len()));
37443744
self.resolve_error((*imports)[index].span, err.as_slice());
37453745
}
37463746
}
@@ -5748,7 +5748,7 @@ impl<'a> Resolver<'a> {
57485748
});
57495749

57505750
if method_scope && token::get_name(self.self_name).get()
5751-
== wrong_name.as_slice() {
5751+
== wrong_name {
57525752
self.resolve_error(
57535753
expr.span,
57545754
"`self` is not available \

src/librustc/middle/ty.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2907,7 +2907,7 @@ pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents {
29072907
res = res | TC::ReachesFfiUnsafe;
29082908
}
29092909

2910-
match repr_hints.as_slice().get(0) {
2910+
match repr_hints.get(0) {
29112911
Some(h) => if !h.is_ffi_safe() {
29122912
res = res | TC::ReachesFfiUnsafe;
29132913
},
@@ -3566,23 +3566,23 @@ pub fn positional_element_ty<'tcx>(cx: &ctxt<'tcx>,
35663566
variant: Option<ast::DefId>) -> Option<Ty<'tcx>> {
35673567

35683568
match (&ty.sty, variant) {
3569-
(&ty_tup(ref v), None) => v.as_slice().get(i).map(|&t| t),
3569+
(&ty_tup(ref v), None) => v.get(i).map(|&t| t),
35703570

35713571

35723572
(&ty_struct(def_id, ref substs), None) => lookup_struct_fields(cx, def_id)
3573-
.as_slice().get(i)
3573+
.get(i)
35743574
.map(|&t|lookup_item_type(cx, t.id).ty.subst(cx, substs)),
35753575

35763576
(&ty_enum(def_id, ref substs), Some(variant_def_id)) => {
35773577
let variant_info = enum_variant_with_id(cx, def_id, variant_def_id);
3578-
variant_info.args.as_slice().get(i).map(|t|t.subst(cx, substs))
3578+
variant_info.args.get(i).map(|t|t.subst(cx, substs))
35793579
}
35803580

35813581
(&ty_enum(def_id, ref substs), None) => {
35823582
assert!(enum_is_univariant(cx, def_id));
35833583
let enum_variants = enum_variants(cx, def_id);
35843584
let variant_info = &(*enum_variants)[0];
3585-
variant_info.args.as_slice().get(i).map(|t|t.subst(cx, substs))
3585+
variant_info.args.get(i).map(|t|t.subst(cx, substs))
35863586
}
35873587

35883588
_ => None

src/librustc/session/config.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -512,13 +512,13 @@ pub fn build_codegen_options(matches: &getopts::Matches) -> CodegenOptions
512512
{
513513
let mut cg = basic_codegen_options();
514514
for option in matches.opt_strs("C").into_iter() {
515-
let mut iter = option.as_slice().splitn(1, '=');
515+
let mut iter = option.splitn(1, '=');
516516
let key = iter.next().unwrap();
517517
let value = iter.next();
518518
let option_to_lookup = key.replace("-", "_");
519519
let mut found = false;
520520
for &(candidate, setter, opt_type_desc, _) in CG_OPTIONS.iter() {
521-
if option_to_lookup.as_slice() != candidate { continue }
521+
if option_to_lookup != candidate { continue }
522522
if !setter(&mut cg, value) {
523523
match (value, opt_type_desc) {
524524
(Some(..), None) => {
@@ -714,7 +714,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
714714

715715
for &level in [lint::Allow, lint::Warn, lint::Deny, lint::Forbid].iter() {
716716
for lint_name in matches.opt_strs(level.as_str()).into_iter() {
717-
if lint_name.as_slice() == "help" {
717+
if lint_name == "help" {
718718
describe_lints = true;
719719
} else {
720720
lint_opts.push((lint_name.replace("-", "_").into_string(), level));
@@ -727,9 +727,8 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
727727
let debug_map = debugging_opts_map();
728728
for debug_flag in debug_flags.iter() {
729729
let mut this_bit = 0;
730-
for tuple in debug_map.iter() {
731-
let (name, bit) = match *tuple { (ref a, _, b) => (a, b) };
732-
if *name == debug_flag.as_slice() {
730+
for &(name, _, bit) in debug_map.iter() {
731+
if name == *debug_flag {
733732
this_bit = bit;
734733
break;
735734
}
@@ -749,7 +748,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
749748
if !parse_only && !no_trans {
750749
let unparsed_output_types = matches.opt_strs("emit");
751750
for unparsed_output_type in unparsed_output_types.iter() {
752-
for part in unparsed_output_type.as_slice().split(',') {
751+
for part in unparsed_output_type.split(',') {
753752
let output_type = match part.as_slice() {
754753
"asm" => OutputTypeAssembly,
755754
"ir" => OutputTypeLlvmAssembly,
@@ -824,7 +823,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
824823
}).collect();
825824

826825
let libs = matches.opt_strs("l").into_iter().map(|s| {
827-
let mut parts = s.as_slice().rsplitn(1, ':');
826+
let mut parts = s.rsplitn(1, ':');
828827
let kind = parts.next().unwrap();
829828
let (name, kind) = match (parts.next(), kind) {
830829
(None, name) |
@@ -875,7 +874,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
875874

876875
let mut externs = HashMap::new();
877876
for arg in matches.opt_strs("extern").iter() {
878-
let mut parts = arg.as_slice().splitn(1, '=');
877+
let mut parts = arg.splitn(1, '=');
879878
let name = match parts.next() {
880879
Some(s) => s,
881880
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
925924

926925
let mut crate_types: Vec<CrateType> = Vec::new();
927926
for unparsed_crate_type in list_list.iter() {
928-
for part in unparsed_crate_type.as_slice().split(',') {
927+
for part in unparsed_crate_type.split(',') {
929928
let new_part = match part {
930929
"lib" => default_lib_output(),
931930
"rlib" => CrateTypeRlib,

src/librustc/session/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ pub fn build_session_(sopts: config::Options,
257257

258258
let can_print_warnings = sopts.lint_opts
259259
.iter()
260-
.filter(|&&(ref key, _)| key.as_slice() == "warnings")
260+
.filter(|&&(ref key, _)| *key == "warnings")
261261
.map(|&(_, ref level)| *level != lint::Allow)
262262
.last()
263263
.unwrap_or(true);

src/librustc/util/ppaux.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ pub fn parameterized<'tcx>(cx: &ctxt<'tcx>,
538538
pub fn ty_to_short_str<'tcx>(cx: &ctxt<'tcx>, typ: Ty<'tcx>) -> String {
539539
let mut s = typ.repr(cx).to_string();
540540
if s.len() >= 32u {
541-
s = s.as_slice().slice(0u, 32u).to_string();
541+
s = s.slice(0u, 32u).to_string();
542542
}
543543
return s;
544544
}

0 commit comments

Comments
 (0)