Skip to content

Commit e6bd217

Browse files
author
Jorge Aparicio
committed
librustdoc: remove unnecessary as_slice() calls
1 parent 8bb5ef9 commit e6bd217

File tree

7 files changed

+39
-39
lines changed

7 files changed

+39
-39
lines changed

src/librustdoc/clean/inline.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,10 @@ fn build_impl(cx: &DocContext, tcx: &ty::ctxt,
341341

342342
fn is_doc_hidden(a: &clean::Attribute) -> bool {
343343
match *a {
344-
clean::List(ref name, ref inner) if name.as_slice() == "doc" => {
344+
clean::List(ref name, ref inner) if *name == "doc" => {
345345
inner.iter().any(|a| {
346346
match *a {
347-
clean::Word(ref s) => s.as_slice() == "hidden",
347+
clean::Word(ref s) => *s == "hidden",
348348
_ => false,
349349
}
350350
})

src/librustdoc/clean/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ impl Item {
256256
pub fn doc_list<'a>(&'a self) -> Option<&'a [Attribute]> {
257257
for attr in self.attrs.iter() {
258258
match *attr {
259-
List(ref x, ref list) if "doc" == x.as_slice() => {
259+
List(ref x, ref list) if "doc" == *x => {
260260
return Some(list.as_slice());
261261
}
262262
_ => {}
@@ -270,7 +270,7 @@ impl Item {
270270
pub fn doc_value<'a>(&'a self) -> Option<&'a str> {
271271
for attr in self.attrs.iter() {
272272
match *attr {
273-
NameValue(ref x, ref v) if "doc" == x.as_slice() => {
273+
NameValue(ref x, ref v) if "doc" == *x => {
274274
return Some(v.as_slice());
275275
}
276276
_ => {}
@@ -284,7 +284,7 @@ impl Item {
284284
Some(ref l) => {
285285
for innerattr in l.iter() {
286286
match *innerattr {
287-
Word(ref s) if "hidden" == s.as_slice() => {
287+
Word(ref s) if "hidden" == *s => {
288288
return true
289289
}
290290
_ => (),
@@ -1217,13 +1217,13 @@ impl PrimitiveType {
12171217
fn find(attrs: &[Attribute]) -> Option<PrimitiveType> {
12181218
for attr in attrs.iter() {
12191219
let list = match *attr {
1220-
List(ref k, ref l) if k.as_slice() == "doc" => l,
1220+
List(ref k, ref l) if *k == "doc" => l,
12211221
_ => continue,
12221222
};
12231223
for sub_attr in list.iter() {
12241224
let value = match *sub_attr {
12251225
NameValue(ref k, ref v)
1226-
if k.as_slice() == "primitive" => v.as_slice(),
1226+
if *k == "primitive" => v.as_slice(),
12271227
_ => continue,
12281228
};
12291229
match PrimitiveType::from_str(value) {

src/librustdoc/html/format.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ fn path(w: &mut fmt::Formatter, path: &clean::Path, print_all: bool,
251251
Some(root) => {
252252
let mut root = String::from_str(root.as_slice());
253253
for seg in path.segments[..amt].iter() {
254-
if "super" == seg.name.as_slice() ||
255-
"self" == seg.name.as_slice() {
254+
if "super" == seg.name ||
255+
"self" == seg.name {
256256
try!(write!(w, "{}::", seg.name));
257257
} else {
258258
root.push_str(seg.name.as_slice());
@@ -337,7 +337,7 @@ fn primitive_link(f: &mut fmt::Formatter,
337337
Some(root) => {
338338
try!(write!(f, "<a href='{}{}/primitive.{}.html'>",
339339
root,
340-
path.ref0().as_slice().head().unwrap(),
340+
path.ref0().head().unwrap(),
341341
prim.to_url_str()));
342342
needs_termination = true;
343343
}

src/librustdoc/html/markdown.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
231231
};
232232

233233
// Transform the contents of the header into a hyphenated string
234-
let id = s.as_slice().words().map(|s| s.to_ascii_lower())
234+
let id = s.words().map(|s| s.to_ascii_lower())
235235
.collect::<Vec<String>>().connect("-");
236236

237237
// This is a terrible hack working around how hoedown gives us rendered
@@ -393,7 +393,7 @@ impl LangString {
393393
let mut seen_other_tags = false;
394394
let mut data = LangString::all_false();
395395

396-
let mut tokens = string.as_slice().split(|c: char|
396+
let mut tokens = string.split(|c: char|
397397
!(c == '_' || c == '-' || c.is_alphanumeric())
398398
);
399399

src/librustdoc/html/render.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -277,15 +277,15 @@ pub fn run(mut krate: clean::Crate,
277277
for attr in attrs.iter() {
278278
match *attr {
279279
clean::NameValue(ref x, ref s)
280-
if "html_favicon_url" == x.as_slice() => {
280+
if "html_favicon_url" == *x => {
281281
cx.layout.favicon = s.to_string();
282282
}
283283
clean::NameValue(ref x, ref s)
284-
if "html_logo_url" == x.as_slice() => {
284+
if "html_logo_url" == *x => {
285285
cx.layout.logo = s.to_string();
286286
}
287287
clean::NameValue(ref x, ref s)
288-
if "html_playground_url" == x.as_slice() => {
288+
if "html_playground_url" == *x => {
289289
cx.layout.playground_url = s.to_string();
290290
markdown::PLAYGROUND_KRATE.with(|slot| {
291291
if slot.borrow().is_none() {
@@ -295,7 +295,7 @@ pub fn run(mut krate: clean::Crate,
295295
});
296296
}
297297
clean::Word(ref x)
298-
if "html_no_source" == x.as_slice() => {
298+
if "html_no_source" == *x => {
299299
cx.include_sources = false;
300300
}
301301
_ => {}
@@ -434,7 +434,7 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> io::IoResult<String>
434434
for (i, item) in cache.search_index.iter().enumerate() {
435435
// Omit the path if it is same to that of the prior item.
436436
let path;
437-
if lastpath.as_slice() == item.path.as_slice() {
437+
if lastpath == item.path {
438438
path = "";
439439
} else {
440440
lastpath = item.path.to_string();
@@ -513,10 +513,10 @@ fn write_shared(cx: &Context,
513513
if path.exists() {
514514
for line in BufferedReader::new(File::open(path)).lines() {
515515
let line = try!(line);
516-
if !line.as_slice().starts_with(key) {
516+
if !line.starts_with(key) {
517517
continue
518518
}
519-
if line.as_slice().starts_with(
519+
if line.starts_with(
520520
format!("{}['{}']", key, krate).as_slice()) {
521521
continue
522522
}
@@ -670,12 +670,12 @@ fn extern_location(e: &clean::ExternalCrate, dst: &Path) -> ExternalLocation {
670670
// external crate
671671
for attr in e.attrs.iter() {
672672
match *attr {
673-
clean::List(ref x, ref list) if "doc" == x.as_slice() => {
673+
clean::List(ref x, ref list) if "doc" == *x => {
674674
for attr in list.iter() {
675675
match *attr {
676676
clean::NameValue(ref x, ref s)
677-
if "html_root_url" == x.as_slice() => {
678-
if s.as_slice().ends_with("/") {
677+
if "html_root_url" == *x => {
678+
if s.ends_with("/") {
679679
return Remote(s.to_string());
680680
}
681681
return Remote(format!("{}/", s));
@@ -964,7 +964,7 @@ impl DocFolder for Cache {
964964
let dox = match attrs.into_iter().find(|a| {
965965
match *a {
966966
clean::NameValue(ref x, _)
967-
if "doc" == x.as_slice() => {
967+
if "doc" == *x => {
968968
true
969969
}
970970
_ => false

src/librustdoc/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ fn acquire_input(input: &str,
299299
fn parse_externs(matches: &getopts::Matches) -> Result<core::Externs, String> {
300300
let mut externs = HashMap::new();
301301
for arg in matches.opt_strs("extern").iter() {
302-
let mut parts = arg.as_slice().splitn(1, '=');
302+
let mut parts = arg.splitn(1, '=');
303303
let name = match parts.next() {
304304
Some(s) => s,
305305
None => {
@@ -363,18 +363,18 @@ fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matche
363363
for inner in nested.iter() {
364364
match *inner {
365365
clean::Word(ref x)
366-
if "no_default_passes" == x.as_slice() => {
366+
if "no_default_passes" == *x => {
367367
default_passes = false;
368368
}
369369
clean::NameValue(ref x, ref value)
370-
if "passes" == x.as_slice() => {
371-
for pass in value.as_slice().words() {
370+
if "passes" == *x => {
371+
for pass in value.words() {
372372
passes.push(pass.to_string());
373373
}
374374
}
375375
clean::NameValue(ref x, ref value)
376-
if "plugins" == x.as_slice() => {
377-
for p in value.as_slice().words() {
376+
if "plugins" == *x => {
377+
for p in value.words() {
378378
plugins.push(p.to_string());
379379
}
380380
}
@@ -397,7 +397,7 @@ fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matche
397397
for pass in passes.iter() {
398398
let plugin = match PASSES.iter()
399399
.position(|&(p, _, _)| {
400-
p == pass.as_slice()
400+
p == *pass
401401
}) {
402402
Some(i) => PASSES[i].val1(),
403403
None => {
@@ -434,7 +434,7 @@ fn json_input(input: &str) -> Result<Output, String> {
434434
// Make sure the schema is what we expect
435435
match obj.remove(&"schema".to_string()) {
436436
Some(Json::String(version)) => {
437-
if version.as_slice() != SCHEMA_VERSION {
437+
if version != SCHEMA_VERSION {
438438
return Err(format!(
439439
"sorry, but I only understand version {}",
440440
SCHEMA_VERSION))

src/librustdoc/passes.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ pub fn unindent_comments(krate: clean::Crate) -> plugins::PluginResult {
258258
for attr in i.attrs.iter() {
259259
match attr {
260260
&clean::NameValue(ref x, ref s)
261-
if "doc" == x.as_slice() => {
261+
if "doc" == *x => {
262262
avec.push(clean::NameValue("doc".to_string(),
263263
unindent(s.as_slice())))
264264
}
@@ -283,15 +283,15 @@ pub fn collapse_docs(krate: clean::Crate) -> plugins::PluginResult {
283283
for attr in i.attrs.iter() {
284284
match *attr {
285285
clean::NameValue(ref x, ref s)
286-
if "doc" == x.as_slice() => {
286+
if "doc" == *x => {
287287
docstr.push_str(s.as_slice());
288288
docstr.push('\n');
289289
},
290290
_ => ()
291291
}
292292
}
293293
let mut a: Vec<clean::Attribute> = i.attrs.iter().filter(|&a| match a {
294-
&clean::NameValue(ref x, _) if "doc" == x.as_slice() => false,
294+
&clean::NameValue(ref x, _) if "doc" == *x => false,
295295
_ => true
296296
}).map(|x| x.clone()).collect();
297297
if docstr.len() > 0 {
@@ -374,14 +374,14 @@ mod unindent_tests {
374374
fn should_unindent() {
375375
let s = " line1\n line2".to_string();
376376
let r = unindent(s.as_slice());
377-
assert_eq!(r.as_slice(), "line1\nline2");
377+
assert_eq!(r, "line1\nline2");
378378
}
379379

380380
#[test]
381381
fn should_unindent_multiple_paragraphs() {
382382
let s = " line1\n\n line2".to_string();
383383
let r = unindent(s.as_slice());
384-
assert_eq!(r.as_slice(), "line1\n\nline2");
384+
assert_eq!(r, "line1\n\nline2");
385385
}
386386

387387
#[test]
@@ -390,7 +390,7 @@ mod unindent_tests {
390390
// base indentation and should be preserved
391391
let s = " line1\n\n line2".to_string();
392392
let r = unindent(s.as_slice());
393-
assert_eq!(r.as_slice(), "line1\n\n line2");
393+
assert_eq!(r, "line1\n\n line2");
394394
}
395395

396396
#[test]
@@ -402,13 +402,13 @@ mod unindent_tests {
402402
// and continue here"]
403403
let s = "line1\n line2".to_string();
404404
let r = unindent(s.as_slice());
405-
assert_eq!(r.as_slice(), "line1\nline2");
405+
assert_eq!(r, "line1\nline2");
406406
}
407407

408408
#[test]
409409
fn should_not_ignore_first_line_indent_in_a_single_line_para() {
410410
let s = "line1\n\n line2".to_string();
411411
let r = unindent(s.as_slice());
412-
assert_eq!(r.as_slice(), "line1\n\n line2");
412+
assert_eq!(r, "line1\n\n line2");
413413
}
414414
}

0 commit comments

Comments
 (0)