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);

0 commit comments

Comments
 (0)